Class: Ruco::StyleMap
Constant Summary collapse
- STYLES =
{ :normal => 0, :reverse => Curses::A_REVERSE }
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #add(style, line, columns) ⇒ Object
- #flatten ⇒ Object
-
#initialize(lines) ⇒ StyleMap
constructor
A new instance of StyleMap.
- #pop ⇒ Object
- #shift ⇒ Object
- #slice!(*args) ⇒ Object
Constructor Details
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/ruco/style_map.rb', line 3 def lines @lines end |
Class Method Details
.curses_style(styles) ⇒ Object
86 87 88 |
# File 'lib/ruco/style_map.rb', line 86 def self.curses_style(styles) styles.sum{|style| STYLES[style] or raise("Unknown style #{style}") } end |
.styled(content, styles) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ruco/style_map.rb', line 64 def self.styled(content, styles) styles ||= [] content = content.dup build = [] build << [[]] buffered = '' styles.each do |style| if style build[-1] << buffered buffered = '' # set new style build << [style] end buffered << (content.slice!(0,1) || '') end build[-1] << buffered + content build end |
Instance Method Details
#+(other) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/ruco/style_map.rb', line 37 def +(other) lines = self.lines + other.lines new = StyleMap.new(0) new.lines = lines new end |
#add(style, line, columns) ⇒ Object
9 10 11 12 |
# File 'lib/ruco/style_map.rb', line 9 def add(style, line, columns) @lines[line] ||= [] @lines[line] << [style, columns] end |
#flatten ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruco/style_map.rb', line 14 def flatten @lines.map do |styles| next unless styles # start and one after end of every column-range changes styles points_of_change = styles.map{|s,c| [c.first, c.last+1] }.flatten flat = [] styles.each do |style, columns| points_of_change.each do |point| next unless columns.include?(point) flat[point] ||= [] flat[point].unshift style end end max = styles.map{|s,c|c.last}.max flat[max+1] = [] flat end end |
#pop ⇒ Object
55 56 57 |
# File 'lib/ruco/style_map.rb', line 55 def pop slice!(-1, 1) end |
#shift ⇒ Object
51 52 53 |
# File 'lib/ruco/style_map.rb', line 51 def shift slice!(0, 1) end |