vedeu 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +6 -0
  4. data/bin/vedeu_drb_client +8 -3
  5. data/bin/vedeu_drb_server +113 -0
  6. data/bin/vedeu_test +1 -1
  7. data/docs/events.md +0 -127
  8. data/examples/borders_app.rb +17 -7
  9. data/examples/configuration_app.rb +1 -1
  10. data/examples/cursor_app.rb +4 -2
  11. data/examples/drb_app.rb +113 -0
  12. data/examples/focus_app.rb +1 -1
  13. data/examples/geometry_app.rb +1 -1
  14. data/examples/hello_world.rb +1 -1
  15. data/examples/lines_app.rb +1 -1
  16. data/features/start_stop.feature +1 -1
  17. data/inch.yml +5 -0
  18. data/lib/vedeu/all.rb +2 -0
  19. data/lib/vedeu/api.rb +1 -0
  20. data/lib/vedeu/application.rb +17 -36
  21. data/lib/vedeu/bindings.rb +134 -27
  22. data/lib/vedeu/buffers/display_buffer.rb +1 -4
  23. data/lib/vedeu/configuration/api.rb +15 -14
  24. data/lib/vedeu/configuration/cli.rb +17 -16
  25. data/lib/vedeu/configuration/configuration.rb +3 -1
  26. data/lib/vedeu/cursor/cursor.rb +6 -8
  27. data/lib/vedeu/cursor/move_cursor.rb +1 -0
  28. data/lib/vedeu/cursor/toggle_cursor.rb +1 -0
  29. data/lib/vedeu/debug.rb +23 -0
  30. data/lib/vedeu/distributed/all.rb +1 -1
  31. data/lib/vedeu/distributed/client.rb +55 -13
  32. data/lib/vedeu/distributed/server.rb +207 -0
  33. data/lib/vedeu/distributed/subprocess.rb +22 -21
  34. data/lib/vedeu/distributed/templates/default_application.vedeu +3 -1
  35. data/lib/vedeu/distributed/test_application.rb +2 -1
  36. data/lib/vedeu/distributed/uri.rb +1 -0
  37. data/lib/vedeu/dsl/all.rb +4 -2
  38. data/lib/vedeu/dsl/components/border.rb +11 -10
  39. data/lib/vedeu/dsl/components/geometry.rb +1 -0
  40. data/lib/vedeu/dsl/components/keymap.rb +1 -0
  41. data/lib/vedeu/dsl/components/menu.rb +1 -0
  42. data/lib/vedeu/dsl/interface.rb +1 -0
  43. data/lib/vedeu/dsl/line.rb +3 -1
  44. data/lib/vedeu/dsl/shared/colour.rb +1 -0
  45. data/lib/vedeu/dsl/shared/style.rb +1 -0
  46. data/lib/vedeu/dsl/shared/text.rb +2 -0
  47. data/lib/vedeu/dsl/shared/use.rb +3 -0
  48. data/lib/vedeu/dsl/stream.rb +3 -1
  49. data/lib/vedeu/dsl/view.rb +1 -0
  50. data/lib/vedeu/events/event.rb +9 -6
  51. data/lib/vedeu/events/trigger.rb +18 -7
  52. data/lib/vedeu/exceptions.rb +4 -1
  53. data/lib/vedeu/input/input.rb +1 -0
  54. data/lib/vedeu/input/key.rb +0 -1
  55. data/lib/vedeu/input/keymap.rb +5 -3
  56. data/lib/vedeu/input/keys.rb +1 -0
  57. data/lib/vedeu/input/mapper.rb +1 -0
  58. data/lib/vedeu/launcher.rb +35 -12
  59. data/lib/vedeu/main_loop.rb +53 -0
  60. data/lib/vedeu/models/collection.rb +11 -3
  61. data/lib/vedeu/models/focus.rb +3 -3
  62. data/lib/vedeu/models/geometry.rb +8 -16
  63. data/lib/vedeu/models/group.rb +1 -0
  64. data/lib/vedeu/models/menu.rb +2 -1
  65. data/lib/vedeu/models/model.rb +7 -1
  66. data/lib/vedeu/models/view/char.rb +52 -44
  67. data/lib/vedeu/models/view/chars.rb +1 -0
  68. data/lib/vedeu/models/view/composition.rb +2 -1
  69. data/lib/vedeu/models/view/interface.rb +5 -3
  70. data/lib/vedeu/models/view/interfaces.rb +1 -0
  71. data/lib/vedeu/models/view/line.rb +2 -1
  72. data/lib/vedeu/models/view/stream.rb +2 -1
  73. data/lib/vedeu/models/view/streams.rb +1 -0
  74. data/lib/vedeu/output/all.rb +4 -0
  75. data/lib/vedeu/output/border.rb +75 -206
  76. data/lib/vedeu/output/compositor.rb +1 -0
  77. data/lib/vedeu/output/html_char.rb +119 -0
  78. data/lib/vedeu/output/html_renderer.rb +89 -0
  79. data/lib/vedeu/output/output.rb +48 -44
  80. data/lib/vedeu/output/position_index.rb +12 -1
  81. data/lib/vedeu/output/renderer.rb +28 -0
  82. data/lib/vedeu/output/viewport.rb +14 -14
  83. data/lib/vedeu/output/virtual_buffer.rb +56 -0
  84. data/lib/vedeu/output/virtual_terminal.rb +42 -34
  85. data/lib/vedeu/output/wordwrap.rb +3 -0
  86. data/lib/vedeu/output/writer.rb +13 -1
  87. data/lib/vedeu/presentation/background.rb +1 -0
  88. data/lib/vedeu/presentation/colour.rb +8 -7
  89. data/lib/vedeu/presentation/foreground.rb +1 -0
  90. data/lib/vedeu/presentation/presentation.rb +43 -7
  91. data/lib/vedeu/presentation/translator.rb +12 -0
  92. data/lib/vedeu/repositories/repository.rb +8 -8
  93. data/lib/vedeu/support/bounding_area.rb +2 -0
  94. data/lib/vedeu/support/coercions.rb +2 -1
  95. data/lib/vedeu/support/common.rb +1 -0
  96. data/lib/vedeu/support/console.rb +17 -23
  97. data/lib/vedeu/support/content_geometry.rb +2 -0
  98. data/lib/vedeu/support/coordinate.rb +1 -0
  99. data/lib/vedeu/support/esc.rb +58 -29
  100. data/lib/vedeu/support/grid.rb +1 -0
  101. data/lib/vedeu/support/limit.rb +9 -0
  102. data/lib/vedeu/support/log.rb +31 -9
  103. data/lib/vedeu/support/node.rb +8 -18
  104. data/lib/vedeu/support/position.rb +13 -34
  105. data/lib/vedeu/support/position_validator.rb +3 -0
  106. data/lib/vedeu/support/read.rb +1 -0
  107. data/lib/vedeu/support/refresh.rb +3 -2
  108. data/lib/vedeu/support/terminal.rb +11 -5
  109. data/lib/vedeu/support/trace.rb +16 -1
  110. data/lib/vedeu/support/visible.rb +2 -0
  111. data/lib/vedeu/support/write.rb +1 -0
  112. data/lib/vedeu/traps.rb +1 -0
  113. data/lib/vedeu.rb +2 -0
  114. data/test/integration/distributed_test.rb +10 -8
  115. data/test/lib/vedeu/api_test.rb +3 -7
  116. data/test/lib/vedeu/application_test.rb +2 -5
  117. data/test/lib/vedeu/configuration/api_test.rb +12 -0
  118. data/test/lib/vedeu/cursor/cursor_test.rb +2 -0
  119. data/test/lib/vedeu/distributed/client_test.rb +17 -7
  120. data/test/lib/vedeu/distributed/server_test.rb +56 -0
  121. data/test/lib/vedeu/distributed/test_application_test.rb +7 -3
  122. data/test/lib/vedeu/dsl/components/border_test.rb +10 -2
  123. data/test/lib/vedeu/dsl/interface_test.rb +6 -0
  124. data/test/lib/vedeu/dsl/line_test.rb +19 -0
  125. data/test/lib/vedeu/dsl/shared/colour_test.rb +4 -26
  126. data/test/lib/vedeu/dsl/shared/text_test.rb +8 -1
  127. data/test/lib/vedeu/dsl/stream_test.rb +13 -1
  128. data/test/lib/vedeu/input/input_test.rb +1 -1
  129. data/test/lib/vedeu/input/key_test.rb +3 -16
  130. data/test/lib/vedeu/launcher_test.rb +11 -1
  131. data/test/lib/vedeu/main_loop_test.rb +41 -0
  132. data/test/lib/vedeu/models/geometry_test.rb +15 -34
  133. data/test/lib/vedeu/models/view/char_test.rb +44 -45
  134. data/test/lib/vedeu/models/view/interface_test.rb +6 -0
  135. data/test/lib/vedeu/models/view/line_test.rb +1 -1
  136. data/test/lib/vedeu/models/view/stream_test.rb +1 -1
  137. data/test/lib/vedeu/output/border_test.rb +6 -5
  138. data/test/lib/vedeu/output/compositor_test.rb +2 -20
  139. data/test/lib/vedeu/output/html_char_test.rb +85 -0
  140. data/test/lib/vedeu/output/html_renderer_test.rb +37 -0
  141. data/test/lib/vedeu/output/position_index_test.rb +2 -10
  142. data/test/lib/vedeu/output/renderer_test.rb +24 -0
  143. data/test/lib/vedeu/output/virtual_buffer_test.rb +53 -0
  144. data/test/lib/vedeu/output/virtual_terminal_test.rb +32 -2
  145. data/test/lib/vedeu/presentation/background_test.rb +41 -1
  146. data/test/lib/vedeu/presentation/colour_test.rb +10 -6
  147. data/test/lib/vedeu/presentation/foreground_test.rb +46 -6
  148. data/test/lib/vedeu/presentation/presentation_test.rb +44 -1
  149. data/test/lib/vedeu/presentation/translator_test.rb +34 -0
  150. data/test/lib/vedeu/repositories/repository_test.rb +1 -1
  151. data/test/lib/vedeu/support/bounding_area_test.rb +4 -12
  152. data/test/lib/vedeu/support/console_test.rb +9 -50
  153. data/test/lib/vedeu/support/esc_test.rb +7 -7
  154. data/test/lib/vedeu/support/position_test.rb +42 -0
  155. data/test/lib/vedeu/support/terminal_test.rb +5 -20
  156. data/test/lib/vedeu/support/write_test.rb +42 -18
  157. data/test/support/helpers/all.rb +0 -1
  158. data/test/support/helpers/repository_test_module.rb +1 -0
  159. data/test/test_helper.rb +5 -2
  160. data/vedeu.gemspec +7 -5
  161. metadata +60 -14
  162. data/lib/vedeu/distributed/application.rb +0 -91
  163. data/test/lib/vedeu/distributed/application_test.rb +0 -24
  164. data/test/support/helpers/presentation.rb +0 -16
