Class: IO

Inherits:
Object
  • Object
show all
Includes:
IronTermAnsiColor
Defined in:
lib/iron-term-ansicolor.rb

Constant Summary

Constants included from IronTermAnsiColor

IronTermAnsiColor::ANSI_REGEXP, IronTermAnsiColor::BGCOLORS, IronTermAnsiColor::FGCOLORS

Instance Method Summary collapse

Methods included from IronTermAnsiColor

#set_color

Instance Method Details

#puts(*args) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/iron-term-ansicolor.rb', line 69

def puts(*args)
  if args.empty?
    syswrite "\n"
  else
    args.each do |str| 
      write(str)
      syswrite "\n"
    end
  end
  nil
end

#write(str) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/iron-term-ansicolor.rb', line 81

def write(str)
  result = 0
  str = str.to_s
  match = ANSI_REGEXP.match(str)
  if match.nil?
    #no ansi code in string
    result += syswrite str
  else
    #write what comes before the ansi code in the current color
    result += syswrite str[0, match.begin(1) - 2]
    set_color(match[1].to_i)
    #write what comes after the ansi code in the new color
    result += write(str[(match.end(1) + 1)..-1])
  end
  result
end