Class: Vedeu::Views::View

Inherits:
Object
  • Object
show all
Includes:
Model, Presentation
Defined in:
lib/vedeu/models/views/view.rb

Overview

Represents a container for Line and Stream objects.

Instance Attribute Summary collapse

Attributes included from Model

#repository

Instance Method Summary collapse

Methods included from Presentation

#render_colour, #render_position, #render_style, #to_s

Methods included from Presentation::Styles

#style, #style=

Methods included from Presentation::Colour

#background, #background=, #colour, #colour=, #foreground, #foreground=

Methods included from Model

#deputy, #dsl_class, included, #store

Methods included from Common

#demodulize, #present?, #snake_case

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Views::View

Return a new instance of Vedeu::Views::View.

Options Hash (attributes):



51
52
53
54
55
56
57
# File 'lib/vedeu/models/views/view.rb', line 51

def initialize(attributes = {})
  @attributes = defaults.merge!(attributes)

  @attributes.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#attributesHash (readonly)



18
19
20
# File 'lib/vedeu/models/views/view.rb', line 18

def attributes
  @attributes
end

#clientFixnum|Float



22
23
24
# File 'lib/vedeu/models/views/view.rb', line 22

def client
  @client
end

#lines=(value) ⇒ Array<Vedeu::Views::Line> (writeonly)



34
35
36
# File 'lib/vedeu/models/views/view.rb', line 34

def lines=(value)
  @lines = value
end

#nameString



26
27
28
# File 'lib/vedeu/models/views/view.rb', line 26

def name
  @name
end

#parentVedeu::Views::Composition



30
31
32
# File 'lib/vedeu/models/views/view.rb', line 30

def parent
  @parent
end

#zindexFixnum



38
39
40
# File 'lib/vedeu/models/views/view.rb', line 38

def zindex
  @zindex
end

Instance Method Details

#add(child) ⇒ Vedeu::Views::Lines Also known as: <<



61
62
63
# File 'lib/vedeu/models/views/view.rb', line 61

def add(child)
  @value = value.add(child)
end

#defaultsHash (private)

The default values for a new instance of this class.



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vedeu/models/views/view.rb', line 126

def defaults
  {
    client: nil,
    colour: Vedeu::Colours::Colour.coerce(background: :default,
                                          foreground: :default),
    name:   '',
    parent: nil,
    style:  :normal,
    value:  [],
    zindex: 0,
  }
end

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



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vedeu/models/views/view.rb', line 73

def render
  return [] unless visible?

  output = [
    Vedeu::Cursors::Cursor.hide_cursor(name),
    Vedeu::Clear::NamedInterface.render(name),
    Vedeu::Output::Viewport.render(self),
    Vedeu.borders.by_name(name).render,
    Vedeu::Cursors::Cursor.show_cursor(name),
  ]

  output
end

#store_deferredVedeu::Views::View

When a name is given, the view is stored with this name. This view will be shown next time a refresh event is triggered with this name. Called by DSL::View.views.

Raises:



105
106
107
108
109
110
111
112
# File 'lib/vedeu/models/views/view.rb', line 105

def store_deferred
  fail Vedeu::Error::InvalidSyntax,
       'Cannot store an interface without a name.' unless present?(name)

  Vedeu.buffers.by_name(name).add(self)

  self
end

#store_immediateVedeu::Views::View

Store the view and immediately refresh it; causing to be pushed to the Terminal. Called by DSL::View.renders.



91
92
93
94
95
96
97
# File 'lib/vedeu/models/views/view.rb', line 91

def store_immediate
  store_deferred

  Vedeu.trigger(:_refresh_, name)

  self
end

#valueVedeu::Views::Lines Also known as: lines



67
68
69
# File 'lib/vedeu/models/views/view.rb', line 67

def value
  collection.coerce(@value, self)
end

#visible?Boolean

Returns a boolean indicating whether the view is visible.



117
118
119
# File 'lib/vedeu/models/views/view.rb', line 117

def visible?
  Vedeu.interfaces.by_name(name).visible?
end