Class: LintTrappings::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/lint_trappings/output.rb

Overview

Encapsulates all communication to an output source.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Output

Creates a new SlimLint::Logger instance.

Parameters:

  • out (IO)

    the output destination.


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_enabledtrue, false

Whether colored output via ANSI escape sequences is enabled.

Returns:

  • (true, false)

6
7
8
# File 'lib/lint_trappings/output.rb', line 6

def color_enabled
  @color_enabled
end

Class Method Details

.silentSlimLint::Logger

Creates a logger which outputs nothing.

Returns:

  • (SlimLint::Logger)

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.

Parameters:

  • args (Array<String>)

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.

Parameters:

  • args (Array<String>)

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.

Parameters:

  • args (Array<String>)

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.

Parameters:

  • args (Array<String>)

91
92
93
# File 'lib/lint_trappings/output.rb', line 91

def info(*args)
  color(36, *args)
end

#newlineObject

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.

Parameters:

  • args (Array<String>)

83
84
85
# File 'lib/lint_trappings/output.rb', line 83

def notice(*args)
  color(35, *args)
end

Print the specified output without a newline.

Parameters:

  • output (String)

    the output to send


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.

Parameters:

  • output (String)

    the output to send

  • newline (true, false) (defaults to: true)

    whether to append a newline


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.

Parameters:

  • args (Array<String>)

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.

Returns:

  • (true, false)

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.

Parameters:

  • args (Array<String>)

74
75
76
# File 'lib/lint_trappings/output.rb', line 74

def warning(*args)
  color(33, *args)
end