Class: Vedeu::Interfaces::Clear
- Inherits:
-
Object
- Object
- Vedeu::Interfaces::Clear
- Includes:
- Common
- Defined in:
- lib/vedeu/interfaces/clear.rb
Overview
Clear the named interface.
Instance Attribute Summary collapse
- #name ⇒ String readonly protected
Class Method Summary collapse
-
.by_name ⇒ Array<Array<Vedeu::Views::Char>>
Clear the interface with the given name.
-
.clear_by_name ⇒ Array<Array<Vedeu::Views::Char>>
Clear the interface with the given name.
-
.clear_content_by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Views::Char>>
Clear the content of the interface with the given name.
-
.render(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Views::Char>>
Clear the interface with the given name.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#border ⇒ Object
private
Returns the border for the interface.
-
#chars ⇒ String
private
A string of blank characters.
- #clearing ⇒ String private
- #colour ⇒ Vedeu::Colours::Colour private
- #content_only? ⇒ Boolean private
- #defaults ⇒ Hash<Symbol => Boolean> private
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
- #direct? ⇒ Boolean private
-
#geometry ⇒ Object
private
Returns the geometry for the interface.
- #height ⇒ Fixnum private
-
#initialize(name, options = {}) ⇒ Vedeu::Interfaces::Clear
constructor
Return a new instance of Vedeu::Interfaces::Clear.
-
#interface ⇒ Object
private
Returns the interface by name.
- #optimised_output ⇒ String private
- #options ⇒ Hash<Symbol => Boolean> private
-
#output ⇒ Array<Array<Vedeu::Views::Char>>
private
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.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- #render ⇒ Array<Array<Vedeu::Views::Char>>
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
- #width ⇒ Fixnum private
- #x ⇒ Fixnum private
- #y ⇒ Fixnum private
Constructor Details
#initialize(name, options = {}) ⇒ Vedeu::Interfaces::Clear
Return a new instance of Vedeu::Interfaces::Clear.
58 59 60 61 |
# File 'lib/vedeu/interfaces/clear.rb', line 58 def initialize(name, = {}) @name = present?(name) ? name : Vedeu.focus = end |
Instance Attribute Details
#name ⇒ String (readonly, protected)
80 81 82 |
# File 'lib/vedeu/interfaces/clear.rb', line 80 def name @name end |
Class Method Details
.by_name ⇒ Array<Array<Vedeu::Views::Char>>
Clear the interface with the given name.
27 28 29 30 31 |
# File 'lib/vedeu/interfaces/clear.rb', line 27 def render(name = Vedeu.focus) name || Vedeu.focus new(name).render end |
.clear_by_name ⇒ Array<Array<Vedeu::Views::Char>>
Clear the interface with the given name.
26 27 28 29 30 |
# File 'lib/vedeu/interfaces/clear.rb', line 26 def render(name = Vedeu.focus) name || Vedeu.focus new(name).render end |
.clear_content_by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Views::Char>>
Clear the content of the interface with the given name.
37 38 39 40 41 |
# File 'lib/vedeu/interfaces/clear.rb', line 37 def clear_content_by_name(name = Vedeu.focus) name || Vedeu.focus new(name, content_only: true, direct: true).render end |
.render(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Views::Char>>
Clear the interface with the given name.
21 22 23 24 25 |
# File 'lib/vedeu/interfaces/clear.rb', line 21 def render(name = Vedeu.focus) name || Vedeu.focus new(name).render end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#border ⇒ Object (private)
Returns the border for the interface.
87 88 89 |
# File 'lib/vedeu/interfaces/clear.rb', line 87 def border @border ||= Vedeu.borders.by_name(name) end |
#chars ⇒ String (private)
Returns A string of blank characters.
92 93 94 |
# File 'lib/vedeu/interfaces/clear.rb', line 92 def chars @chars ||= (' ' * width).freeze end |
#clearing ⇒ String (private)
178 179 180 181 182 183 184 185 186 |
# File 'lib/vedeu/interfaces/clear.rb', line 178 def clearing @clearing ||= if content_only? 'content'.freeze else 'interface'.freeze end end |
#colour ⇒ Vedeu::Colours::Colour (private)
97 98 99 |
# File 'lib/vedeu/interfaces/clear.rb', line 97 def colour @colour ||= interface.colour end |
#content_only? ⇒ Boolean (private)
102 103 104 |
# File 'lib/vedeu/interfaces/clear.rb', line 102 def content_only? [:content_only] end |
#defaults ⇒ Hash<Symbol => Boolean> (private)
107 108 109 110 111 112 |
# File 'lib/vedeu/interfaces/clear.rb', line 107 def defaults { content_only: false, direct: false, } end |
#demodulize(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the module part from the expression in the string.
#direct? ⇒ Boolean (private)
115 116 117 |
# File 'lib/vedeu/interfaces/clear.rb', line 115 def direct? [:direct] end |
#geometry ⇒ Object (private)
Returns the geometry for the interface.
122 123 124 |
# File 'lib/vedeu/interfaces/clear.rb', line 122 def geometry @geometry ||= Vedeu.geometries.by_name(name) end |
#height ⇒ Fixnum (private)
127 128 129 130 131 132 133 134 135 |
# File 'lib/vedeu/interfaces/clear.rb', line 127 def height @height ||= if content_only? border.height else geometry.height end end |
#interface ⇒ Object (private)
Returns the interface by name.
140 141 142 |
# File 'lib/vedeu/interfaces/clear.rb', line 140 def interface @interface ||= Vedeu.interfaces.by_name(name) end |
#optimised_output ⇒ String (private)
150 151 152 153 154 155 156 |
# File 'lib/vedeu/interfaces/clear.rb', line 150 def optimised_output Vedeu.timer("Optimised clearing #{clearing}: '#{name}'".freeze) do height.times.map do |iy| Vedeu::Geometry::Position.new(y + iy, x).to_s + colour.to_s + chars end.join + Vedeu::Geometry::Position.new(y, x).to_s end end |
#options ⇒ Hash<Symbol => Boolean> (private)
145 146 147 |
# File 'lib/vedeu/interfaces/clear.rb', line 145 def defaults.merge!() end |
#output ⇒ Array<Array<Vedeu::Views::Char>> (private)
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.
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/vedeu/interfaces/clear.rb', line 164 def output Vedeu.timer("Clearing #{clearing}: '#{name}'".freeze) do @clear ||= Array.new(height) do |iy| Array.new(width) do |ix| Vedeu::Views::Char.new(value: ' '.freeze, colour: colour, name: name, position: [y + iy, x + ix]) end end end end |
#present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
#render ⇒ Array<Array<Vedeu::Views::Char>>
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/interfaces/clear.rb', line 64 def render if direct? Vedeu.direct_write(optimised_output) Vedeu::Terminal::Buffer.update(output) else Vedeu.render_output(output) end end |
#snake_case(name) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
#width ⇒ Fixnum (private)
189 190 191 192 193 194 195 196 197 |
# File 'lib/vedeu/interfaces/clear.rb', line 189 def width @width ||= if content_only? border.width else geometry.width end end |
#x ⇒ Fixnum (private)
211 212 213 214 215 216 217 218 219 |
# File 'lib/vedeu/interfaces/clear.rb', line 211 def x @x ||= if content_only? border.bx else geometry.x end end |
#y ⇒ Fixnum (private)
200 201 202 203 204 205 206 207 208 |
# File 'lib/vedeu/interfaces/clear.rb', line 200 def y @y ||= if content_only? border.by else geometry.y end end |