Skip to content

Commit

Permalink
Use $stderr instead of STDERR to allow redirection.
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Oct 8, 2012
1 parent 0769b90 commit d011713
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## Master

- Use `$stderr` instead of `STDERR` to allow redirection.

## 1.4.1 - 5 October, 2012

- [#334][] Extend `:tmux` notifier with use of `tmux display-message` and options to configure them. ([@matthijsgroen][])
Expand Down
14 changes: 7 additions & 7 deletions lib/guard/ui.rb
Expand Up @@ -2,7 +2,7 @@ module Guard

# The UI class helps to format messages for the user. Everything that is logged
# through this class is considered either as an error message or a diagnostic
# message and is written to standard error (STDERR).
# message and is written to standard error ($stderr).
#
# If your Guard plugin does some output that is piped into another process for further
# processing, please just write it to STDOUT with `puts`.
Expand All @@ -20,7 +20,7 @@ class << self
def info(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color(message) if message != ''
$stderr.puts color(message) if message != ''
end
end

Expand All @@ -32,7 +32,7 @@ def info(message, options = { })
def warning(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color('WARNING: ', :yellow) + message
$stderr.puts color('WARNING: ', :yellow) + message
end
end

Expand All @@ -44,7 +44,7 @@ def warning(message, options = { })
def error(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color('ERROR: ', :red) + message
$stderr.puts color('ERROR: ', :red) + message
end
end

Expand All @@ -56,7 +56,7 @@ def error(message, options = { })
def deprecation(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color('DEPRECATION: ', :red) + message
$stderr.puts color('DEPRECATION: ', :red) + message
end
end

Expand All @@ -68,14 +68,14 @@ def deprecation(message, options = { })
def debug(message, options = { })
unless ENV['GUARD_ENV'] == 'test'
reset_line if options[:reset]
STDERR.puts color("DEBUG (#{Time.now.strftime('%T')}): ", :yellow) + message if ::Guard.options && ::Guard.options[:debug]
$stderr.puts color("DEBUG (#{Time.now.strftime('%T')}): ", :yellow) + message if ::Guard.options && ::Guard.options[:debug]
end
end

# Reset a line.
#
def reset_line
STDERR.print(color_enabled? ? "\r\e[0m" : "\r\n")
$stderr.print(color_enabled? ? "\r\e[0m" : "\r\n")
end

# Clear the output if clearable.
Expand Down

0 comments on commit d011713

Please sign in to comment.