Class: Vedeu::Interfaces::DSL
- Inherits:
-
Object
- Object
- Vedeu::Interfaces::DSL
- 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
-
#client ⇒ Object
included
from DSL
readonly
protected
The object instance where the DSL is being used.
-
#model ⇒ void
included
from DSL
readonly
protected
The new model object which the DSL is constructing.
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
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.
-
.add_cursor!(name) ⇒ Vedeu::Cursors::Cursor
private
Registers a new cursor for the interface unless already registered.
-
.add_editor!(name) ⇒ Object
private
Registers a new document with the interface.
-
.add_focusable!(name) ⇒ Array<String|Symbol>
private
Registers interface name in focus list unless already registered.
-
.add_keymap!(name) ⇒ NilClass|Vedeu::Input::Keymap
private
Registers a new keymap for the interface unless already registered.
-
.become(klass, attributes) ⇒ Class
extended
from Common
private
Converts one class into another.
-
.boolean(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the value was a boolean.
-
.boolean?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
.client(&block) ⇒ Object
private
Returns the client object which called the DSL method.
-
.escape?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
.falsy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
.hash?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
.interface(name, &block) ⇒ Vedeu::Interfaces::Interface
Register an interface by name which will display output from an event or a command.
- .keymap?(name) ⇒ Boolean private
-
.line_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
.numeric?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
.snake_case(klass) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.stream_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
.string?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.truthy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
.view_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::View.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#attributes ⇒ Hash<Symbol => void>
included
from DSL
private
Returns the default attributes for the new model.
-
#background(value = '') ⇒ String
(also: #bg, #bgcolor, #background=, #bg=, #bgcolor=)
included
from DSL::Presentation
Define the background colour for an interface, line, or a stream.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#colour(attrs = {}) ⇒ Vedeu::Colours::Colour
(also: #colour=)
included
from DSL::Presentation
Define either or both foreground and background colours for an interface, line or a stream.
- #colour_attributes ⇒ Hash<Symbol => String> included from DSL::Presentation private
-
#cursor(value = true) ⇒ Vedeu::Cursors::Cursor
included
from DSL::Cursors
Set the cursor visibility on an interface.
-
#cursor! ⇒ Vedeu::Cursors::Cursor
(also: #show_cursor!)
included
from 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.
-
#editable(value = true) ⇒ Boolean
Set whether the interface is editable.
-
#editable! ⇒ Boolean
Set the interface to be editable.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#focus! ⇒ Array<String>
Specify this interface as being in focus when the application starts.
- #foreground(value = '') ⇒ Object (also: #fg, #fgcolor, #foreground=, #fg=, #fgcolor=) included from DSL::Presentation
-
#group(name) ⇒ Vedeu::Groups::Group
Specify a group for an interface.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#hide! ⇒ Boolean
Set the interface to invisible.
-
#initialize(model, client = nil) ⇒ void
included
from DSL
Returns a new instance of the DSL class including DSL.
- #keymap(name = model.name, &block) ⇒ Object (also: #keys)
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#method_missing(method, *args, &block) ⇒ void
included
from DSL
private
Attempts to find the missing method on the client object.
-
#name ⇒ NilClass|String|Symbol
included
from DSL
Returns the model name if available.
-
#no_cursor! ⇒ Vedeu::Cursors::Cursor
(also: #hide_cursor!)
included
from DSL::Cursors
Set the cursor to invisible for the interface or view.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#show! ⇒ Boolean
(also: #visible!)
Set the interface to visible.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#style(value) ⇒ Vedeu::Presentation::Style
(also: #style=, #styles, #styles=)
included
from DSL::Presentation
Define a style or styles for an interface, line or a stream.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#use(name) ⇒ Vedeu::Interfaces::Interface
Use a value from another model.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
-
#visible(value = true) ⇒ Boolean
Set the visibility of the interface.
-
#zindex(value) ⇒ Fixnum
(also: #z_index, #z)
Set the zindex of the interface.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Attribute Details
#client ⇒ Object (readonly, protected) Originally defined in module DSL
#model ⇒ void (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.
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
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
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.
.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.
#attributes ⇒ Hash<Symbol => void> (private) Originally defined in module DSL
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
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.
#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
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.
#colour_attributes ⇒ Hash<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.
139 140 141 |
# File 'lib/vedeu/interfaces/dsl.rb', line 139 def delay(value) model.delay = value end |
#editable(value = true) ⇒ Boolean
When an interface is made editable, then the cursor visibility will be set to visible.
Set whether the interface is editable.
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>
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
#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.
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.
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.
#name ⇒ NilClass|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.
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.
#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.
#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.
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.
321 322 323 |
# File 'lib/vedeu/interfaces/dsl.rb', line 321 def zindex(value) model.zindex = value end |