Class: Fuzz::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/fuzz/screen.rb

Defined Under Namespace

Modules: ColorizeMethods Classes: Color

Constant Summary collapse

COLORS =
{
  black:    [Color.new("\e[30m"), Color.new("\e[m")],
  red:      [Color.new("\e[31m"), Color.new("\e[m")],
  green:    [Color.new("\e[32m"), Color.new("\e[m")],
  yellow:   [Color.new("\e[33m"), Color.new("\e[m")],
  blue:     [Color.new("\e[34m"), Color.new("\e[m")],
  magenta:  [Color.new("\e[34m"), Color.new("\e[m")],
  bold:     [Color.new("\e[1m"),  Color.new("\e[m")],
  reverse:  [Color.new("\e[7m"),  Color.new("\e[m")],
  underline:[Color.new("\e[4m"),  Color.new("\e[m")]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output = STDOUT, input = STDIN, errout = STDERR) ⇒ Screen

Returns a new instance of Screen.



50
51
52
53
54
55
# File 'lib/fuzz/screen.rb', line 50

def initialize(output = STDOUT, input = STDIN, errout = STDERR)
  @output = output
  @input = input
  @errout = errout
  @colorize = output.tty? && Fuzz::Sys.has_ansi?
end

Instance Attribute Details

#erroutObject (readonly)

Returns the value of attribute errout.



57
58
59
# File 'lib/fuzz/screen.rb', line 57

def errout
  @errout
end

#inputObject (readonly)

Returns the value of attribute input.



57
58
59
# File 'lib/fuzz/screen.rb', line 57

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



57
58
59
# File 'lib/fuzz/screen.rb', line 57

def output
  @output
end

Instance Method Details

#colorize?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/fuzz/screen.rb', line 59

def colorize?
  @colorize
end

#error_print(*args) ⇒ Object



75
76
77
# File 'lib/fuzz/screen.rb', line 75

def error_print(*args)
  errout.print args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
end

#error_println(*args) ⇒ Object



79
80
81
# File 'lib/fuzz/screen.rb', line 79

def error_println(*args)
  errout.puts args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
end

#output_colsObject



63
64
65
# File 'lib/fuzz/screen.rb', line 63

def output_cols
  80
end


67
68
69
# File 'lib/fuzz/screen.rb', line 67

def print(*args)
  output.print args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
end

#println(*args) ⇒ Object



71
72
73
# File 'lib/fuzz/screen.rb', line 71

def println(*args)
  output.puts args.flatten.collect {|a| (colorize? && Color === a) ? a.code : a }.join
end