@@ -7,6 +7,7 @@ module Vedeu
7
7
  # characters.
8
8
  #
9
9
  # @api private
10
+ #
10
11
  class Colour
11
12
 
12
13
  include Vedeu::Coercions
@@ -24,24 +25,24 @@ module Vedeu
24
25
  def initialize(attributes = {})
25
26
  @attributes = defaults.merge(attributes)
26
27
 
27
- @background = Background.escape_sequence(@attributes[:background])
28
- @foreground = Foreground.escape_sequence(@attributes[:foreground])
28
+ @background = Background.coerce(@attributes[:background])
29
+ @foreground = Foreground.coerce(@attributes[:foreground])
29
30
  end
30
31
 
31
- # Converts the value into a terminal escape sequence.
32
+ # Converts the value into a Vedeu::Foreground.
32
33
  #
33
34
  # @param value [String]
34
35
  # @return [String]
35
36
  def foreground=(value)
36
- @foreground = Foreground.escape_sequence(value)
37
+ @foreground = Foreground.coerce(value)
37
38
  end
38
39
 
39
- # Converts the value into a terminal escape sequence.
40
+ # Converts the value into a Vedeu::Background.
40
41
  #
41
42
  # @param value [String]
42
43
  # @return [String]
43
44
  def background=(value)
