Class: Vedeu::Interfaces::Clear

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vedeu/interfaces/clear.rb

Overview

Clear the named interface.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

#initialize(name, options = {}) ⇒ Vedeu::Interfaces::Clear

Return a new instance of Vedeu::Interfaces::Clear.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • content_only (Boolean)

    Only clear the content not the border as well. Defaults to false.

  • direct (Boolean)

    Write the content directly to the terminal using a faster mechanism. The virtual buffer will still be updated. This improves the refresh time for Vedeu as we will not be building a grid of Cells::Char objects.



49
50
51
52
# File 'lib/vedeu/interfaces/clear.rb', line 49

def initialize(name, options = {})
  @name    = present?(name) ? name : Vedeu.focus
  @options = options
end

Instance Attribute Details

#nameString|Symbol (readonly, protected)

Returns:

  • (String|Symbol)


71
72
73
# File 'lib/vedeu/interfaces/clear.rb', line 71

def name
  @name
end

Class Method Details

.by_nameArray<Array<Vedeu::Cells::Char>>

Returns:

See Also:



24
25
26
27
28
# File 'lib/vedeu/interfaces/clear.rb', line 24

def render(name = Vedeu.focus)
  name || Vedeu.focus

  new(name).render
end

.clear_by_nameArray<Array<Vedeu::Cells::Char>>

Returns:

See Also:



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

.clear_content_by_name(name = Vedeu.focus) ⇒ Array<Array<Vedeu::Cells::Char>>

Returns:

See Also:



29
30
31
32
33
# File 'lib/vedeu/interfaces/clear.rb', line 29

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>>

Returns:

See Also:



18
19
20
21
22
# File 'lib/vedeu/interfaces/clear.rb', line 18

def render(name = Vedeu.focus)
  name || Vedeu.focus

  new(name).render
end

Instance Method Details

#build_position(pos_y, pos_x) ⇒ Vedeu::Geometries::Position (private)

TODO:

Not sure if #to_s is required here. (GL: 2015-11-30)

Parameters:

  • pos_y (Fixnum)
  • pos_x (Fixnum)

Returns:



178
179
180
# File 'lib/vedeu/interfaces/clear.rb', line 178

def build_position(pos_y, pos_x)
  Vedeu::Geometries::Position.new(pos_y, pos_x).to_s
end

#charsString (private)

Returns A string of blank characters.

Returns:

  • (String)

    A string of blank characters.



76
77
78
# File 'lib/vedeu/interfaces/clear.rb', line 76

def chars
  @chars ||= (' ' * width)
end

#clearingString (private)

Returns:

  • (String)


164
165
166
167
168
169
170
171
172
# File 'lib/vedeu/interfaces/clear.rb', line 164

def clearing
  @clearing ||= if content_only?
                  'content'

                else
                  'interface'

                end
end

#colourVedeu::Colours::Colour (private)



81
82
83
# File 'lib/vedeu/interfaces/clear.rb', line 81

def colour
  @colour ||= interface.colour
end

#content_only?Boolean (private)

Returns:



86
87
88
# File 'lib/vedeu/interfaces/clear.rb', line 86

def content_only?
  options[:content_only]
end

#defaultsHash<Symbol => void> (private)

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


91
92
93
94
95
96
# File 'lib/vedeu/interfaces/clear.rb', line 91

def defaults
  {
    content_only: false,
    direct:       false,
  }
end

#direct?Boolean (private)

Returns:



99
100
101
# File 'lib/vedeu/interfaces/clear.rb', line 99

def direct?
  options[:direct]
end

#geometryObject (private)

Returns the geometry for the interface.



106
107
108
# File 'lib/vedeu/interfaces/clear.rb', line 106

def geometry
  @geometry ||= Vedeu.geometries.by_name(name)
end

#heightFixnum (private)

Returns:

  • (Fixnum)


111
112
113
114
115
116
117
118
119
# File 'lib/vedeu/interfaces/clear.rb', line 111

def height
  @height ||= if content_only?
                geometry.bordered_height

              else
                geometry.height

              end
end

#interfaceVedeu::Interfaces::Interface (private)



122
123
124
# File 'lib/vedeu/interfaces/clear.rb', line 122

def interface
  Vedeu.interfaces.by_name(name)
end

#optimised_outputString (private)

Returns:

  • (String)


132
133
134
135
136
137
138
139
140
141
142
# File 'lib/vedeu/interfaces/clear.rb', line 132

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

#optionsHash<Symbol => Boolean> (private)

Returns:



127
128
129
# File 'lib/vedeu/interfaces/clear.rb', line 127

def options
  defaults.merge!(@options)
end

#outputArray<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.

Returns:



150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/vedeu/interfaces/clear.rb', line 150

def output
  Vedeu.timer("Clearing #{clearing}: '#{name}'") do
    @clear ||= Array.new(height) do |iy|
      Array.new(width) do |ix|
        position = Vedeu::Geometries::Position.new((y + iy), (x + ix))
        Vedeu::Cells::Clear.new(colour:   colour,
                                name:     name,
                                position: position)
      end
    end
  end
end

#renderArray<Array<Vedeu::Cells::Char>>

Returns:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/interfaces/clear.rb', line 55

def render
  if direct?
    Vedeu.direct_write(optimised_output)

    Vedeu.buffer_update(output)

  else
    Vedeu.render_output(output)

  end
end

#widthFixnum (private)

Returns:

  • (Fixnum)


183
184
185
186
187
188
189
190
191
# File 'lib/vedeu/interfaces/clear.rb', line 183

def width
  @width ||= if content_only?
               geometry.bordered_width

             else
               geometry.width

             end
end

#xFixnum (private)

Returns:

  • (Fixnum)


205
206
207
208
209
210
211
212
213
# File 'lib/vedeu/interfaces/clear.rb', line 205

def x
  @x ||= if content_only?
           geometry.bx

         else
           geometry.x

         end
end

#yFixnum (private)

Returns:

  • (Fixnum)


194
195
196
197
198
199
200
201
202
# File 'lib/vedeu/interfaces/clear.rb', line 194

def y
  @y ||= if content_only?
           geometry.by

         else
           geometry.y

         end
end