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 collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

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

Instance Attribute Details

#clientObject (readonly, protected) Originally defined in module DSL

#modelvoid (readonly, protected) Originally defined in module DSL

Class Method Details

.absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

.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.

See Also:



69
70
71
# File 'lib/vedeu/interfaces/dsl.rb', line 69

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.



78
79
80
# File 'lib/vedeu/interfaces/dsl.rb', line 78

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

.add_editor!(name) ⇒ Object (private)

Registers a new document with the interface.



85
86
87
# File 'lib/vedeu/interfaces/dsl.rb', line 85

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.



94
95
96
# File 'lib/vedeu/interfaces/dsl.rb', line 94

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.



103
104
105
# File 'lib/vedeu/interfaces/dsl.rb', line 103

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

.become(klass, attributes) ⇒ Class Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts one class into another.

.boolean(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the value was a boolean.

.boolean?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Boolean.

.client(&block) ⇒ Object (private)

Returns the client object which called the DSL method.



111
112
113
# File 'lib/vedeu/interfaces/dsl.rb', line 111

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

.escape?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

.falsy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered false.

.hash?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Hash.

.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

Raises:



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

def interface(name, &block)
  fail Vedeu::Error::MissingRequired unless name
  fail 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)



119
120
121
# File 'lib/vedeu/interfaces/dsl.rb', line 119

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

.line_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Line.

.numeric?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

.present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

.snake_case(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

.stream_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Stream.

.string?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

.truthy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered true.

.view_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::View.

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

#attributesHash<Symbol => void> (private) Originally defined in module DSL

Note:

Specific DSL classes may be overriding this method.

Returns the default attributes for the new model.

#background(value = '') ⇒ String Also known as: bg, bgcolor, background=, bg=, bgcolor= Originally defined in module DSL::Presentation

Note:

The last defined background colour for a particular interface, line or stream overrides previously defined entries in the same block.

Define the background colour for an interface, line, or a stream. When called with a block, will create a new stream with the background colour specified. When the block terminates, the background will return to that of the parent.

Examples:

interface 'my_interface' do
  background '#0022ff' # /or/ (blue)
  bgcolor    '#22ff00' # /or/ (blue is overridden to green)
  bg         '#ff0022' #      (green is overridden to red)
  # ...

  lines do
    background '#2200ff'
    # ...

    stream do
      background '#22ff00'
      # ...
    end
  end
end

#become(klass, attributes) ⇒ Class Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts one class into another.

#boolean(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the value was a boolean.

#boolean?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Boolean.

#colour(attrs = {}) ⇒ Vedeu::Colours::Colour Also known as: colour= Originally defined in module DSL::Presentation

Note:

Rejects invalid keys and empty/nil attributes. Also, the last defined colour for a particular interface, line or stream overrides previously defined entries in the same block.

Define either or both foreground and background colours for an interface, line or a stream. At least one attribute is required.

Examples:

interface 'my_interface' do
  colour background: '#ff00ff', foreground: '#ffff00'
  # ...

  lines do
    colour background: '#000000', foreground: '#ffffff'
    # ...

    stream do
      colour background: '#000000', foreground: '#ffffff'
      # ...
    end
  end
end

#colour_attributesHash<Symbol => String> (private) Originally defined in module DSL::Presentation

#cursor(value = true) ⇒ Vedeu::Cursors::Cursor Originally defined in module DSL::Cursors

Set the cursor visibility on an interface.

#cursor!Vedeu::Cursors::Cursor Also known as: show_cursor! Originally defined in module DSL::Cursors

Set the cursor to visible for the interface or view.

#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


139
140
141
# File 'lib/vedeu/interfaces/dsl.rb', line 139

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


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

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

  cursor(true) if boolean

  model.editable = boolean
end

#editable!Boolean

Set the interface to be editable.



184
185
186
# File 'lib/vedeu/interfaces/dsl.rb', line 184

def editable!
  editable(true)
end

#escape?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

#falsy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered false.

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



203
204
205
# File 'lib/vedeu/interfaces/dsl.rb', line 203

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

#foreground(value = '') ⇒ Object Also known as: fg, fgcolor, foreground=, fg=, fgcolor= Originally defined in module DSL::Presentation

See Also:

#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


220
221
222
223
224
225
226
# File 'lib/vedeu/interfaces/dsl.rb', line 220

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

  model.group = name

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

#hash?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Hash.

#hide!Boolean

Set the interface to invisible.

Examples:

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


259
260
261
# File 'lib/vedeu/interfaces/dsl.rb', line 259

def hide!
  visible(false)
end

#initialize(model, client = nil) ⇒ void Originally defined in module DSL

Returns a new instance of the DSL class including Vedeu::DSL.

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



231
232
233
# File 'lib/vedeu/interfaces/dsl.rb', line 231

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

#line_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Line.

#nameNilClass|String|Symbol Originally defined in module DSL

Returns the model name if available.

#no_cursor!Vedeu::Cursors::Cursor Also known as: hide_cursor! Originally defined in module DSL::Cursors

Set the cursor to invisible for the interface or view.

#numeric?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

#show!Boolean Also known as: visible!

Set the interface to visible.

Examples:

Vedeu.interface :my_interface do
  show!

  # ... some code
end


246
247
248
# File 'lib/vedeu/interfaces/dsl.rb', line 246

def show!
  visible(true)
end

#snake_case(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

#stream_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Stream.

#string?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

#style(value) ⇒ Vedeu::Presentation::Style Also known as: style=, styles, styles= Originally defined in module DSL::Presentation

Define a style or styles for an interface, line or a stream.

Examples:

interface 'my_interface' do
  style 'normal'
  # ...
end

lines do
  style ['bold', 'underline']
  # ...
end

stream do
  style 'blink'
  # ...
end

#truthy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered true.

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

Use a value from another model.



268
269
270
# File 'lib/vedeu/interfaces/dsl.rb', line 268

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

#view_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::View.

#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


298
299
300
301
302
# File 'lib/vedeu/interfaces/dsl.rb', line 298

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


321
322
323
# File 'lib/vedeu/interfaces/dsl.rb', line 321

def zindex(value)
  model.zindex = value
end