44
- @background = Background.escape_sequence(value)
45
+ @background = Background.coerce(value)
45
46
  end
46
47
 
47
48
  # Returns both or either of the converted attributes into a single escape
@@ -49,7 +50,7 @@ module Vedeu
49
50
  #
50
51
  # @return [String]
51
52
  def to_s
52
- foreground + background
53
+ foreground.to_s + background.to_s
53
54
  end
54
55
 
55
56
  private
@@ -8,6 +8,7 @@ module Vedeu
8
8
  # {Vedeu::Background}) of a terminal colour escape sequence.
9
9
  #
10
10
  # @api private
11
+ #
11
12
  class Foreground < Translator
12
13
 
13
14
  private
@@ -4,8 +4,37 @@ module Vedeu
4
4
  # Interface, Line and Stream.
5
5
  #
6
6
  # @api private
7
+ #
7
8
  module Presentation
8
9
 
10
+ # @return [Vedeu::Background|NilClass]
11
+ def background
12
+ if colour
13
+ colour.background
14
+ end
15
+ end
16
+
17
+ # @return [Vedeu::Foreground|NilClass]
18
+ def foreground
19
+ if colour
20
+ colour.foreground
21
+ end
22
+ end
23
+
24
+ # @return [Vedeu::Background|NilClass]
25
+ def parent_background
26
+ if parent_colour
27
+ parent_colour.background
28
+ end
29
+ end
30
+
31
+ # @return [Vedeu::Foreground|NilClass]
32
+ def parent_foreground
33
+ if parent_colour
34
+ parent_colour.foreground
35
+ end
36
+ end
37
+
9
38
  # @return [Vedeu::Colour]
