Class: Vedeu::DSL::Interface

Inherits:
Object
  • Object
show all
Extended by:
Common
Includes:
Common, Vedeu::DSL, Presentation, Shared, Text, Use
Defined in:
lib/vedeu/dsl/interface.rb

Overview

DSL for creating interfaces.

Instance Attribute Summary

Attributes included from Vedeu::DSL

#client, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

demodulize, present?, snake_case

Methods included from Text

#text

Methods included from Shared

#border, #border!, #geometry

Methods included from Presentation

#background, #colour, #colour_attributes, #foreground, #style

Methods included from Vedeu::DSL

#attributes, #method_missing

Constructor Details

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

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

Parameters:



91
92
93
94
# File 'lib/vedeu/dsl/interface.rb', line 91

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

Class Method Details

.add_buffers!(name) ⇒ Vedeu::Buffers::Buffer (private)

Registers a set of buffers for the interface unless already registered, and also adds interface’s name to list of focussable interfaces.



58
59
60
# File 'lib/vedeu/dsl/interface.rb', line 58

def add_buffers!(name)
  Vedeu::Buffers::Buffer.new(name: name).store
end

.add_cursor!(name) ⇒ Vedeu::Cursors::Cursor (private)

Registers a new cursor for the interface unless already registered.



65
66
67
# File 'lib/vedeu/dsl/interface.rb', line 65

def add_cursor!(name)
  Vedeu::Cursors::Cursor.new(name: name).store
end

.add_focusable!(name) ⇒ void (private)

This method returns an undefined value.

Registers interface name in focus list unless already registered.



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

def add_focusable!(name)
  Vedeu.focusable.add(name) unless Vedeu.focusable.registered?(name)
end

.client(&block) ⇒ Object (private)

Returns the client object which called the DSL method.

Parameters:

  • block (Proc)

Returns:

  • (Object)


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

def client(&block)
  eval('self', block.binding)
end

.interface(name, &block) ⇒ Vedeu::Models::Interface

TODO:

More documentation required.

Register an interface by name which will display output from a event or command. This provides the means for you to define your the views of your application without their content.

Vedeu.interface 'my_interface' do
  # ... some code
end

Parameters:

  • name (String)

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

  • block (Proc)

    A set of attributes which define the features of the interface.

Returns:

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vedeu/dsl/interface.rb', line 35

def interface(name, &block)
  fail Vedeu::Error::InvalidSyntax,
       'block not given' unless block_given?
  fail Vedeu::Error::MissingRequired,
       'name not given' unless present?(name)

  add_buffers!(name)
  add_cursor!(name)
  add_focusable!(name)

  attributes = { client: client(&block), name: name }

  Vedeu::Models::Interface.build(attributes, &block).store
end

Instance Method Details

#cursor(value = true) ⇒ Vedeu::Cursors::Cursor

Set the cursor visibility on an interface.

Examples:

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

Vedeu.interface 'my_interface' do
  cursor false # => hide the cursor for this interface
  # or...
  cursor nil   # => as above
  # ...
end

Vedeu.view 'my_interface' do
  cursor true # => Specify the visibility of the cursor when the view
  # ...       #    is rendered.
end

Parameters:

  • value (Boolean) (defaults to: true)

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

Returns:



124
125
126
127
128
# File 'lib/vedeu/dsl/interface.rb', line 124

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

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

#cursor!Vedeu::Cursors::Cursor

Set the cursor to visible for the interface.



133
134
135
# File 'lib/vedeu/dsl/interface.rb', line 133

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:

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

Parameters:

  • value (Fixnum|Float)

    Time in seconds. (0.5 = 500ms).

Returns:

  • (Fixnum|Float)


150
151
152
# File 'lib/vedeu/dsl/interface.rb', line 150

def delay(value)
  model.delay = value
end

#focus!Array<String>

Note:

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

“‘ruby Vedeu.focus_by_name ’some_interface’ “‘

When the above is specified (outside of a ‘Vedeu.interface` declaration), the named interface will be focussed instead.

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

Returns:

  • (Array<String>)

    A list of focusable interfaces.



168
169
170
# File 'lib/vedeu/dsl/interface.rb', line 168

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

#group(name) ⇒ Vedeu::Models::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:

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

Parameters:

  • name (String)

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

Returns:



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

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

  model.group = name

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

#hide!Boolean

Set the interface to invisible.

Examples:

Vedeu.interface('my_interface') do
  # ... some code
end

Returns:

  • (Boolean)


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

def hide!
  visible(false)
end

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

See Also:



194
195
196
# File 'lib/vedeu/dsl/interface.rb', line 194

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

#name(value) ⇒ String

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

Examples:

Vedeu.interface do
  name 'my_interface'
  # ...
end

Parameters:

  • value (String)

Returns:

  • (String)


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

def name(value)
  model.name = value
end

#no_cursor!Vedeu::Cursors::Cursor

Set the cursor to invisible for the interface.



218
219
220
# File 'lib/vedeu/dsl/interface.rb', line 218

def no_cursor!
  cursor(false)
end

#show!Boolean

Set the interface to visible.

Examples:

Vedeu.interface('my_interface') do
  show!

  # ... some code
end

Returns:

  • (Boolean)


232
233
234
# File 'lib/vedeu/dsl/interface.rb', line 232

def show!
  visible(true)
end

#use(name) ⇒ Vedeu::Models::Interface

Use a value from another model.

Parameters:

  • name (String)

    The name of the interface model you wish to use a value from.

Returns:



253
254
255
# File 'lib/vedeu/dsl/interface.rb', line 253

def use(name)
  model.repository.by_name(name)
end

#visible(value = true) ⇒ Boolean

Set the visibility of the interface.

Examples:

Vedeu.interface 'my_interface' do
  visible true  # => show the interface
  # or...
  show!         # => as above
  # ... some code
end

Vedeu.interface 'my_interface' do
  visible false # => hide the interface
  # or...
  hide!         # => as above
  # ... some code
end

Vedeu.view 'my_interface' do
  visible false
  # ... some code
end

Parameters:

  • value (Boolean) (defaults to: true)

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

Returns:

  • (Boolean)


283
284
285
286
287
# File 'lib/vedeu/dsl/interface.rb', line 283

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

  model.visible = boolean
end

#zindex(value) ⇒ Fixnum Also known as: z_index, z

Set the zindex of the interface. This controls the render order of interfaces. Interfaces with a lower zindex will render before those with a higher zindex.

Examples:

--4-- # rendered last
--3--
--2--
--1-- # rendered first

Vedeu.interface 'my_interface' do
  zindex 3
  # ...
end

Parameters:

  • value (Fixnum)

Returns:

  • (Fixnum)


306
307
308
# File 'lib/vedeu/dsl/interface.rb', line 306

def zindex(value)
  model.zindex = value
end