Class: Vedeu::API::Interface

Inherits:
Interface show all
Includes:
Helpers
Defined in:
lib/vedeu/api/interface.rb

Instance Attribute Summary

Attributes inherited from Interface

#attributes

Instance Method Summary collapse

Methods included from Helpers

#colour, #style

Methods inherited from Interface

build, #clear, #defaults, #define, define, #geometry, #initialize, #lines, #method_missing, #out_of_bounds, #to_s, #x_out_of_bounds?, #y_out_of_bounds?

Methods included from Presentation

#colour, #style

Methods included from Coercions

included

Constructor Details

This class inherits a constructor from Vedeu::Interface

Dynamic Method Handling

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

Instance Method Details

#centred(value) ⇒ Object

Instructs Vedeu to calculate x and y geometry automatically based on the centre character of the terminal, the width and the height.

Examples:

interface 'my_interface' do
  centred true
  ...


205
206
207
208
209
210
211
# File 'lib/vedeu/api/interface.rb', line 205

def centred(value)
  unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
    fail InvalidSyntax, 'Argument must be `true` or `false` for centred.'
  end

  attributes[:geometry][:centred] = value
end

#cursor(value) ⇒ Object

Define the cursor visibility for an interface. A ‘true` value will show the cursor, whilst `false` will hide it.

Examples:

interface 'my_interface' do
  cursor true
  ...


57
58
59
60
61
62
63
# File 'lib/vedeu/api/interface.rb', line 57

def cursor(value)
  unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
    fail InvalidSyntax, 'Argument must be `true` or `false` for cursor.'
  end

  attributes[:cursor] = value
end

#delay(value) ⇒ Object

To maintain performance interfaces can be delayed from refreshing too often, the reduces artefacts particularly when resizing the terminal screen.



73
74
75
# File 'lib/vedeu/api/interface.rb', line 73

def delay(value)
  attributes[:delay] = value
end

#group(value) ⇒ Object

Define 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:

interface 'my_interface' do
  group 'main_screen'
  ...


90
91
92
# File 'lib/vedeu/api/interface.rb', line 90

def group(value)
  attributes[:group] = value
end

#height(value) ⇒ Object

Define the number of characters/rows/lines tall the interface will be.

Examples:

interface 'my_interface' do
  height 8
  ...


187
188
189
190
191
# File 'lib/vedeu/api/interface.rb', line 187

def height(value)
  Vedeu.log(out_of_bounds('height')) if y_out_of_bounds?(value)

  attributes[:geometry][:height] = value
end

#line(value = '', &block) ⇒ Object

Define a single line in a view.

Examples:

view 'my_interface' do
  line 'This is a line of text...'
  line 'and so is this...'
  ...

view 'my_interface' do
  line do
    ... some line attributes ...
  end
end


25
26
27
28
29
30
31
32
33
# File 'lib/vedeu/api/interface.rb', line 25

def line(value = '', &block)
  if block_given?
    attributes[:lines] << Line.build(&block)

  else
    attributes[:lines] << Line.build({ streams: { text: value } })

  end
end

#name(value) ⇒ Object

The name of the interface. Used to reference the interface throughout your application’s execution lifetime.

Examples:

interface do
  name 'my_interface'
  ...


106
107
108
# File 'lib/vedeu/api/interface.rb', line 106

def name(value)
  attributes[:name] = value
end

#use(value) ⇒ Object

Use the specified interface; useful for sharing attributes with other interfaces.

See Also:



41
42
43
# File 'lib/vedeu/api/interface.rb', line 41

def use(value)
  Vedeu.use(value)
end

#width(value) ⇒ Object

Define the number of characters/columns wide the interface will be.

Examples:

interface 'my_interface' do
  width 25
  ...


170
171
172
173
174
# File 'lib/vedeu/api/interface.rb', line 170

def width(value)
  Vedeu.log(out_of_bounds('width')) if x_out_of_bounds?(value)

  attributes[:geometry][:width] = value
end

#x(value = 0, &block) ⇒ Object

Define the starting x position (column) of the interface.

Examples:

interface 'my_interface' do
  x 7 # start on column 7.

interface 'other_interface' do
  x { use('my_interface').east } # start on column 8, if
                                 # `my_interface` changes position,
                                 # `other_interface` will too.


126
127
128
129
130
131
132
# File 'lib/vedeu/api/interface.rb', line 126

def x(value = 0, &block)
  return attributes[:geometry][:x] = block if block_given?

  Vedeu.log(out_of_bounds('x')) if x_out_of_bounds?(value)

  attributes[:geometry][:x] = value
end

#y(value = 0, &block) ⇒ Object

Define the starting y position (row/line) of the interface.

Examples:

interface 'my_interface' do
  y  4
  ...

interface 'other_interface' do
  y  { use('my_interface').north } # start on row/line 3, if
  ...                              # `my_interface` changes position,
                                   # `other_interface` will too.


151
152
153
154
155
156
157
# File 'lib/vedeu/api/interface.rb', line 151

def y(value = 0, &block)
  return attributes[:geometry][:y] = block if block_given?

  Vedeu.log(out_of_bounds('y')) if y_out_of_bounds?(value)

  attributes[:geometry][:y] = value
end