10
39
  def colour
11
40
  Vedeu::Colour.coerce(@colour)
@@ -32,23 +61,30 @@ module Vedeu
32
61
  #
33
62
  # @return [String] An escape sequence with value interpolated.
34
63
  def to_s
35
- render_position { render_colour { render_style { value } } }
64
+ render_position { render_colour { render_style { render_border { value } } } }
36
65
  end
37
66
 
38
67
  private
39
68
 
40
- # @return [String]
69
+ # @return [String|NilClass]
41
70
  def parent_colour
42
- return '' unless parent
71
+ parent.colour if parent
72
+ end
43
73
 
44
- parent.colour
74
+ # @return [String|NilClass]
75
+ def parent_style
76
+ parent.style if parent
45
77
  end
46
78
 
47
79
  # @return [String]
48
- def parent_style
49
- return '' unless parent
80
+ def render_border
81
+ if self.respond_to?(:border) && !border.nil?
82
+ Esc.border { yield }
50
83
 
51
- parent.style
84
+ else
85
+ yield
86
+
87
+ end
52
88
  end
53
89
 
54
90
  # Renders the colour attributes of the receiver, yields (to then render the
@@ -22,6 +22,7 @@ module Vedeu
22
22
  #
23
23
  # @todo More documentation required (create a fancy chart!)
24
24
  # @api private
25
+ #
25
26
  class Translator
26
27
 
27
28
  include Vedeu::Coercions
@@ -67,6 +68,17 @@ module Vedeu
67
68
  end
