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|Symbol readonly protected
Class Method Summary collapse
-
.by_name ⇒ Array<Array<Vedeu::Cells::Char>>
Clear the interface with the given name.
-
.clear_by_name ⇒ Array<Array<Vedeu::Cells::Char>>
Clear the interface with the given name.
-
.clear_content_by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Cells::Char>>
Clear the content of the interface with the given name.
-
.render(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Cells::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.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
- #build_position(pos_y, pos_x) ⇒ Vedeu::Geometries::Position private
-
#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
- #direct? ⇒ Boolean private
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#geometry ⇒ Object
private
Returns the geometry for the interface.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
- #height ⇒ Fixnum private
-
#initialize(name, options = {}) ⇒ Vedeu::Interfaces::Clear
constructor
Return a new instance of Vedeu::Interfaces::Clear.
- #interface ⇒ Vedeu::Interfaces::Interface private
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #optimised_output ⇒ String private
- #options ⇒ Hash<Symbol => Boolean> private
-
#output ⇒ Array<Array<Vedeu::Cells::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::Cells::Char>>
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
- #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.
60 61 62 63 |
# File 'lib/vedeu/interfaces/clear.rb', line 60 def initialize(name, = {}) @name = present?(name) ? name : Vedeu.focus @options = end |
Instance Attribute Details
#name ⇒ String|Symbol (readonly, protected)
82 83 84 |
# File 'lib/vedeu/interfaces/clear.rb', line 82 def name @name end |
Class Method Details
.by_name ⇒ Array<Array<Vedeu::Cells::Char>>
Clear the interface with the given name.
29 30 31 32 33 |
# File 'lib/vedeu/interfaces/clear.rb', line 29 def render(name = Vedeu.focus) name || Vedeu.focus new(name).render end |
.clear_by_name ⇒ Array<Array<Vedeu::Cells::Char>>
Clear the interface with the given name.
28 29 30 31 32 |
# File 'lib/vedeu/interfaces/clear.rb', line 28 def render(name = Vedeu.focus) name || Vedeu.focus new(name).render end |
.clear_content_by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Cells::Char>>
Clear the content of the interface with the given name.
39 40 41 42 43 |
# File 'lib/vedeu/interfaces/clear.rb', line 39 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::Cells::Char>>
Clear the interface with the given name.
23 24 25 26 27 |
# File 'lib/vedeu/interfaces/clear.rb', line 23 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.
#become(klass, attributes) ⇒ Class 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 one class into another.
#boolean(value) ⇒ 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 the value was a boolean.
#boolean?(value) ⇒ 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 the value is a Boolean.
#build_position(pos_y, pos_x) ⇒ Vedeu::Geometries::Position (private)
Not sure if #to_s is required here. (GL: 2015-11-30)
188 189 190 |
# File 'lib/vedeu/interfaces/clear.rb', line 188 def build_position(pos_y, pos_x) Vedeu::Geometries::Position.new(pos_y, pos_x).to_s end |
#chars ⇒ String (private)
Returns A string of blank characters.
87 88 89 |
# File 'lib/vedeu/interfaces/clear.rb', line 87 def chars @chars ||= (' ' * width) end |
#clearing ⇒ String (private)
174 175 176 177 178 179 180 181 182 |
# File 'lib/vedeu/interfaces/clear.rb', line 174 def clearing @clearing ||= if content_only? 'content' else 'interface' end end |
#colour ⇒ Vedeu::Colours::Colour (private)
92 93 94 |
# File 'lib/vedeu/interfaces/clear.rb', line 92 def colour @colour ||= interface.colour end |
#content_only? ⇒ Boolean (private)
97 98 99 |
# File 'lib/vedeu/interfaces/clear.rb', line 97 def content_only? [:content_only] end |
#defaults ⇒ Hash<Symbol => Boolean> (private)
102 103 104 105 106 107 |
# File 'lib/vedeu/interfaces/clear.rb', line 102 def defaults { content_only: false, direct: false, } end |
#direct? ⇒ Boolean (private)
110 111 112 |
# File 'lib/vedeu/interfaces/clear.rb', line 110 def direct? [:direct] end |
#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ 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 the value should be considered false.
#geometry ⇒ Object (private)
Returns the geometry for the interface.
117 118 119 |
# File 'lib/vedeu/interfaces/clear.rb', line 117 def geometry @geometry ||= Vedeu.geometries.by_name(name) end |
#hash?(value) ⇒ 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 the value is a Hash.
#height ⇒ Fixnum (private)
122 123 124 125 126 127 128 129 130 |
# File 'lib/vedeu/interfaces/clear.rb', line 122 def height @height ||= if content_only? geometry.bordered_height else geometry.height end end |
#interface ⇒ Vedeu::Interfaces::Interface (private)
133 134 135 |
# File 'lib/vedeu/interfaces/clear.rb', line 133 def interface Vedeu.interfaces.by_name(name) end |
#line_model? ⇒ 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 the model is a Views::Line.
#numeric?(value) ⇒ 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 the value is a Fixnum.
#optimised_output ⇒ String (private)
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vedeu/interfaces/clear.rb', line 143 def optimised_output Vedeu.timer("Optimised clearing #{clearing}: '#{name}'") do Array.new(height) do |iy| [ build_position(y + iy, x), colour.to_s, chars, ].join end.join + build_position(y, x) end end |
#options ⇒ Hash<Symbol => Boolean> (private)
138 139 140 |
# File 'lib/vedeu/interfaces/clear.rb', line 138 def defaults.merge!(@options) end |
#output ⇒ Array<Array<Vedeu::Cells::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.
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/vedeu/interfaces/clear.rb', line 161 def output Vedeu.timer("Clearing #{clearing}: '#{name}'") do @clear ||= Array.new(height) do |iy| Array.new(width) do |ix| Vedeu::Cells::Clear.new(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::Cells::Char>>
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vedeu/interfaces/clear.rb', line 66 def render if direct? Vedeu.direct_write(optimised_output) Vedeu::Buffers::Terminal.update(output) else Vedeu.render_output(output) end end |
#snake_case(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.
Converts a class name to a lowercase snake case string.
#stream_model? ⇒ 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 the model is a Views::Stream.
#string?(value) ⇒ 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 the value is a Fixnum.
#truthy?(value) ⇒ 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 the value should be considered true.
#view_model? ⇒ 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 the model is a Views::View.
#width ⇒ Fixnum (private)
193 194 195 196 197 198 199 200 201 |
# File 'lib/vedeu/interfaces/clear.rb', line 193 def width @width ||= if content_only? geometry.bordered_width else geometry.width end end |
#x ⇒ Fixnum (private)
215 216 217 218 219 220 221 222 223 |
# File 'lib/vedeu/interfaces/clear.rb', line 215 def x @x ||= if content_only? geometry.bx else geometry.x end end |
#y ⇒ Fixnum (private)
204 205 206 207 208 209 210 211 212 |
# File 'lib/vedeu/interfaces/clear.rb', line 204 def y @y ||= if content_only? geometry.by else geometry.y end end |