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
Attributes included from DSL
Class Method Summary collapse
-
.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.
-
.client(&block) ⇒ Object
private
Returns the client object which called the DSL method.
-
.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
Instance Method Summary collapse
-
#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.
-
#focus! ⇒ Array<String>
Specify this interface as being in focus when the application starts.
-
#group(name) ⇒ Vedeu::Groups::Group
Specify a group for an interface.
-
#hide! ⇒ Boolean
Set the interface to invisible.
- #keymap(name = model.name, &block) ⇒ Object (also: #keys)
-
#show! ⇒ Boolean
(also: #visible!)
Set the interface to visible.
-
#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.
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
Methods included from DSL::Border
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.
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.
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.
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.
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.
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.
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
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
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)
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.
137 138 139 |
# File 'lib/vedeu/interfaces/dsl.rb', line 137 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.
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.
182 183 184 |
# File 'lib/vedeu/interfaces/dsl.rb', line 182 def editable! editable(true) end |
#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.
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.
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.
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
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.
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.
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.
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.
316 317 318 |
# File 'lib/vedeu/interfaces/dsl.rb', line 316 def zindex(value) model.zindex = value end |