68
69
  alias_method :to_s, :escape_sequence
69
70
 
71
+ # @return [String]
72
+ def to_html
73
+ if rgb?
74
+ colour
75
+
76
+ else
77
+ ''
78
+
79
+ end
80
+ end
81
+
70
82
  private
71
83
 
72
84
  # @return [Boolean]
@@ -12,6 +12,7 @@ module Vedeu
12
12
  # { 'models' => [Model] }
13
13
  #
14
14
  # @api private
15
+ #
15
16
  class Repository
16
17
 
17
18
  include Vedeu::Common
@@ -74,13 +75,13 @@ module Vedeu
74
75
  # Find a model by name, registers the model by name if not found.
75
76
  #
76
77
  # @param name [String]
77
- # @return []
78
+ # @return [void]
78
79
  def find_or_create(name)
79
80
  if registered?(name)
80
81
  find(name)
81
82
 
82
83
  else
83
- Vedeu.log("Model (#{model}) not found, registering: '#{name}'")
84
+ Vedeu.log(type: :store, message: "Model (#{model}) not found, registering: '#{name}'")
84
85
 
85
86
  model.new(name).store
86
87
  end
@@ -141,12 +142,13 @@ module Vedeu
141
142
  # Stores the model instance by name in the repository of the model.
142
143
  #
143
144
  # @param model [void] A model instance.
145
+ # @raise [MissingRequired] When the name attribute is not defined.
144
146
  # @return [void] The model instance which was stored.
145
147
  def store(model)
146
148
  fail MissingRequired, "Cannot store model '#{model.class}' without a " \
147
149
  "name attribute." unless defined_value?(model.name)
148
150
 
149
- Vedeu.log(_log_store(model))
151
+ Vedeu.log(type: log_type(model), message: "#{model.class.name}: '#{model.name}'")
150
152
 
151
153
  storage[model.name] = model
152
154
  end
@@ -174,14 +176,12 @@ module Vedeu
174
176
  end
175
177
 
176
178
  # @return [String]
177
- def _log_store(model)
178
- message = "Storing #{model.class.name}: '#{model.name}' "
179
-
179
+ def log_type(model)
180
180
  if registered?(model.name)
181
- message + '(updating)'
181
+ :update
182
182
 
183
183
  else
184
- message + '(creating)'
184
+ :create
185
185
 
186
186
  end
187
187
  end
@@ -1,5 +1,7 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides coordinates based on the height and width provided.
4
+ #
3
5
  class BoundingArea
4
6
 
5
7
  attr_reader :height,
@@ -5,6 +5,7 @@ module Vedeu
5
5
  # Provides means to convert attributes into the correct model.
6
6
  #
7
7
  # @api private
8
+ #
8
9
  module Coercions
9
10
 
10
11
  include Vedeu::Common
@@ -48,7 +49,7 @@ module Vedeu
48
49
  # directly.
49
50
  #
50
51
  # @param receiver [Class] The class in which this module is included.
51
- # @return []
52
+ # @return [void]
52
53
  def self.included(receiver)
53
54
  receiver.extend(self)
54
55
  end
@@ -3,6 +3,7 @@ module Vedeu
3
3
  # A module for common methods used throughout Vedeu.
4
4
  #
5
5
  # @api private
6
+ #
6
7
  module Common
7
8
 
8
9
  # Returns a boolean indicating whether a variable has a useful value.
@@ -3,13 +3,30 @@ require 'vedeu/support/write'
3
3
 
4
4
  module Vedeu
5
5
 
6
+ # An abstract terminal class.
7
+ #
6
8
  class Console
7
9
 
10
+ attr_reader :height,
11
+ :origin,
12
+ :width
13
+
14
+ alias_method :tyn, :height
15
+ alias_method :yn, :height
16
+ alias_method :x, :origin
17
+ alias_method :y, :origin
18
+ alias_method :tx, :origin
19
+ alias_method :ty, :origin
20
+ alias_method :txn, :width
21
+ alias_method :xn, :width
22
+
8
23
  # @param height [Fixnum]
