Class: Vedeu::Clear::Interface

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

Overview

Clear the named interface.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

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

Options Hash (options):

  • content_only (Boolean)

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



53
54
55
56
# File 'lib/vedeu/output/clear/interface.rb', line 53

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

Instance Attribute Details

#nameString (readonly, protected)



67
68
69
# File 'lib/vedeu/output/clear/interface.rb', line 67

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)

See Also:



27
28
29
30
31
# File 'lib/vedeu/output/clear/interface.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)

See Also:



26
27
28
29
30
# File 'lib/vedeu/output/clear/interface.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)

See Also:



37
38
39
40
41
# File 'lib/vedeu/output/clear/interface.rb', line 37

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

  new(name, content_only: 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)

See Also:



21
22
23
24
25
# File 'lib/vedeu/output/clear/interface.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 Vedeu::Common

Returns a boolean indicating whether a variable is nil or empty.

#borderObject (private)

See Also:

  • Borders::Repository#by_name


72
73
74
# File 'lib/vedeu/output/clear/interface.rb', line 72

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

#clearingString (private)



140
141
142
143
144
# File 'lib/vedeu/output/clear/interface.rb', line 140

def clearing
  return 'content'.freeze if content_only?

  'interface'.freeze
end

#colourVedeu::Colours::Colour (private)



77
78
79
# File 'lib/vedeu/output/clear/interface.rb', line 77

def colour
  interface.colour
end

#content_only?Boolean (private)



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

def content_only?
  options[:content_only]
end

#defaultsHash<Symbol => Boolean> (private)



87
88
89
90
91
# File 'lib/vedeu/output/clear/interface.rb', line 87

def defaults
  {
    content_only: false,
  }
end

#demodulize(klass) ⇒ String Originally defined in module Vedeu::Common

Removes the module part from the expression in the string.

Examples:

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

#geometryObject (private)

See Also:

  • Geometry::Repository#by_name


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

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

#heightFixnum (private)



99
100
101
102
103
# File 'lib/vedeu/output/clear/interface.rb', line 99

def height
  return border.height if content_only?

  geometry.height
end

#interfaceObject (private)

See Also:

  • Interfaces::Repository#by_name


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

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

#optionsHash<Symbol => Boolean> (private)



111
112
113
# File 'lib/vedeu/output/clear/interface.rb', line 111

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.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vedeu/output/clear/interface.rb', line 121

def output
  Vedeu.timer("Clearing #{clearing}: '#{name}'".freeze) do
    @y      = y
    @x      = x
    @width  = width
    @height = height
    @colour = colour

    @clear ||= Array.new(@height) do |iy|
      Array.new(@width) do |ix|
        Vedeu::Views::Char.new(value:    ' '.freeze,
                               colour:   @colour,
                               position: [@y + iy, @x + ix])
      end
    end
  end
end

#present?(variable) ⇒ Boolean Originally defined in module Vedeu::Common

Returns a boolean indicating whether a variable has a useful value.

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



59
60
61
# File 'lib/vedeu/output/clear/interface.rb', line 59

def render
  Vedeu.render_output(output)
end

#snake_case(name) ⇒ String Originally defined in module Vedeu::Common

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"

#widthFixnum (private)



147
148
149
150
151
# File 'lib/vedeu/output/clear/interface.rb', line 147

def width
  return border.width if content_only?

  geometry.width
end

#xFixnum (private)



161
162
163
164
165
# File 'lib/vedeu/output/clear/interface.rb', line 161

def x
  return border.bx if content_only?

  geometry.x
end

#yFixnum (private)



154
155
156
157
158
# File 'lib/vedeu/output/clear/interface.rb', line 154

def y
  return border.by if content_only?

  geometry.y
end