Class: RSpecLive::TerminalSection
- Inherits:
-
Object
- Object
- RSpecLive::TerminalSection
- Defined in:
- lib/rspec-live/terminal.rb
Instance Method Summary collapse
- #add_section(options = {}) ⇒ Object
- #clear ⇒ Object
- #content=(value) ⇒ Object
- #draw ⇒ Object
- #draw_content ⇒ Object
- #draw_left_margin ⇒ Object
- #draw_right_margin ⇒ Object
-
#initialize(parent = nil, options = {}) ⇒ TerminalSection
constructor
A new instance of TerminalSection.
- #refresh ⇒ Object
- #wrap(text, width) ⇒ Object
- #wrap_with_margin(text, width, margin_width) ⇒ Object
Constructor Details
#initialize(parent = nil, options = {}) ⇒ TerminalSection
Returns a new instance of TerminalSection.
44 45 46 47 48 49 |
# File 'lib/rspec-live/terminal.rb', line 44 def initialize(parent = nil, = {}) @content = "" @parent = parent .each_pair { |key, value| instance_variable_set "@#{key}", value } @children = [] end |
Instance Method Details
#add_section(options = {}) ⇒ Object
51 52 53 54 55 |
# File 'lib/rspec-live/terminal.rb', line 51 def add_section( = {}) new_section = TerminalSection.new(self, ) @children << new_section new_section end |
#clear ⇒ Object
61 62 63 64 65 |
# File 'lib/rspec-live/terminal.rb', line 61 def clear @content = "" @children = [] refresh end |
#content=(value) ⇒ Object
57 58 59 |
# File 'lib/rspec-live/terminal.rb', line 57 def content=(value) @content = value.to_s end |
#draw ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rspec-live/terminal.rb', line 78 def draw Curses.addstr "\n" if @display == :block draw_left_margin if @color Curses.attron(color_attribute @color) { draw_content } else draw_content end draw_right_margin @children.each(&:draw) end |
#draw_content ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/rspec-live/terminal.rb', line 90 def draw_content text = @content bullet = @bullet ? "#{@bullet} " : "" if @display == :block && @wrap text = bullet + wrap_with_margin(text, Terminal.width-1, bullet.length) end Curses.addstr text end |
#draw_left_margin ⇒ Object
107 108 109 |
# File 'lib/rspec-live/terminal.rb', line 107 def draw_left_margin Curses.addstr(("=" * [0, (((Terminal.width - @content.length) / 2) - 1)].max) + " ") if @align == :center end |
#draw_right_margin ⇒ Object
111 112 113 |
# File 'lib/rspec-live/terminal.rb', line 111 def draw_right_margin Curses.addstr(" " + ("=" * [0, (((Terminal.width - @content.length) / 2) - 2)].max)) if @align == :center end |
#refresh ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rspec-live/terminal.rb', line 67 def refresh if @parent @parent.refresh else Curses.clear Curses.setpos 0, 0 draw Curses.refresh end end |
#wrap(text, width) ⇒ Object
103 104 105 |
# File 'lib/rspec-live/terminal.rb', line 103 def wrap(text, width) text.scan(/\S.{0,#{width-2}}\S(?=\s|$)|\S+/).join("\n") end |
#wrap_with_margin(text, width, margin_width) ⇒ Object
99 100 101 |
# File 'lib/rspec-live/terminal.rb', line 99 def wrap_with_margin(text, width, margin_width) wrap(text, width - margin_width).split("\n").join("\n" + (" " * margin_width)) end |