Class: Vedeu::Clear
- Inherits:
-
Object
- Object
- Vedeu::Clear
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/output/clear.rb
Overview
Clears the area defined by an interface.
Instance Attribute Summary collapse
- #interface ⇒ Interface readonly protected
Class Method Summary collapse
-
.clear(interface, options = {}) ⇒ Array|String
Clears the area defined by the interface.
-
.render ⇒ Array|String
Clears the area defined by the interface.
Instance Method Summary collapse
- #border ⇒ Object private
-
#clear ⇒ Array<Array<Vedeu::Char>>
(also: #render, #rendered)
For each visible line of the interface, set the foreground and background colours to those specified when the interface was defined, then starting write space characters over the area which the interface occupies.
-
#clear_border? ⇒ Boolean
private
Indicates whether the area occupied by the border of the interface should be cleared also.
-
#clear_colour ⇒ Vedeu::Colour
private
The default background and foreground colours for the terminal, or the colours of the interface.
- #defaults ⇒ Hash<Symbol => Boolean> private
- #geometry ⇒ Object private
-
#height ⇒ Fixnum
private
Returns the height of the area to be cleared.
-
#initialize(interface, options = {}) ⇒ Vedeu::Clear
constructor
Return a new instance of Vedeu::Clear.
- #options ⇒ Hash<Symbol => Boolean> private
- #position ⇒ Vedeu::IndexPosition private
-
#use_terminal_colours? ⇒ Boolean
private
Indicates whether the default terminal colours should be used to clear the area.
-
#width ⇒ Fixnum
private
Returns the width of the area to be cleared.
-
#write ⇒ Array
Clear the view and send to the terminal.
Constructor Details
#initialize(interface, options = {}) ⇒ Vedeu::Clear
Return a new instance of Vedeu::Clear.
49 50 51 52 |
# File 'lib/vedeu/output/clear.rb', line 49 def initialize(interface, = {}) @interface = interface = end |
Instance Attribute Details
#interface ⇒ Interface (readonly, protected)
90 91 92 |
# File 'lib/vedeu/output/clear.rb', line 90 def interface @interface end |
Class Method Details
.clear(interface, options = {}) ⇒ Array|String
Clears the area defined by the interface.
28 29 30 31 32 33 34 35 36 |
# File 'lib/vedeu/output/clear.rb', line 28 def clear(interface, = {}) if interface.visible? new(interface, ).write else [] end end |
.render ⇒ Array|String
Clears the area defined by the interface.
37 38 39 40 41 42 43 44 45 |
# File 'lib/vedeu/output/clear.rb', line 37 def clear(interface, = {}) if interface.visible? new(interface, ).write else [] end end |
Instance Method Details
#border ⇒ Object (private)
95 96 97 |
# File 'lib/vedeu/output/clear.rb', line 95 def border @border ||= Vedeu.borders.by_name(name) end |
#clear ⇒ Array<Array<Vedeu::Char>> Also known as: render, rendered
For each visible line of the interface, set the foreground and background colours to those specified when the interface was defined, then starting write space characters over the area which the interface occupies.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vedeu/output/clear.rb', line 59 def clear if visible? Vedeu.log(type: :output, message: "Clearing: '#{name}'") @clear ||= Array.new(height) do |iy| Array.new(width) do |ix| Vedeu::Char.new(value: ' ', colour: clear_colour, style: style, position: Vedeu::IndexPosition[iy, ix, *position]) end end else [] end end |
#clear_border? ⇒ Boolean (private)
Returns Indicates whether the area occupied by the border of the interface should be cleared also.
101 102 103 |
# File 'lib/vedeu/output/clear.rb', line 101 def clear_border? [:clear_border] end |
#clear_colour ⇒ Vedeu::Colour (private)
Returns The default background and foreground colours for the terminal, or the colours of the interface.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/vedeu/output/clear.rb', line 107 def clear_colour @colour ||= if use_terminal_colours? Vedeu::Colour.new(background: :default, foreground: :default) else colour end end |
#defaults ⇒ Hash<Symbol => Boolean> (private)
119 120 121 122 123 124 |
# File 'lib/vedeu/output/clear.rb', line 119 def defaults { clear_border: false, use_terminal_colours: false, } end |
#geometry ⇒ Object (private)
127 128 129 |
# File 'lib/vedeu/output/clear.rb', line 127 def geometry @geometry ||= Vedeu.geometries.by_name(name) end |
#height ⇒ Fixnum (private)
Returns the height of the area to be cleared.
134 135 136 137 138 139 140 141 142 |
# File 'lib/vedeu/output/clear.rb', line 134 def height if clear_border? geometry.height else border.height end end |
#options ⇒ Hash<Symbol => Boolean> (private)
145 146 147 |
# File 'lib/vedeu/output/clear.rb', line 145 def ||= defaults.merge!() end |
#position ⇒ Vedeu::IndexPosition (private)
152 153 154 155 156 157 158 159 160 |
# File 'lib/vedeu/output/clear.rb', line 152 def position @position ||= if clear_border? [y, x] else [by, bx] end end |
#use_terminal_colours? ⇒ Boolean (private)
Returns Indicates whether the default terminal colours should be used to clear the area.
164 165 166 |
# File 'lib/vedeu/output/clear.rb', line 164 def use_terminal_colours? [:use_terminal_colours] end |
#width ⇒ Fixnum (private)
Returns the width of the area to be cleared.
171 172 173 174 175 176 177 178 179 |
# File 'lib/vedeu/output/clear.rb', line 171 def width if clear_border? geometry.width else border.width end end |
#write ⇒ Array
Clear the view and send to the terminal.
82 83 84 |
# File 'lib/vedeu/output/clear.rb', line 82 def write Vedeu::Output.render(rendered) end |