Class: LintTrappings::Output
- Inherits:
-
Object
- Object
- LintTrappings::Output
- Defined in:
- lib/lint_trappings/output.rb
Overview
Encapsulates all communication to an output source.
Instance Attribute Summary collapse
-
#color_enabled ⇒ true, false
Whether colored output via ANSI escape sequences is enabled.
Class Method Summary collapse
-
.silent ⇒ SlimLint::Logger
Creates a logger which outputs nothing.
Instance Method Summary collapse
-
#bold(*args) ⇒ Object
Print the specified output in bold face.
-
#bold_error(*args) ⇒ Object
Print the specified output in a bold face and color indicative of error.
-
#error(*args) ⇒ Object
Print the specified output in a color indicative of error.
-
#info(*args) ⇒ Object
Print the specified output in a color indicating information.
-
#initialize(out) ⇒ Output
constructor
Creates a new SlimLint::Logger instance.
-
#newline ⇒ Object
Print a blank line.
-
#notice(*args) ⇒ Object
Print the specified output in a color indicating something worthy of notice.
-
#print(output) ⇒ Object
Print the specified output without a newline.
-
#puts(output, newline = true) ⇒ Object
Print the specified output.
-
#success(*args) ⇒ Object
Print the specified output in a color indicative of success.
-
#tty? ⇒ true, false
Whether this logger is outputting to a TTY.
-
#warning(*args) ⇒ Object
Print the specified output in a color indicative of a warning.
Constructor Details
#initialize(out) ⇒ Output
Creates a new SlimLint::Logger instance.
17 18 19 20 |
# File 'lib/lint_trappings/output.rb', line 17 def initialize(out) @out = out @color_enabled = tty? end |
Instance Attribute Details
#color_enabled ⇒ true, false
Whether colored output via ANSI escape sequences is enabled.
6 7 8 |
# File 'lib/lint_trappings/output.rb', line 6 def color_enabled @color_enabled end |
Class Method Details
.silent ⇒ SlimLint::Logger
Creates a logger which outputs nothing.
10 11 12 |
# File 'lib/lint_trappings/output.rb', line 10 def self.silent new(File.open(File::NULL, 'w')) end |
Instance Method Details
#bold(*args) ⇒ Object
Print the specified output in bold face. If output destination is not a TTY, behaves the same as #log.
42 43 44 |
# File 'lib/lint_trappings/output.rb', line 42 def bold(*args) color('1', *args) end |
#bold_error(*args) ⇒ Object
Print the specified output in a bold face and color indicative of error. If output destination is not a TTY, behaves the same as #log.
58 59 60 |
# File 'lib/lint_trappings/output.rb', line 58 def bold_error(*args) color('1;31', *args) end |
#error(*args) ⇒ Object
Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as #log.
50 51 52 |
# File 'lib/lint_trappings/output.rb', line 50 def error(*args) color(31, *args) end |
#info(*args) ⇒ Object
Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as #log.
91 92 93 |
# File 'lib/lint_trappings/output.rb', line 91 def info(*args) color(36, *args) end |
#newline ⇒ Object
Print a blank line.
96 97 98 |
# File 'lib/lint_trappings/output.rb', line 96 def newline puts('') end |
#notice(*args) ⇒ Object
Print the specified output in a color indicating something worthy of notice. If output destination is not a TTY, behaves the same as #log.
83 84 85 |
# File 'lib/lint_trappings/output.rb', line 83 def notice(*args) color(35, *args) end |
#print(output) ⇒ Object
Print the specified output without a newline.
34 35 36 |
# File 'lib/lint_trappings/output.rb', line 34 def print(output) puts(output, false) end |
#puts(output, newline = true) ⇒ Object
Print the specified output.
26 27 28 29 |
# File 'lib/lint_trappings/output.rb', line 26 def puts(output, newline = true) @out.print(output) @out.print("\n") if newline end |
#success(*args) ⇒ Object
Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as #log.
66 67 68 |
# File 'lib/lint_trappings/output.rb', line 66 def success(*args) color(32, *args) end |
#tty? ⇒ true, false
Whether this logger is outputting to a TTY.
103 104 105 |
# File 'lib/lint_trappings/output.rb', line 103 def tty? @out.respond_to?(:tty?) && @out.tty? end |
#warning(*args) ⇒ Object
Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as #log.
74 75 76 |
# File 'lib/lint_trappings/output.rb', line 74 def warning(*args) color(33, *args) end |