9
24
  # @param width [Fixnum]
25
+ # @return [Vedeu::Console]
10
26
  def initialize(height = 25, width = 80)
11
27
  @height = height || 25
12
28
  @width = width || 80
29
+ @origin = 1
13
30
  end
14
31
 
15
32
  # @param data [String|NilClass]
@@ -56,22 +73,6 @@ module Vedeu
56
73
  yield
57
74
  end
58
75
 
59
- # @return [Fixnum]
60
- def height
61
- @height
62
- end
63
- alias_method :tyn, :height
64
- alias_method :yn, :height
65
-
66
- # @return [Fixnum]
67
- def origin
68
- 1
69
- end
70
- alias_method :x, :origin
71
- alias_method :y, :origin
72
- alias_method :tx, :origin
73
- alias_method :ty, :origin
74
-
75
76
  # @param block [Proc]
76
77
  # @return [Proc]
77
78
  def raw(&block)
@@ -84,13 +85,6 @@ module Vedeu
84
85
  end
85
86
  alias_method :winsize, :size
86
87
 
87
- # @return [Fixnum]
88
- def width
89
- @width
90
- end
91
- alias_method :txn, :width
92
- alias_method :xn, :width
93
-
94
88
  end # Console
95
89
 
96
90
  end # Vedeu
@@ -1,5 +1,7 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides information about the content within an interface or view.
4
+ #
3
5
  class ContentGeometry
4
6
 
5
7
  extend Forwardable
@@ -1,6 +1,7 @@
1
1
  module Vedeu
2
2
 
3
3
  # Crudely corrects out of range values.
4
+ #
4
5
  class Coordinate
5
6
 
6
7
  attr_reader :height,
@@ -4,6 +4,7 @@ module Vedeu
4
4
  # display related functions.
5
5
  #
6
6
  # @api private
7
+ #
7
8
  module Esc
8
9
 
9
10
  extend self
@@ -13,15 +14,23 @@ module Vedeu
13
14
  # @return [Hash]
14
15
  def codes
15
16
  {
16
- black: 30,
17
- red: 31,
18
- green: 32,
19
- yellow: 33,
20
- blue: 34,
21
- magenta: 35,
22
- cyan: 36,
23
- white: 37,
24
- default: 39,
17
+ black: 30,
18
+ red: 31,
19
+ green: 32,
20
+ yellow: 33,
21
+ blue: 34,
22
+ magenta: 35,
23
+ cyan: 36,
24
+ light_grey: 37,
25
+ default: 39,
26
+ dark_grey: 90,
27
+ light_red: 91,
28
+ light_green: 92,
29
+ light_yellow: 93,
30
+ light_blue: 94,
31
+ light_magenta: 95,
32
+ light_cyan: 96,
33
+ white: 97,
25
34
  }
26
35
  end
27
36
  alias_method :foreground_codes, :codes
@@ -72,18 +81,6 @@ module Vedeu
72
81
  stream.gsub(/\e/, '\\e')
73
82
  end
74
83
 
75
- # Return the escape sequence required to position the cursor at a particular
76
- # point on the screen. When passed a block, will do the aforementioned,
77
- # call the block and then reposition to this location.
78
- #
79
- # @param y [Fixnum] The row/line position.
80
- # @param x [Fixnum] The column/character position.
81
- # @param block [Proc]
82
- # @return [String]
83
- def set_position(y = 1, x = 1, &block)
84
- Position.new(y, x).to_s(&block)
85
- end
86
-
87
84
  # Return the escape sequence string from the list of recognised sequence
88
85
  # 'commands', or an empty string if the 'command' cannot be found.
89
86
  #
@@ -95,6 +92,16 @@ module Vedeu
95
92
  sequences.fetch(value.to_sym, proc { '' }).call
