Class: Vedeu::Interfaces::DSL
- Inherits:
-
Object
- Object
- Vedeu::Interfaces::DSL
- Extended by:
- Common
- Includes:
- Common, DSL, DSL::Presentation, DSL::Shared, DSL::Text, 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
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_focusable!(name) ⇒ void
private
Registers interface name in focus list unless already registered.
-
.client(&block) ⇒ Object
private
Returns the client object which called the DSL method.
-
.demodulize(klass) ⇒ String
extended
from Common
Removes the module part from the expression in the string.
-
.interface(name, &block) ⇒ Vedeu::Interfaces::Interface
Register an interface by name which will display output from an event or a command.
-
.present?(variable) ⇒ Boolean
extended
from Common
Returns a boolean indicating whether a variable has a useful value.
-
.snake_case(name) ⇒ String
extended
from Common
Converts a class name to a lowercase snake case string.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
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.
-
#border(name = nil, &block) ⇒ Vedeu::Borders::Border
included
from DSL::Shared
Allows the setting of a border for the interface.
-
#border! ⇒ Vedeu::Borders::Border
included
from DSL::Shared
Applies the default border to the interface.
-
#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
Set the cursor visibility on an interface.
-
#cursor! ⇒ Vedeu::Cursors::Cursor
Set the cursor to visible for the interface.
-
#delay(value) ⇒ Fixnum|Float
To maintain performance interfaces can be delayed from refreshing too often, the reduces artefacts particularly when resizing the terminal screen.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#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
-
#geometry(name = nil, &block) ⇒ Vedeu::Geometry::Geometry
included
from DSL::Shared
Define the geometry for an interface.
-
#group(name) ⇒ Vedeu::Groups::Group
Specify a group for an interface.
-
#hide! ⇒ Boolean
Set the interface to invisible.
-
#initialize(model, client = nil) ⇒ void
included
from DSL
Returns an instance of the DSL class including DSL.
- #keymap(name = model.name, &block) ⇒ Object (also: #keys)
-
#method_missing(method, *args, &block) ⇒ void
included
from DSL
private
Attempts to find the missing method on the client object.
-
#name(value) ⇒ String|Symbol
The name of the interface.
-
#no_cursor! ⇒ Vedeu::Cursors::Cursor
Set the cursor to invisible for the interface.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#show! ⇒ Boolean
Set the interface to visible.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#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.
-
#text(value = '', options = {}) ⇒ String
(also: #text=, #align, #center, #centre, #left, #right, #align=, #center=, #centre=, #left=, #right=)
included
from DSL::Text
Specify the content for a view.
-
#use(name) ⇒ Vedeu::Interfaces::Interface
Use a value from another model.
-
#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
Returns The object instance where the DSL is being used.
#model ⇒ void (readonly, protected) Originally defined in module DSL
This method returns an undefined value.
Returns The new model object which the DSL is constructing.
Class Method Details
.absent?(variable) ⇒ Boolean Originally defined in module Common
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.
60 61 62 |
# File 'lib/vedeu/interfaces/dsl.rb', line 60 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.
69 70 71 |
# File 'lib/vedeu/interfaces/dsl.rb', line 69 def add_cursor!(name) Vedeu::Cursors::Cursor.store(name: name) end |
.add_focusable!(name) ⇒ void (private)
This method returns an undefined value.
Registers interface name in focus list unless already registered.
78 79 80 |
# File 'lib/vedeu/interfaces/dsl.rb', line 78 def add_focusable!(name) Vedeu::Models::Focus.add(name) end |
.client(&block) ⇒ Object (private)
Returns the client object which called the DSL method.
86 87 88 |
# File 'lib/vedeu/interfaces/dsl.rb', line 86 def client(&block) eval('self', block.binding) end |
.demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
.interface(name, &block) ⇒ Vedeu::Interfaces::Interface
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vedeu/interfaces/dsl.rb', line 37 def interface(name, &block) fail Vedeu::Error::RequiresBlock unless block_given? fail Vedeu::Error::MissingRequired, 'name not given'.freeze unless present?(name) add_buffers!(name) add_cursor!(name) add_focusable!(name) attributes = { client: client(&block), name: name } Vedeu::Interfaces::Interface.build(attributes, &block).store end |
.present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
.snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
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.
#border(name = nil, &block) ⇒ Vedeu::Borders::Border Originally defined in module DSL::Shared
Allows the setting of a border for the interface.
#border! ⇒ Vedeu::Borders::Border Originally defined in module DSL::Shared
Applies the default border to the interface.
#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
Set the cursor visibility on an interface.
123 124 125 126 127 |
# File 'lib/vedeu/interfaces/dsl.rb', line 123 def cursor(value = true) boolean = value ? true : false Vedeu::Cursors::Cursor.store(name: model.name, visible: boolean) end |
#cursor! ⇒ Vedeu::Cursors::Cursor
Set the cursor to visible for the interface.
132 133 134 |
# File 'lib/vedeu/interfaces/dsl.rb', line 132 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.
150 151 152 |
# File 'lib/vedeu/interfaces/dsl.rb', line 150 def delay(value) model.delay = value end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#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.
169 170 171 |
# File 'lib/vedeu/interfaces/dsl.rb', line 169 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
#geometry(name = nil, &block) ⇒ Vedeu::Geometry::Geometry Originally defined in module DSL::Shared
Define the geometry for an interface.
#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.
186 187 188 189 190 191 192 |
# File 'lib/vedeu/interfaces/dsl.rb', line 186 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.
247 248 249 |
# File 'lib/vedeu/interfaces/dsl.rb', line 247 def hide! visible(false) end |
#initialize(model, client = nil) ⇒ void Originally defined in module DSL
Returns an instance of the DSL class including Vedeu::DSL.
#keymap(name = model.name, &block) ⇒ Object Also known as: keys
197 198 199 |
# File 'lib/vedeu/interfaces/dsl.rb', line 197 def keymap(name = model.name, &block) Vedeu.keymap(name, &block) end |
#name(value) ⇒ String|Symbol
The name of the interface. Used to reference the interface throughout your application’s execution lifetime.
214 215 216 |
# File 'lib/vedeu/interfaces/dsl.rb', line 214 def name(value) model.name = value end |
#no_cursor! ⇒ Vedeu::Cursors::Cursor
Set the cursor to invisible for the interface.
221 222 223 |
# File 'lib/vedeu/interfaces/dsl.rb', line 221 def no_cursor! cursor(false) end |
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#show! ⇒ Boolean
Set the interface to visible.
235 236 237 |
# File 'lib/vedeu/interfaces/dsl.rb', line 235 def show! visible(true) end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#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.
#text(value = '', options = {}) ⇒ String Also known as: text=, align, center, centre, left, right, align=, center=, centre=, left=, right= Originally defined in module DSL::Text
If using the convenience methods; left, centre, center or right, then a specified anchor will be ignored.
Specify the content for a view. Provides the means to align a string (or object responding to ‘to_s`), and add it as a Line or to the Stream.
#use(name) ⇒ Vedeu::Interfaces::Interface
Use a value from another model.
256 257 258 |
# File 'lib/vedeu/interfaces/dsl.rb', line 256 def use(name) model.repository.by_name(name) end |
#visible(value = true) ⇒ Boolean
Set the visibility of the interface.
286 287 288 289 290 |
# File 'lib/vedeu/interfaces/dsl.rb', line 286 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.
309 310 311 |
# File 'lib/vedeu/interfaces/dsl.rb', line 309 def zindex(value) model.zindex = value end |