Class: Vedeu::Clear

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/output/clear.rb

Overview

Clears the area defined by an interface.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Return a new instance of Vedeu::Clear.

Parameters:

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

Options Hash (options):



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

def initialize(interface, options = {})
  @interface = interface
  @options   = options
end

Instance Attribute Details

#interfaceInterface (readonly, protected)

Returns:



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.

Returns:

  • (Array|String)

See Also:



28
29
30
31
32
33
34
35
36
# File 'lib/vedeu/output/clear.rb', line 28

def clear(interface, options = {})
  if interface.visible?
    new(interface, options).write

  else
    []

  end
end

.renderArray|String

Clears the area defined by the interface.

Returns:

  • (Array|String)

See Also:



37
38
39
40
41
42
43
44
45
# File 'lib/vedeu/output/clear.rb', line 37

def clear(interface, options = {})
  if interface.visible?
    new(interface, options).write

  else
    []

  end
end

Instance Method Details

#borderObject (private)



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

def border
  @border ||= Vedeu.borders.by_name(name)
end

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

Returns:



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.

Returns:

  • (Boolean)

    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?
  options[:clear_border]
end

#clear_colourVedeu::Colour (private)

Returns The default background and foreground colours for the terminal, or the colours of the interface.

Returns:

  • (Vedeu::Colour)

    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

#defaultsHash<Symbol => Boolean> (private)

Returns:

  • (Hash<Symbol => Boolean>)


119
120
121
122
123
124
# File 'lib/vedeu/output/clear.rb', line 119

def defaults
  {
    clear_border:         false,
    use_terminal_colours: false,
  }
end

#geometryObject (private)



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

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

#heightFixnum (private)

Returns the height of the area to be cleared.

Returns:

  • (Fixnum)


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

#optionsHash<Symbol => Boolean> (private)

Returns:

  • (Hash<Symbol => Boolean>)


145
146
147
# File 'lib/vedeu/output/clear.rb', line 145

def options
  @_options ||= defaults.merge!(@options)
end

#positionVedeu::IndexPosition (private)

Parameters:

  • iy (Fixnum)
  • ix (Fixnum)

Returns:



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.

Returns:

  • (Boolean)

    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?
  options[:use_terminal_colours]
end

#widthFixnum (private)

Returns the width of the area to be cleared.

Returns:

  • (Fixnum)


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

#writeArray

Clear the view and send to the terminal.

Returns:

  • (Array)


82
83
84
# File 'lib/vedeu/output/clear.rb', line 82

def write
  Vedeu::Output.render(rendered)
end