96
93
  end
97
94
 
95
+ # Return the escape sequence to render a border character.
96
+ #
97
+ # @param block [Proc]
98
+ # @return [String]
99
+ def border(&block)
100
+ return '' unless block_given?
101
+
102
+ [ border_on, yield, border_off ].join
103
+ end
104
+
98
105
  private
99
106
 
100
107
  # @return [Hash]
@@ -126,7 +133,7 @@ module Vedeu
126
133
 
127
134
  # @return [String]
128
135
  def bg_reset
129
- "\e[48;2;49m"
136
+ "\e[49m"
130
137
  end
131
138
 
132
139
  # @return [String]
@@ -149,21 +156,39 @@ module Vedeu
149
156
  "\e[22m"
150
157
  end
151
158
 
159
+ # Returns the escape sequence to start a border.
160
+ #
161
+ # @return [String]
162
+ def border_on
163
+ "\e(0"
164
+ end
165
+
166
+ # Returns the escape sequence to end a border.
167
+ #
168
+ # @return [String]
169
+ def border_off
170
+ "\e(B"
171
+ end
172
+
152
173
  # @return [String]
153
174
  def clear
154
- [ colour_reset,
155
- "\e[2J" ].join
175
+ [
176
+ colour_reset,
177
+ "\e[2J"
178
+ ].join
156
179
  end
157
180
 
158
181
  # @return [String]
159
182
  def clear_line
160
- [ colour_reset,
161
- "\e[2K" ].join
183
+ [
184
+ colour_reset,
185
+ "\e[2K"
186
+ ].join
162
187
  end
163
188
 
164
189
  # @return [String]
165
190
  def clear_last_line
166
- [set_position((Terminal.height - 1), 1), clear_line].join
191
+ Vedeu::Position.new((Terminal.height - 1), 1).to_s { clear_line }
167
192
  end
168
193
 
169
194
  # @return [String]
@@ -178,7 +203,7 @@ module Vedeu
178
203
 
179
204
  # @return [String]
180
205
  def fg_reset
181
- "\e[38;2;39m"
206
+ "\e[39m"
182
207
  end
183
208
 
184
209
  # @return [String]
@@ -213,7 +238,11 @@ module Vedeu
213
238
 
214
239
  # @return [String]
215
240
  def screen_exit
216
- [show_cursor, colour_reset, reset].join
241
+ [
242
+ show_cursor,
243
+ colour_reset,
244
+ reset
245
+ ].join
217
246
  end
218
247
 
219
248
  # @return [String]
@@ -25,6 +25,7 @@ module Vedeu
25
25
  # the remainder.
26
26
  #
27
27
  # @api private
28
+ #
28
29
  class Grid
29
30
 
30
31
  # @param value [Fixnum]
@@ -1,11 +1,19 @@
1
1
  module Vedeu
2
2
 
3
+ # Forces the value within defined limits.
4
+ #
3
5
  class Limit
4
6
 
7
+ # @see #new, #apply
5
8
  def self.apply(v, vn, max, min = 1)
6
9
  new(v, vn, max, min).apply
7
10
  end
8
11
 
12
+ # @param v [Fixnum]
13
+ # @param vn [Fixnum]
14
+ # @param max [Fixnum]
15
+ # @param min [Fixnum]
16
+ # @return [Vedeu::Limit]
9
17
  def initialize(v, vn, max, min = 1)
10
18
  @v = v
11
19
  @vn = vn
@@ -13,6 +21,7 @@ module Vedeu
13
21
  @min = min || 1
14
22
  end
15
23
 
24
+ # @return [Fixnum]
16
25
  def apply
17
26
  if (v + vn) > max
18
27
  applied = vn - ((v + vn) - max)
@@ -5,25 +5,26 @@ module Vedeu
5
5
  # Provides the ability to log anything to the Vedeu log file.
6
6
  #
7
7
  # @api private
8
+ #
8
9
  class Log
9
10
 
