Class: Vedeu::DSL::Interface

Inherits:
Object
  • Object
show all
Includes:
Common, Vedeu::DSL, Colour, Style, Text, Use
Defined in:
lib/vedeu/dsl/interface.rb

Overview

DSL for creating interfaces.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Use

#use

Methods included from Text

#stream_attributes, #stream_builder, #text

Methods included from Style

#style

Methods included from Colour

#background, #colour, #foreground

Methods included from Vedeu::DSL

#method_missing

Methods included from Common

#defined_value?, #to_sentence

Constructor Details

#initialize(model, client = nil) ⇒ Vedeu::DSL::Interface

Returns an instance of Vedeu::DSL::Interface.

Parameters:



29
30
31
32
# File 'lib/vedeu/dsl/interface.rb', line 29

def initialize(model, client = nil)
  @model  = model
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Attribute Details

#clientObject (readonly, private)

Returns:

  • (Object)


213
214
215
# File 'lib/vedeu/dsl/interface.rb', line 213

def client
  @client
end

#modelInterface (readonly, private)

Returns:



216
217
218
# File 'lib/vedeu/dsl/interface.rb', line 216

def model
  @model
end

Instance Method Details

#attributesHash (private)

Returns:

  • (Hash)


219
220
221
222
223
224
# File 'lib/vedeu/dsl/interface.rb', line 219

def attributes
  {
    client: client,
    parent: model,
  }
end

#border(&block) ⇒ Vedeu::Border

Allows the setting of a border for the interface.

Parameters:

  • block (Proc)

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



39
40
41
42
43
44
45
46
# File 'lib/vedeu/dsl/interface.rb', line 39

def border(&block)
  fail InvalidSyntax, 'block not given' unless block_given?

  border_attrs = attributes.merge!({ enabled: true,
                                     name:    model.name })

  Vedeu::Border.build(border_attrs, &block).store
end

#border!Vedeu::Border

Applies the default border to the interface.

Returns:



51
52
53
54
55
# File 'lib/vedeu/dsl/interface.rb', line 51

def border!
  border do
    # adds default border
  end
end

#cursor(value = true) ⇒ Cursor

Set the cursor visibility on an interface.

Examples:

interface 'my_interface' do
  cursor  true  # => show the cursor for this interface
  cursor  :show # => both of these are equivalent to line above
  cursor!       #
  # ...

  cursor false # => hide the cursor for this interface
  cursor :hide # => both of these are equivalent to line above
  cursor nil   #
  # ...

view 'my_interface' do
  cursor true
  # ...

Parameters:

  • value (Boolean) (defaults to: true)

    Any value other than nil or false will evaluate to true.

Returns:



79
80
81
# File 'lib/vedeu/dsl/interface.rb', line 79

def cursor(value = true)
  Vedeu::Cursor.new({ name: model.name, state: value }).store
end

#cursor!Vedeu::Cursor

Set the cursor to visible for the interface.

Returns:



86
87
88
# File 'lib/vedeu/dsl/interface.rb', line 86

def cursor!
  cursor(true)
end

#delay(value) ⇒ Fixnum|Float

To maintain performance interfaces can be delayed from refreshing too often, the reduces artefacts particularly when resizing the terminal screen.

Examples:

interface 'my_interface' do
  delay 0.5 # interface will not update more often than every 500ms.
  # ...

Parameters:

Returns:



102
103
104
# File 'lib/vedeu/dsl/interface.rb', line 102

def delay(value)
  model.delay = value
end

#focus!String

Note:

If multiple interfaces are defined, and this is included in each, then the last defined will be the interface in focus.

Specify this interface as being in focus when the application starts.

Returns:

  • (String)

    The name of the interface in focus.



112
113
114
# File 'lib/vedeu/dsl/interface.rb', line 112

def focus!
  Vedeu::Focus.add(model.name, true) if defined_value?(model.name)
end

#geometry(&block) ⇒ Geometry

Define the geometry for an interface.

Examples:

interface 'my_interface' do
  geometry do
    # ...

Parameters:

  • block (Proc)

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.

See Also:



128
129
130
131
132
# File 'lib/vedeu/dsl/interface.rb', line 128

def geometry(&block)
  fail InvalidSyntax, 'block not given' unless block_given?

  Vedeu::Geometry.build({ name: model.name }, &block).store
end

#group(name) ⇒ String

Specify a group for an interface. Interfaces of the same group can be targetted together; for example you may want to refresh multiple interfaces at once.

Examples:

interface 'my_interface' do
  group 'main_screen'
  # ...

Parameters:

  • name (String)

    The name of the group to which this interface should belong.

Returns:

  • (String)


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/vedeu/dsl/interface.rb', line 146

def group(name)
  return false unless defined_value?(name)

  if defined_value?(model.name)
    if Vedeu.groups.registered?(name)
      Vedeu.groups.find(name).add(model.name)

    else
      new_group = Vedeu::Group.new({ name: name })
      new_group.add(model.name)

    end
  end

  model.group = name
end

#keymap(name = model.name, &block) ⇒ Object Also known as: keys

See Also:



164
165
166
# File 'lib/vedeu/dsl/interface.rb', line 164

def keymap(name = model.name, &block)
  Vedeu.keymap(name, &block)
end

#lines(&block) ⇒ Line Also known as: line

Specify multiple lines in a view.

Examples:

view 'my_interface' do
  lines do
    # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
  end
end

view 'my_interface' do
  line do
    # ... see {Vedeu::DSL::Line} and {Vedeu::DSL::Stream}
  end
end

Parameters:

  • block (Proc)

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



188
189
190
191
192
# File 'lib/vedeu/dsl/interface.rb', line 188

def lines(&block)
  fail InvalidSyntax, 'block not given' unless block_given?

  model.add(model.member.build(attributes, &block))
end

#name(value) ⇒ String

The name of the interface. Used to reference the interface throughout your application’s execution lifetime.

Examples:

interface do
  name 'my_interface'
  # ...

Parameters:

  • value (String)

Returns:

  • (String)


206
207
208
# File 'lib/vedeu/dsl/interface.rb', line 206

def name(value)
  model.name = value
end