Module: Term2IRC
Overview
FIXME: This module breaks some termi ANSI pattern, such as: “e[31;0;42mhello, worlde[0m” This must remain string green-backgrounded, but currently it would truncate all the color info.
Constant Summary collapse
- ATTRIBUTE_TABLE =
{ :reset => ["0", "\x0f"], :bold => ["1", "\x02"], :underline => ["4", "\x1f"], }
- ATTRIBUTE_T2I_TABLE =
- ATTRIBUTE_I2T_TABLE =
- COLOR_TABLE =
{ :black => ["0", "1"], :red => ["1", "4"], :green => ["2", "3"], :yellow => ["3", "8"], :blue => ["4", "12"], :magenta => ["5", "13"], :cyan => ["6", "11"], :white => ["7", "0"], }
- COLOR_T2I_TABLE =
- COLOR_I2T_TABLE =
- RE_TERMINAL_SEQUENCE =
/(\e\[(?:\d+(?:;\d+)*)m)/- VERSION =
"0.1.0"
Instance Method Summary collapse
Instance Method Details
#meta_to_irc(meta) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/term2irc.rb', line 60 def () words = "" if [:reset] words << ATTRIBUTE_TABLE[:reset][1] end if [:bold] words << ATTRIBUTE_TABLE[:bold][1] end if [:underline] words << ATTRIBUTE_TABLE[:underline][1] end if [:foreground] or [:background] f = [:foreground] b = [:background] words << "\x03" if f and !b words << "#{COLOR_T2I_TABLE[f]}" else words << "#{f && COLOR_T2I_TABLE[f]},#{COLOR_T2I_TABLE[b]}" end end return words end |
#t2i(str) ⇒ Object
33 34 35 36 37 |
# File 'lib/term2irc.rb', line 33 def t2i(str) str.gsub(RE_TERMINAL_SEQUENCE) do |part| ((part)) end end |
#term_ansi_to_meta(part) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/term2irc.rb', line 39 def (part) = {} sequences = part.tr("\e[m", '').split(';') sequences.each do |sequence| # TODO: DRY... case sequence when "0" [:reset] = true when "1" [:bold] = true when "4" [:underline] = true when /^3[0-7]$/ [:foreground] = sequence[1] when /^4[0-7]$/ [:background] = sequence[1] end end return end |