Class: Vedeu::Interfaces::DSL Private

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

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

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)

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.

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:



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

def add_buffers!(name)
  Vedeu::Buffers::Buffer.new(name: name).store
end

.add_cursor!(name) ⇒ Vedeu::Cursors::Cursor (private)

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.

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:



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

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

.add_editor!(name) ⇒ Object (private)

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.

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



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

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

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

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.

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


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

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

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

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.

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:



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

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

.client(&block) ⇒ Object (private)

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 the client object which called the DSL method.

Parameters:

  • block (Proc)

Returns:

  • (Object)


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

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

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

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.

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)

Returns:

Raises:



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

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)

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.

Parameters:

  • name (NilClass|Symbol|String)

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

Returns:



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

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

Instance Method Details

#delay(value) ⇒ Fixnum|Float

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.

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)


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

def delay(value)
  model.delay = value
end

#editable(value = true) ⇒ Boolean

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.

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:



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

def editable(value = true)
  cursor(true) if Vedeu::Boolean.coerce(value)

  model.editable = Vedeu::Boolean.coerce(value)
end

#editable!Boolean

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.

Set the interface to be editable.

Returns:



179
180
181
# File 'lib/vedeu/interfaces/dsl.rb', line 179

def editable!
  editable(true)
end

#focus!Array<String>

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.

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.



198
199
200
# File 'lib/vedeu/interfaces/dsl.rb', line 198

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

#group(name) ⇒ Vedeu::Groups::Group

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.

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:



214
215
216
217
218
219
220
# File 'lib/vedeu/interfaces/dsl.rb', line 214

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

  model.group = name

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

#hide!Boolean

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.

Set the interface to invisible.

Examples:

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

Returns:



252
253
254
# File 'lib/vedeu/interfaces/dsl.rb', line 252

def hide!
  visible(false)
end

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

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.

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:



224
225
226
# File 'lib/vedeu/interfaces/dsl.rb', line 224

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

#show!Boolean Also known as: visible!

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.

Set the interface to visible.

Examples:

Vedeu.interface :my_interface do
  show!

  # ... some code
end

Returns:



239
240
241
# File 'lib/vedeu/interfaces/dsl.rb', line 239

def show!
  visible(true)
end

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

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.

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:



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

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

#visible(value = true) ⇒ Boolean

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.

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:



290
291
292
# File 'lib/vedeu/interfaces/dsl.rb', line 290

def visible(value = true)
  model.visible = Vedeu::Boolean.coerce(value)
end

#zindex(value) ⇒ Fixnum Also known as: z_index, z

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.

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)


311
312
313
# File 'lib/vedeu/interfaces/dsl.rb', line 311

def zindex(value)
  model.zindex = value
end