class TerraformLandscape::Output
Encapsulates all communication to an output source.
Attributes
Whether colored output via ANSI escape sequences is enabled. @return [true,false]
Public Class Methods
Creates a new {SlimLint::Logger} instance.
@param out [IO] the output destination.
# File lib/terraform_landscape/output.rb, line 17 def initialize(out) @out = out @color_enabled = tty? end
Creates a logger which outputs nothing. @return [TerraformLandscape::Output]
# File lib/terraform_landscape/output.rb, line 10 def self.silent new(File.open(File::NULL, 'w')) end
Public Instance Methods
Print the specified output in bold face. If output destination is not a TTY, behaves the same as {#log}.
@param args [Array<String>]
# File lib/terraform_landscape/output.rb, line 42 def bold(*args) color('1', *args) end
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}.
@param args [Array<String>]
# File lib/terraform_landscape/output.rb, line 58 def bold_error(*args) color('1;31', *args) end
Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as {#log}.
@param args [Array<String>]
# File lib/terraform_landscape/output.rb, line 50 def error(*args) color(31, *args) end
Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as {#log}.
@param args [Array<String>]
# File lib/terraform_landscape/output.rb, line 91 def info(*args) color(36, *args) end
Print a blank line.
# File lib/terraform_landscape/output.rb, line 96 def newline puts('') end
Print the specified output in a color indicating something worthy of notice. If output destination is not a TTY, behaves the same as {#log}.
@param args [Array<String>]
# File lib/terraform_landscape/output.rb, line 83 def notice(*args) color(35, *args) end
Print the specified output without a newline.
@param output [String] the output to send
# File lib/terraform_landscape/output.rb, line 34 def print(output) puts(output, false) end
Print the specified output.
@param output [String] the output to send @param newline [true,false] whether to append a newline
# File lib/terraform_landscape/output.rb, line 26 def puts(output, newline = true) @out.print(output) @out.print("\n") if newline end
Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as {#log}.
@param args [Array<String>]
# File lib/terraform_landscape/output.rb, line 66 def success(*args) color(32, *args) end
Whether this logger is outputting to a TTY.
@return [true,false]
# File lib/terraform_landscape/output.rb, line 103 def tty? @out.respond_to?(:tty?) && @out.tty? end
Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as {#log}.
@param args [Array<String>]
# File lib/terraform_landscape/output.rb, line 74 def warning(*args) color(33, *args) end
Connect directly to a readable stream
# File lib/terraform_landscape/output.rb, line 108 def write_from(other_io) while (line = other_io.gets) print line end end
Private Instance Methods
Print output in the specified color.
@param code [Integer,String] ANSI color code @param output [String] output to print @param newline [Boolean] whether to append a newline
# File lib/terraform_landscape/output.rb, line 121 def color(code, output, newline = true) puts(color_enabled ? "\033[#{code}m#{output}\033[0m" : output, newline) end