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

Constructor Details

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

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

Parameters:

  • name (String|Symbol)

    The name of the interface to clear.

  • 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 Views::Char objects.



58
59
60
61
# File 'lib/vedeu/interfaces/clear.rb', line 58

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

Instance Attribute Details

#nameString|Symbol (readonly, protected)

Returns:

  • (String|Symbol)


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

def name
  @name
end

Class Method Details

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

Clear the interface with the given name.

Examples:

Vedeu.trigger(:_clear_view_, name)
Vedeu.clear_by_name(name)

Returns:

See Also:



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_nameArray<Array<Vedeu::Views::Char>>

Clear the interface with the given name.

Examples:

Vedeu.trigger(:_clear_view_, name)
Vedeu.clear_by_name(name)

Returns:

See Also:



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.

Examples:

Vedeu.trigger(:_clear_view_content_, name)
Vedeu.clear_content_by_name(name)

Returns:

See Also:



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.

Examples:

Vedeu.trigger(:_clear_view_, name)
Vedeu.clear_by_name(name)

Returns:

See Also:



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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#charsString (private)

Returns A string of blank characters.

Returns:

  • (String)

    A string of blank characters.



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

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

#clearingString (private)

Returns:

  • (String)


171
172
173
174
175
176
177
178
179
# File 'lib/vedeu/interfaces/clear.rb', line 171

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

                else
                  'interface'.freeze

                end
end

#colourVedeu::Colours::Colour (private)



90
91
92
# File 'lib/vedeu/interfaces/clear.rb', line 90

def colour
  @colour ||= interface.colour
end

#content_only?Boolean (private)

Returns:

  • (Boolean)


95
96
97
# File 'lib/vedeu/interfaces/clear.rb', line 95

def content_only?
  options[:content_only]
end

#defaultsHash<Symbol => Boolean> (private)

Returns:

  • (Hash<Symbol => Boolean>)


100
101
102
103
104
105
# File 'lib/vedeu/interfaces/clear.rb', line 100

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.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#direct?Boolean (private)

Returns:

  • (Boolean)


108
109
110
# File 'lib/vedeu/interfaces/clear.rb', line 108

def direct?
  options[:direct]
end

#geometryObject (private)

Returns the geometry for the interface.



115
116
117
# File 'lib/vedeu/interfaces/clear.rb', line 115

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

#heightFixnum (private)

Returns:

  • (Fixnum)


120
121
122
123
124
125
126
127
128
# File 'lib/vedeu/interfaces/clear.rb', line 120

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

              else
                geometry.height

              end
end

#interfaceObject (private)

Returns the interface by name.



133
134
135
# File 'lib/vedeu/interfaces/clear.rb', line 133

def interface
  @interface ||= Vedeu.interfaces.by_name(name)
end

#optimised_outputString (private)

Returns:

  • (String)


143
144
145
146
147
148
149
# File 'lib/vedeu/interfaces/clear.rb', line 143

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

#optionsHash<Symbol => Boolean> (private)

Returns:

  • (Hash<Symbol => Boolean>)


138
139
140
# File 'lib/vedeu/interfaces/clear.rb', line 138

def options
  defaults.merge!(@options)
end

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

Returns:



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/vedeu/interfaces/clear.rb', line 157

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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

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

Returns:



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.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#widthFixnum (private)

Returns:

  • (Fixnum)


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

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

             else
               geometry.width

             end
end

#xFixnum (private)

Returns:

  • (Fixnum)


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

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

         else
           geometry.x

         end
end

#yFixnum (private)

Returns:

  • (Fixnum)


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

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

         else
           geometry.y

         end
end