Class: Vedeu::DSL::Interface

Inherits:
Object
  • Object
show all
Includes:
Common, Vedeu::DSL, Presentation, 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

#duplicate, #use

Methods included from Text

#text

Methods included from Presentation

#background, #colour, #foreground, #style

Methods included from Vedeu::DSL

#method_missing

Methods included from Common

#defined_value?

Constructor Details

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

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

Parameters:



19
20
21
22
# File 'lib/vedeu/dsl/interface.rb', line 19

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, protected)

Returns:

  • (Object)


245
246
247
# File 'lib/vedeu/dsl/interface.rb', line 245

def client
  @client
end

#modelInterface (readonly, protected)

Returns:



249
250
251
# File 'lib/vedeu/dsl/interface.rb', line 249

def model
  @model
end

Instance Method Details

#attributesHash (private)

Returns:

  • (Hash)


254
255
256
257
258
259
# File 'lib/vedeu/dsl/interface.rb', line 254

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

#border(name = nil, &block) ⇒ Vedeu::Border

Allows the setting of a border for the interface.

Parameters:

  • name (String) (defaults to: nil)

    The name of the interface; this is already provided when we define the interface or view, setting it here is just mirroring functionality of Border.border.

  • block (Proc)

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



32
33
34
35
36
37
38
39
40
41
# File 'lib/vedeu/dsl/interface.rb', line 32

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

  model_name = name ? name : model.name

  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:



46
47
48
49
50
# File 'lib/vedeu/dsl/interface.rb', line 46

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 nil   # => as above
  # ...

view 'my_interface' do
  cursor true
  # ...

Parameters:

  • value (Boolean) (defaults to: true)

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

Returns:



73
74
75
76
77
# File 'lib/vedeu/dsl/interface.rb', line 73

def cursor(value = true)
  boolean = value ? true : false

  Vedeu::Cursor.new(name: model.name, visible: boolean).store
end

#cursor!Vedeu::Cursor

Set the cursor to visible for the interface.

Returns:



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

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:

  • value (Fixnum|Float)

Returns:

  • (Fixnum|Float)


98
99
100
# File 'lib/vedeu/dsl/interface.rb', line 98

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.



108
109
110
# File 'lib/vedeu/dsl/interface.rb', line 108

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

#geometry(name = nil, &block) ⇒ Geometry

Define the geometry for an interface.

Examples:

interface 'my_interface' do
  geometry do
    # ...

Parameters:

  • name (String) (defaults to: nil)

    The name of the interface; this is already provided when we define the interface or view, setting it here is just mirroring functionality of Geometry.geometry.

  • block (Proc)

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.

See Also:



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

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

  model_name = name ? name : model.name

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

#group(name) ⇒ Vedeu::Group

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:



146
147
148
149
150
151
152
# File 'lib/vedeu/dsl/interface.rb', line 146

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

  model.group = name

  Vedeu.groups.by_name(name).add(model.name)
end

#hide!void

This method returns an undefined value.

Set the interface to invisible.



211
212
213
# File 'lib/vedeu/dsl/interface.rb', line 211

def hide!
  visible(false)
end

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

See Also:



155
156
157
# File 'lib/vedeu/dsl/interface.rb', line 155

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.



179
180
181
182
183
# File 'lib/vedeu/dsl/interface.rb', line 179

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)


197
198
199
# File 'lib/vedeu/dsl/interface.rb', line 197

def name(value)
  model.name = value
end

#show!void

This method returns an undefined value.

Set the interface to visible.



204
205
206
# File 'lib/vedeu/dsl/interface.rb', line 204

def show!
  visible(true)
end

#visible(value = true) ⇒ void

This method returns an undefined value.

Set the visibility of the interface.

Examples:

interface 'my_interface' do
  visible true  # => show the interface
  show!         # => as above
  # ...

  visible false # => hide the interface
  hide!         # => as above
  # ...

view 'my_interface' do
  visible false
  # ...

Parameters:

  • value (Boolean) (defaults to: true)

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



235
236
237
238
239
# File 'lib/vedeu/dsl/interface.rb', line 235

def visible(value = true)
  boolean = value ? true : false

  model.visible = boolean
end