Class: Vedeu::Interfaces::DSL

Inherits:
Object
  • Object
show all
Extended by:
Common
Includes:
Common, DSL, DSL::Border, DSL::Cursors, DSL::Geometry, DSL::Presentation, DSL::Use
Defined in:
lib/vedeu/interfaces/dsl.rb

Overview

DSL for creating interfaces.

Instance Attribute Summary

Attributes included from DSL

#client, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

absent?, array?, boolean, boolean?, empty_value?, escape?, falsy?, hash?, line_model?, numeric?, positionable?, present?, snake_case, stream_model?, string?, symbol?, truthy?, view_model?

Methods included from DSL::Presentation

#background, #colour, #colour_attributes, #foreground, #no_wordwrap!, #style, #wordwrap

Methods included from DSL::Geometry

included

Methods included from DSL::Border

included

Methods included from DSL::Cursors

#cursor, #cursor!, #no_cursor!

Methods included from DSL

#attributes, #initialize, #method_missing, #name

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.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:

See Also:



67
68
69
# File 'lib/vedeu/interfaces/dsl.rb', line 67

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.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



76
77
78
# File 'lib/vedeu/interfaces/dsl.rb', line 76

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

.add_editor!(name) ⇒ Object (private)

Registers a new document with the interface.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.



83
84
85
# File 'lib/vedeu/interfaces/dsl.rb', line 83

def add_editor!(name)
  Vedeu::Editor::Document.store(name: name)
end

.add_focusable!(name) ⇒ Array<String|Symbol> (private)

Registers interface name in focus list unless already registered.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:

  • (Array<String|Symbol>)


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

def add_focusable!(name)
  Vedeu::Models::Focus.add(name)
end

.add_keymap!(name) ⇒ NilClass|Vedeu::Input::Keymap (private)

Registers a new keymap for the interface unless already registered.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



101
102
103
# File 'lib/vedeu/interfaces/dsl.rb', line 101

def add_keymap!(name)
  Vedeu::Input::Keymap.store(name: name) unless keymap?(name)
end

.client(&block) ⇒ Object (private)

Returns the client object which called the DSL method.

Parameters:

  • block (Proc)

Returns:

  • (Object)


109
110
111
# File 'lib/vedeu/interfaces/dsl.rb', line 109

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

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

TODO:

More documentation required.

Register an interface by name which will display output from an event or a 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 (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • block (Proc)

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

Returns:

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vedeu/interfaces/dsl.rb', line 39

def interface(name, &block)
  raise Vedeu::Error::MissingRequired unless name
  raise Vedeu::Error::RequiresBlock unless block_given?

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

  interface = Vedeu::Interfaces::Interface
              .build(attributes, &block)
              .store

  add_buffers!(name)
  add_cursor!(name)
  add_editor!(name) if interface.editable?
  add_focusable!(name)
  add_keymap!(name)

  interface
end

.keymap?(name) ⇒ Boolean (private)

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



117
118
119
# File 'lib/vedeu/interfaces/dsl.rb', line 117

def keymap?(name)
  Vedeu.keymaps.registered?(name)
end

Instance Method Details

#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)


137
138
139
# File 'lib/vedeu/interfaces/dsl.rb', line 137

def delay(value)
  model.delay = value
end

#editable(value = true) ⇒ Boolean

Note:

When an interface is made editable, then the cursor visibility will be set to visible.

Set whether the interface is editable.

Examples:

Vedeu.interface :my_interface do
  editable true # => The interface/view can be edited.

  # or...

  editable! # => Convenience method for above.

  # ...
end

Vedeu.interface :my_interface do
  editable false # => The interface/view cannot be edited.

  # or...

  editable # => as above
  # ...
end

Parameters:

  • value (Boolean) (defaults to: true)

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

Returns:



171
172
173
174
175
176
177
# File 'lib/vedeu/interfaces/dsl.rb', line 171

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

  cursor(true) if boolean

  model.editable = boolean
end

#editable!Boolean

Set the interface to be editable.

Returns:



182
183
184
# File 'lib/vedeu/interfaces/dsl.rb', line 182

def editable!
  editable(true)
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.



201
202
203
# File 'lib/vedeu/interfaces/dsl.rb', line 201

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

#group(name) ⇒ Vedeu::Groups::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 (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



217
218
219
220
221
222
223
# File 'lib/vedeu/interfaces/dsl.rb', line 217

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:



255
256
257
# File 'lib/vedeu/interfaces/dsl.rb', line 255

def hide!
  visible(false)
end

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

Parameters:

  • name (NilClass|Symbol|String) (defaults to: model.name)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

See Also:



227
228
229
# File 'lib/vedeu/interfaces/dsl.rb', line 227

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

#show!Boolean Also known as: visible!

Set the interface to visible.

Examples:

Vedeu.interface :my_interface do
  show!

  # ... some code
end

Returns:



242
243
244
# File 'lib/vedeu/interfaces/dsl.rb', line 242

def show!
  visible(true)
end

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

Use a value from another model.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

Returns:



263
264
265
# File 'lib/vedeu/interfaces/dsl.rb', line 263

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:



293
294
295
296
297
# File 'lib/vedeu/interfaces/dsl.rb', line 293

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)


316
317
318
# File 'lib/vedeu/interfaces/dsl.rb', line 316

def zindex(value)
  model.zindex = value
end