vedeu 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +6 -0
- data/bin/vedeu_drb_client +8 -3
- data/bin/vedeu_drb_server +113 -0
- data/bin/vedeu_test +1 -1
- data/docs/events.md +0 -127
- data/examples/borders_app.rb +17 -7
- data/examples/configuration_app.rb +1 -1
- data/examples/cursor_app.rb +4 -2
- data/examples/drb_app.rb +113 -0
- data/examples/focus_app.rb +1 -1
- data/examples/geometry_app.rb +1 -1
- data/examples/hello_world.rb +1 -1
- data/examples/lines_app.rb +1 -1
- data/features/start_stop.feature +1 -1
- data/inch.yml +5 -0
- data/lib/vedeu/all.rb +2 -0
- data/lib/vedeu/api.rb +1 -0
- data/lib/vedeu/application.rb +17 -36
- data/lib/vedeu/bindings.rb +134 -27
- data/lib/vedeu/buffers/display_buffer.rb +1 -4
- data/lib/vedeu/configuration/api.rb +15 -14
- data/lib/vedeu/configuration/cli.rb +17 -16
- data/lib/vedeu/configuration/configuration.rb +3 -1
- data/lib/vedeu/cursor/cursor.rb +6 -8
- data/lib/vedeu/cursor/move_cursor.rb +1 -0
- data/lib/vedeu/cursor/toggle_cursor.rb +1 -0
- data/lib/vedeu/debug.rb +23 -0
- data/lib/vedeu/distributed/all.rb +1 -1
- data/lib/vedeu/distributed/client.rb +55 -13
- data/lib/vedeu/distributed/server.rb +207 -0
- data/lib/vedeu/distributed/subprocess.rb +22 -21
- data/lib/vedeu/distributed/templates/default_application.vedeu +3 -1
- data/lib/vedeu/distributed/test_application.rb +2 -1
- data/lib/vedeu/distributed/uri.rb +1 -0
- data/lib/vedeu/dsl/all.rb +4 -2
- data/lib/vedeu/dsl/components/border.rb +11 -10
- data/lib/vedeu/dsl/components/geometry.rb +1 -0
- data/lib/vedeu/dsl/components/keymap.rb +1 -0
- data/lib/vedeu/dsl/components/menu.rb +1 -0
- data/lib/vedeu/dsl/interface.rb +1 -0
- data/lib/vedeu/dsl/line.rb +3 -1
- data/lib/vedeu/dsl/shared/colour.rb +1 -0
- data/lib/vedeu/dsl/shared/style.rb +1 -0
- data/lib/vedeu/dsl/shared/text.rb +2 -0
- data/lib/vedeu/dsl/shared/use.rb +3 -0
- data/lib/vedeu/dsl/stream.rb +3 -1
- data/lib/vedeu/dsl/view.rb +1 -0
- data/lib/vedeu/events/event.rb +9 -6
- data/lib/vedeu/events/trigger.rb +18 -7
- data/lib/vedeu/exceptions.rb +4 -1
- data/lib/vedeu/input/input.rb +1 -0
- data/lib/vedeu/input/key.rb +0 -1
- data/lib/vedeu/input/keymap.rb +5 -3
- data/lib/vedeu/input/keys.rb +1 -0
- data/lib/vedeu/input/mapper.rb +1 -0
- data/lib/vedeu/launcher.rb +35 -12
- data/lib/vedeu/main_loop.rb +53 -0
- data/lib/vedeu/models/collection.rb +11 -3
- data/lib/vedeu/models/focus.rb +3 -3
- data/lib/vedeu/models/geometry.rb +8 -16
- data/lib/vedeu/models/group.rb +1 -0
- data/lib/vedeu/models/menu.rb +2 -1
- data/lib/vedeu/models/model.rb +7 -1
- data/lib/vedeu/models/view/char.rb +52 -44
- data/lib/vedeu/models/view/chars.rb +1 -0
- data/lib/vedeu/models/view/composition.rb +2 -1
- data/lib/vedeu/models/view/interface.rb +5 -3
- data/lib/vedeu/models/view/interfaces.rb +1 -0
- data/lib/vedeu/models/view/line.rb +2 -1
- data/lib/vedeu/models/view/stream.rb +2 -1
- data/lib/vedeu/models/view/streams.rb +1 -0
- data/lib/vedeu/output/all.rb +4 -0
- data/lib/vedeu/output/border.rb +75 -206
- data/lib/vedeu/output/compositor.rb +1 -0
- data/lib/vedeu/output/html_char.rb +119 -0
- data/lib/vedeu/output/html_renderer.rb +89 -0
- data/lib/vedeu/output/output.rb +48 -44
- data/lib/vedeu/output/position_index.rb +12 -1
- data/lib/vedeu/output/renderer.rb +28 -0
- data/lib/vedeu/output/viewport.rb +14 -14
- data/lib/vedeu/output/virtual_buffer.rb +56 -0
- data/lib/vedeu/output/virtual_terminal.rb +42 -34
- data/lib/vedeu/output/wordwrap.rb +3 -0
- data/lib/vedeu/output/writer.rb +13 -1
- data/lib/vedeu/presentation/background.rb +1 -0
- data/lib/vedeu/presentation/colour.rb +8 -7
- data/lib/vedeu/presentation/foreground.rb +1 -0
- data/lib/vedeu/presentation/presentation.rb +43 -7
- data/lib/vedeu/presentation/translator.rb +12 -0
- data/lib/vedeu/repositories/repository.rb +8 -8
- data/lib/vedeu/support/bounding_area.rb +2 -0
- data/lib/vedeu/support/coercions.rb +2 -1
- data/lib/vedeu/support/common.rb +1 -0
- data/lib/vedeu/support/console.rb +17 -23
- data/lib/vedeu/support/content_geometry.rb +2 -0
- data/lib/vedeu/support/coordinate.rb +1 -0
- data/lib/vedeu/support/esc.rb +58 -29
- data/lib/vedeu/support/grid.rb +1 -0
- data/lib/vedeu/support/limit.rb +9 -0
- data/lib/vedeu/support/log.rb +31 -9
- data/lib/vedeu/support/node.rb +8 -18
- data/lib/vedeu/support/position.rb +13 -34
- data/lib/vedeu/support/position_validator.rb +3 -0
- data/lib/vedeu/support/read.rb +1 -0
- data/lib/vedeu/support/refresh.rb +3 -2
- data/lib/vedeu/support/terminal.rb +11 -5
- data/lib/vedeu/support/trace.rb +16 -1
- data/lib/vedeu/support/visible.rb +2 -0
- data/lib/vedeu/support/write.rb +1 -0
- data/lib/vedeu/traps.rb +1 -0
- data/lib/vedeu.rb +2 -0
- data/test/integration/distributed_test.rb +10 -8
- data/test/lib/vedeu/api_test.rb +3 -7
- data/test/lib/vedeu/application_test.rb +2 -5
- data/test/lib/vedeu/configuration/api_test.rb +12 -0
- data/test/lib/vedeu/cursor/cursor_test.rb +2 -0
- data/test/lib/vedeu/distributed/client_test.rb +17 -7
- data/test/lib/vedeu/distributed/server_test.rb +56 -0
- data/test/lib/vedeu/distributed/test_application_test.rb +7 -3
- data/test/lib/vedeu/dsl/components/border_test.rb +10 -2
- data/test/lib/vedeu/dsl/interface_test.rb +6 -0
- data/test/lib/vedeu/dsl/line_test.rb +19 -0
- data/test/lib/vedeu/dsl/shared/colour_test.rb +4 -26
- data/test/lib/vedeu/dsl/shared/text_test.rb +8 -1
- data/test/lib/vedeu/dsl/stream_test.rb +13 -1
- data/test/lib/vedeu/input/input_test.rb +1 -1
- data/test/lib/vedeu/input/key_test.rb +3 -16
- data/test/lib/vedeu/launcher_test.rb +11 -1
- data/test/lib/vedeu/main_loop_test.rb +41 -0
- data/test/lib/vedeu/models/geometry_test.rb +15 -34
- data/test/lib/vedeu/models/view/char_test.rb +44 -45
- data/test/lib/vedeu/models/view/interface_test.rb +6 -0
- data/test/lib/vedeu/models/view/line_test.rb +1 -1
- data/test/lib/vedeu/models/view/stream_test.rb +1 -1
- data/test/lib/vedeu/output/border_test.rb +6 -5
- data/test/lib/vedeu/output/compositor_test.rb +2 -20
- data/test/lib/vedeu/output/html_char_test.rb +85 -0
- data/test/lib/vedeu/output/html_renderer_test.rb +37 -0
- data/test/lib/vedeu/output/position_index_test.rb +2 -10
- data/test/lib/vedeu/output/renderer_test.rb +24 -0
- data/test/lib/vedeu/output/virtual_buffer_test.rb +53 -0
- data/test/lib/vedeu/output/virtual_terminal_test.rb +32 -2
- data/test/lib/vedeu/presentation/background_test.rb +41 -1
- data/test/lib/vedeu/presentation/colour_test.rb +10 -6
- data/test/lib/vedeu/presentation/foreground_test.rb +46 -6
- data/test/lib/vedeu/presentation/presentation_test.rb +44 -1
- data/test/lib/vedeu/presentation/translator_test.rb +34 -0
- data/test/lib/vedeu/repositories/repository_test.rb +1 -1
- data/test/lib/vedeu/support/bounding_area_test.rb +4 -12
- data/test/lib/vedeu/support/console_test.rb +9 -50
- data/test/lib/vedeu/support/esc_test.rb +7 -7
- data/test/lib/vedeu/support/position_test.rb +42 -0
- data/test/lib/vedeu/support/terminal_test.rb +5 -20
- data/test/lib/vedeu/support/write_test.rb +42 -18
- data/test/support/helpers/all.rb +0 -1
- data/test/support/helpers/repository_test_module.rb +1 -0
- data/test/test_helper.rb +5 -2
- data/vedeu.gemspec +7 -5
- metadata +60 -14
- data/lib/vedeu/distributed/application.rb +0 -91
- data/test/lib/vedeu/distributed/application_test.rb +0 -24
- 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.
|
28
|
-
@foreground = Foreground.
|
28
|
+
@background = Background.coerce(@attributes[:background])
|
29
|
+
@foreground = Foreground.coerce(@attributes[:foreground])
|
29
30
|
end
|
30
31
|
|
31
|
-
# Converts the value into a
|
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.
|
37
|
+
@foreground = Foreground.coerce(value)
|
37
38
|
end
|
38
39
|
|
39
|
-
# Converts the value into a
|
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.
|
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
|
@@ -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
|
-
|
71
|
+
parent.colour if parent
|
72
|
+
end
|
43
73
|
|
44
|
-
|
74
|
+
# @return [String|NilClass]
|
75
|
+
def parent_style
|
76
|
+
parent.style if parent
|
45
77
|
end
|
46
78
|
|
47
79
|
# @return [String]
|
48
|
-
def
|
49
|
-
|
80
|
+
def render_border
|
81
|
+
if self.respond_to?(:border) && !border.nil?
|
82
|
+
Esc.border { yield }
|
50
83
|
|
51
|
-
|
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(
|
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
|
178
|
-
message = "Storing #{model.class.name}: '#{model.name}' "
|
179
|
-
|
179
|
+
def log_type(model)
|
180
180
|
if registered?(model.name)
|
181
|
-
|
181
|
+
:update
|
182
182
|
|
183
183
|
else
|
184
|
-
|
184
|
+
:create
|
185
185
|
|
186
186
|
end
|
187
187
|
end
|
@@ -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
|
data/lib/vedeu/support/common.rb
CHANGED
@@ -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
|
data/lib/vedeu/support/esc.rb
CHANGED
@@ -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:
|
17
|
-
red:
|
18
|
-
green:
|
19
|
-
yellow:
|
20
|
-
blue:
|
21
|
-
magenta:
|
22
|
-
cyan:
|
23
|
-
|
24
|
-
default:
|
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[
|
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
|
-
[
|
155
|
-
|
175
|
+
[
|
176
|
+
colour_reset,
|
177
|
+
"\e[2J"
|
178
|
+
].join
|
156
179
|
end
|
157
180
|
|
158
181
|
# @return [String]
|
159
182
|
def clear_line
|
160
|
-
[
|
161
|
-
|
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
|
-
|
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[
|
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
|
-
[
|
241
|
+
[
|
242
|
+
show_cursor,
|
243
|
+
colour_reset,
|
244
|
+
reset
|
245
|
+
].join
|
217
246
|
end
|
218
247
|
|
219
248
|
# @return [String]
|
data/lib/vedeu/support/grid.rb
CHANGED
data/lib/vedeu/support/limit.rb
CHANGED
@@ -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)
|
data/lib/vedeu/support/log.rb
CHANGED
@@ -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
|
-
#
|
16
|
-
# @param force [Boolean] When evaluates to true will attempt to
|
17
|
-
#
|
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
|
24
|
-
|
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
|
#
|
data/lib/vedeu/support/node.rb
CHANGED
@@ -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
|