10
11
  class << self
11
12
 
12
13
  # Write a message to the Vedeu log file.
13
14
  #
14
- # @param message [String] The message you wish to emit to the log
15
- # file, useful for debugging.
16
- # @param force [Boolean] When evaluates to true will attempt to
17
- # write to the log file regardless of the Configuration setting.
15
+ # @param message [String] The message you wish to emit to the log file,
16
+ # useful for debugging.
17
+ # @param force [Boolean] When evaluates to true will attempt to write to
18
+ # the log file regardless of the Configuration setting.
19
+ # @param type [Symbol] Colour code messages in the log file depending
20
+ # on their source.
18
21
  #
19
22
  # @example
20
- # Vedeu.log('A useful debugging message: Error!')
23
+ # Vedeu.log(message: 'A useful debugging message: Error!')
21
24
  #
22
25
  # @return [TrueClass]
23
- def log(message, force = false)
24
- colour = [:red, :green, :yellow, :blue, :magenta, :cyan, :white].sample
25
-
26
- logger.debug(Esc.send(colour) { message }) if enabled? || force
26
+ def log(message:, force: false, type: :info)
27
+ logger.debug([message_type(type), message]) if enabled? || force
27
28
  end
28
29
 
29
30
  # @return [TrueClass]
@@ -52,6 +53,27 @@ module Vedeu
52
53
  Vedeu::Configuration.log
53
54
  end
54
55
 
56
+ # @return [String]
57
+ def message_type(type)
58
+ Esc.send(message_types.fetch(type, :default)) { "[#{type}]".ljust(9) }
59
+ end
60
+
61
+ # @return [Hash]
62
+ def message_types
63
+ {
64
+ create: :green,
65
+ debug: :red,
66
+ drb: :blue,
67
+ event: :magenta,
68
+ info: :default,
69
+ input: :yellow,
70
+ output: :green,
71
+ store: :cyan,
72
+ test: :white,
73
+ update: :cyan,
74
+ }
75
+ end
76
+
55
77
  # Returns a formatted (red, underlined) UTC timestamp,
56
78
  # eg. 2014-10-24T12:34:56Z
57
79
  #
@@ -1,5 +1,7 @@
1
1
  module Vedeu
2
2
 
3
+ # A composition class.
4
+ #
3
5
  class Node
4
6
 
5
7
  attr_accessor :name,
@@ -7,11 +9,13 @@ module Vedeu
7
9
 
8
10
  attr_reader :children
9
11
 
12
+ # @return [void]
10
13
  def initialize(name)
11
14
  @name = name
12
15
  @children = []
13
16
  end
14
17
 
18
+ # @return [void]
15
19
  def add_child(node)
16
20
  children << node
17
21
 
@@ -19,14 +23,17 @@ module Vedeu
19
23
  end
20
24
  alias :<< :add_child
21
25
 
26
+ # @return [void]
22
27
  def remove_child(node)
23
28
  children.delete(node)
24
29
  end
25
30
 
31
+ # @return [void]
26
32
  def [](index)
27
33
  children[index]
28
34
  end
29
35
 
36
+ # @return [void]
30
37
  def []=(index, node)
31
38
  replaced_child = @children[index]
32
39
  children[index] = node
@@ -34,28 +41,11 @@ module Vedeu
34
41
  node.parent = self
35
42
  end
36
43
 
44
+ # @return [void]
37
45
  def leaf?
38
46
  children.empty?
39
47
  end
40
48
 
41
49
  end # Node
42
50
 
43
- class Task < Node
44
-
45
- def initialize(name, time_required = nil)
46
- super(name)
47
- @time_required = time_required
48
- end
49
- def time_required
50
- if leaf?
51
- @time_required
52
- else
53
- time = 0.0
54
- children.each { |child_task| time += child_task.time_required }
55
- time
56
- end
57
- end
58
-
59
- end # Task
60
-
61
51
  end # Vedeu