vedeu 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vedeu/all.rb +2 -13
- data/lib/vedeu/api.rb +9 -9
- data/lib/vedeu/application/application_view.rb +3 -5
- data/lib/vedeu/bindings/bindings.rb +5 -1
- data/lib/vedeu/bindings/focus.rb +0 -5
- data/lib/vedeu/bindings/refresh.rb +0 -5
- data/lib/vedeu/bindings/system.rb +1 -6
- data/lib/vedeu/colours/all.rb +17 -0
- data/lib/vedeu/colours/background.rb +32 -28
- data/lib/vedeu/colours/backgrounds.rb +13 -9
- data/lib/vedeu/colours/colour.rb +106 -102
- data/lib/vedeu/colours/foreground.rb +32 -28
- data/lib/vedeu/colours/foregrounds.rb +13 -9
- data/lib/vedeu/colours/repository.rb +70 -0
- data/lib/vedeu/colours/translator.rb +267 -0
- data/lib/vedeu/configuration/api.rb +10 -7
- data/lib/vedeu/configuration/configuration.rb +2 -1
- data/lib/vedeu/dsl/border.rb +15 -2
- data/lib/vedeu/dsl/composition.rb +6 -4
- data/lib/vedeu/dsl/geometry.rb +14 -7
- data/lib/vedeu/dsl/group.rb +2 -2
- data/lib/vedeu/dsl/interface.rb +5 -3
- data/lib/vedeu/dsl/keymap.rb +9 -7
- data/lib/vedeu/dsl/line.rb +7 -4
- data/lib/vedeu/dsl/menu.rb +3 -0
- data/lib/vedeu/dsl/presentation.rb +20 -10
- data/lib/vedeu/dsl/shared.rb +4 -4
- data/lib/vedeu/dsl/stream.rb +2 -2
- data/lib/vedeu/dsl/text.rb +11 -5
- data/lib/vedeu/dsl/use.rb +2 -2
- data/lib/vedeu/dsl/view.rb +8 -6
- data/lib/vedeu/events/aliases.rb +91 -0
- data/lib/vedeu/events/all.rb +15 -0
- data/lib/vedeu/events/collection.rb +13 -0
- data/lib/vedeu/events/event.rb +244 -239
- data/lib/vedeu/events/repository.rb +30 -0
- data/lib/vedeu/events/trigger.rb +68 -64
- data/lib/vedeu/exceptions.rb +65 -54
- data/lib/vedeu/geometry/coordinate.rb +3 -1
- data/lib/vedeu/geometry/grid.rb +2 -4
- data/lib/vedeu/input/editor/all.rb +2 -1
- data/lib/vedeu/input/editor/{virtual_cursor.rb → cursor.rb} +10 -10
- data/lib/vedeu/input/editor/document.rb +7 -7
- data/lib/vedeu/input/editor/insert.rb +70 -0
- data/lib/vedeu/input/editor/line.rb +4 -16
- data/lib/vedeu/input/editor/lines.rb +2 -16
- data/lib/vedeu/input/input_translator.rb +2 -2
- data/lib/vedeu/input/key.rb +2 -2
- data/lib/vedeu/internal_api.rb +6 -6
- data/lib/vedeu/log/lockless_log_device.rb +0 -74
- data/lib/vedeu/models/focus.rb +3 -3
- data/lib/vedeu/models/interface.rb +3 -3
- data/lib/vedeu/models/menu.rb +2 -2
- data/lib/vedeu/models/views/char.rb +1 -1
- data/lib/vedeu/models/views/composition.rb +1 -1
- data/lib/vedeu/models/views/line.rb +1 -1
- data/lib/vedeu/models/views/stream.rb +1 -1
- data/lib/vedeu/models/views/view.rb +6 -7
- data/lib/vedeu/output/presentation/colour.rb +23 -21
- data/lib/vedeu/output/renderers/renderer_options.rb +2 -4
- data/lib/vedeu/output/text.rb +1 -1
- data/lib/vedeu/output/wordwrap.rb +18 -7
- data/lib/vedeu/plugins/plugin.rb +2 -2
- data/lib/vedeu/refresh/refresh_buffer.rb +3 -3
- data/lib/vedeu/refresh/refresh_group.rb +3 -3
- data/lib/vedeu/repositories/repository.rb +7 -6
- data/lib/vedeu/runtime/application.rb +1 -1
- data/lib/vedeu/runtime/main_loop.rb +3 -3
- data/lib/vedeu/runtime/router.rb +14 -11
- data/lib/vedeu/templating/helpers.rb +5 -5
- data/lib/vedeu/templating/template.rb +4 -4
- data/lib/vedeu/templating/view_template.rb +1 -1
- data/lib/vedeu/terminal/terminal.rb +2 -2
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/application/application_view_test.rb +1 -1
- data/test/lib/vedeu/colours/background_test.rb +93 -89
- data/test/lib/vedeu/colours/backgrounds_test.rb +11 -7
- data/test/lib/vedeu/colours/colour_test.rb +155 -151
- data/test/lib/vedeu/colours/foreground_test.rb +93 -89
- data/test/lib/vedeu/colours/foregrounds_test.rb +11 -7
- data/test/lib/vedeu/colours/repository_test.rb +97 -0
- data/test/lib/vedeu/colours/translator_test.rb +173 -0
- data/test/lib/vedeu/configuration/api_test.rb +4 -4
- data/test/lib/vedeu/dsl/border_test.rb +12 -0
- data/test/lib/vedeu/dsl/composition_test.rb +3 -3
- data/test/lib/vedeu/dsl/geometry_test.rb +11 -0
- data/test/lib/vedeu/dsl/group_test.rb +2 -2
- data/test/lib/vedeu/dsl/interface_test.rb +4 -4
- data/test/lib/vedeu/dsl/keymap_test.rb +8 -4
- data/test/lib/vedeu/dsl/line_test.rb +6 -3
- data/test/lib/vedeu/dsl/menu_test.rb +6 -0
- data/test/lib/vedeu/dsl/presentation_test.rb +16 -3
- data/test/lib/vedeu/dsl/stream_test.rb +1 -1
- data/test/lib/vedeu/dsl/text_test.rb +7 -0
- data/test/lib/vedeu/dsl/view_test.rb +3 -3
- data/test/lib/vedeu/events/aliases_test.rb +144 -0
- data/test/lib/vedeu/events/collection_test.rb +22 -0
- data/test/lib/vedeu/events/event_test.rb +84 -80
- data/test/lib/vedeu/events/repository_test.rb +28 -0
- data/test/lib/vedeu/events/trigger_test.rb +41 -37
- data/test/lib/vedeu/geometry/grid_test.rb +4 -4
- data/test/lib/vedeu/input/editor/{virtual_cursor_test.rb → cursor_test.rb} +3 -3
- data/test/lib/vedeu/input/editor/insert_test.rb +36 -0
- data/test/lib/vedeu/input/key_test.rb +1 -1
- data/test/lib/vedeu/models/cell_test.rb +1 -1
- data/test/lib/vedeu/models/focus_test.rb +4 -2
- data/test/lib/vedeu/models/menu_test.rb +1 -1
- data/test/lib/vedeu/models/views/char_test.rb +8 -4
- data/test/lib/vedeu/models/views/line_test.rb +4 -4
- data/test/lib/vedeu/models/views/stream_test.rb +3 -3
- data/test/lib/vedeu/models/views/view_test.rb +1 -1
- data/test/lib/vedeu/output/html_char_test.rb +4 -2
- data/test/lib/vedeu/output/presentation/colour_test.rb +5 -5
- data/test/lib/vedeu/output/presentation_test.rb +4 -4
- data/test/lib/vedeu/output/renderers/json_test.rb +4 -2
- data/test/lib/vedeu/plugins/plugin_test.rb +1 -1
- data/test/lib/vedeu/refresh/refresh_buffer_test.rb +1 -1
- data/test/lib/vedeu/refresh/refresh_group_test.rb +1 -1
- data/test/lib/vedeu/repositories/repository_test.rb +2 -2
- data/test/lib/vedeu/runtime/router_test.rb +6 -6
- data/test/lib/vedeu/templating/decoder_test.rb +2 -3
- data/test/lib/vedeu/templating/encoder_test.rb +2 -3
- data/test/lib/vedeu/templating/helpers_test.rb +6 -6
- data/test/lib/vedeu/templating/template_test.rb +2 -2
- data/test/lib/vedeu/templating/view_template_test.rb +13 -7
- data/test/lib/vedeu/terminal/terminal_test.rb +3 -3
- metadata +24 -19
- data/lib/vedeu/colours/colour_translator.rb +0 -260
- data/lib/vedeu/colours/colours.rb +0 -66
- data/lib/vedeu/events/event_aliases.rb +0 -87
- data/lib/vedeu/events/event_collection.rb +0 -9
- data/lib/vedeu/events/events.rb +0 -26
- data/test/lib/vedeu/colours/colour_translator_test.rb +0 -169
- data/test/lib/vedeu/colours/colours_test.rb +0 -93
- data/test/lib/vedeu/events/event_aliases_test.rb +0 -140
- data/test/lib/vedeu/events/event_collection_test.rb +0 -18
- data/test/lib/vedeu/events/events_test.rb +0 -24
@@ -2,10 +2,9 @@ module Vedeu
|
|
2
2
|
|
3
3
|
# Provides shared functionality to Vedeu::Renderer classes.
|
4
4
|
#
|
5
|
+
# :nocov:
|
5
6
|
module RendererOptions
|
6
7
|
|
7
|
-
# :nocov:
|
8
|
-
|
9
8
|
private
|
10
9
|
|
11
10
|
# Combines the options provided at instantiation with the default values.
|
@@ -22,8 +21,7 @@ module Vedeu
|
|
22
21
|
{}
|
23
22
|
end
|
24
23
|
|
25
|
-
# :nocov:
|
26
|
-
|
27
24
|
end # RendererOptions
|
25
|
+
# :nocov:
|
28
26
|
|
29
27
|
end # Vedeu
|
data/lib/vedeu/output/text.rb
CHANGED
@@ -4,7 +4,7 @@ module Vedeu
|
|
4
4
|
#
|
5
5
|
class Wordwrap
|
6
6
|
|
7
|
-
# @see
|
7
|
+
# @see Vedeu::Wordwrap#initialize
|
8
8
|
def self.for(text, options = {})
|
9
9
|
new(text, options).content
|
10
10
|
end
|
@@ -13,12 +13,9 @@ module Vedeu
|
|
13
13
|
#
|
14
14
|
# @param text [String]
|
15
15
|
# @param options [Hash]
|
16
|
-
# @option options ellipsis [String]
|
17
|
-
# @option options mode [Symbol]
|
18
|
-
#
|
19
|
-
# :prune = Discards the remainder of the content line after width.
|
20
|
-
# :wrap = Forces the content on to a new line after width.
|
21
|
-
# @option options width [Fixnum] The width to prune or wrap to.
|
16
|
+
# @option options ellipsis [String] See {#ellipsis}.
|
17
|
+
# @option options mode [Symbol] See {#mode}.
|
18
|
+
# @option options width [Fixnum] See {#width}.
|
22
19
|
# @return [Vedeu::Wordwrap]
|
23
20
|
def initialize(text, options = {})
|
24
21
|
@text = text
|
@@ -106,6 +103,8 @@ module Vedeu
|
|
106
103
|
Vedeu::Views::Lines.new(line_objects)
|
107
104
|
end
|
108
105
|
|
106
|
+
# Returns the text as an array of lines, split on '\n'.
|
107
|
+
#
|
109
108
|
# @return [Array<String>]
|
110
109
|
def split_lines
|
111
110
|
text.split(/\n/)
|
@@ -123,27 +122,39 @@ module Vedeu
|
|
123
122
|
end
|
124
123
|
end
|
125
124
|
|
125
|
+
# Returns the string pruned.
|
126
|
+
#
|
126
127
|
# @param string [String]
|
127
128
|
# @return [String]
|
128
129
|
def prune_string(string)
|
129
130
|
string.chomp.slice(0..pruned_width)
|
130
131
|
end
|
131
132
|
|
133
|
+
# Returns the width of the string minus the ellipsis.
|
134
|
+
#
|
132
135
|
# @return [Fixnum]
|
133
136
|
def pruned_width
|
134
137
|
width - ellipsis.size
|
135
138
|
end
|
136
139
|
|
140
|
+
# For when using mode `:prune`, by default, provides '...'.
|
141
|
+
#
|
137
142
|
# @return [String]
|
138
143
|
def ellipsis
|
139
144
|
options.fetch(:ellipsis)
|
140
145
|
end
|
141
146
|
|
147
|
+
# Returns the word wrapping mode. One of :default, :prune or :wrap;
|
148
|
+
# :default = Renders the content as is.
|
149
|
+
# :prune = Discards the remainder of the content line after width.
|
150
|
+
# :wrap = Forces the content on to a new line after width.
|
142
151
|
# @return [Symbol]
|
143
152
|
def mode
|
144
153
|
options.fetch(:mode)
|
145
154
|
end
|
146
155
|
|
156
|
+
# Returns the width to prune or wrap to.
|
157
|
+
#
|
147
158
|
# @return [Fixnum]
|
148
159
|
def width
|
149
160
|
options.fetch(:width)
|
data/lib/vedeu/plugins/plugin.rb
CHANGED
@@ -40,10 +40,10 @@ module Vedeu
|
|
40
40
|
begin
|
41
41
|
require gem_name unless enabled?
|
42
42
|
rescue LoadError => error
|
43
|
-
raise Vedeu::
|
43
|
+
raise Vedeu::Error::Fatal,
|
44
44
|
"Unable to load plugin #{gem_name} due to #{error}."
|
45
45
|
rescue => error
|
46
|
-
raise Vedeu::
|
46
|
+
raise Vedeu::Error::Fatal,
|
47
47
|
"require '#{gem_name}' failed with #{error}."
|
48
48
|
end
|
49
49
|
|
@@ -11,7 +11,7 @@ module Vedeu
|
|
11
11
|
|
12
12
|
# @param name [String] The name of the interface to be refreshed using the
|
13
13
|
# named buffer.
|
14
|
-
# @return [Array|Vedeu::ModelNotFound]
|
14
|
+
# @return [Array|Vedeu::Error::ModelNotFound]
|
15
15
|
def self.by_name(name)
|
16
16
|
new(name).by_name
|
17
17
|
end
|
@@ -39,12 +39,12 @@ module Vedeu
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
# @raise [Vedeu::MissingRequired] When the name is empty or nil.
|
42
|
+
# @raise [Vedeu::Error::MissingRequired] When the name is empty or nil.
|
43
43
|
# @return [String]
|
44
44
|
def buffer_name
|
45
45
|
return name if present?(name)
|
46
46
|
|
47
|
-
fail Vedeu::MissingRequired,
|
47
|
+
fail Vedeu::Error::MissingRequired,
|
48
48
|
'Cannot refresh interface with an empty interface name.'
|
49
49
|
end
|
50
50
|
|
@@ -14,7 +14,7 @@ module Vedeu
|
|
14
14
|
include Vedeu::Common
|
15
15
|
|
16
16
|
# @param name [String] The name of the group to be refreshed.
|
17
|
-
# @return [Array|Vedeu::ModelNotFound] A collection of the names of
|
17
|
+
# @return [Array|Vedeu::Error::ModelNotFound] A collection of the names of
|
18
18
|
# interfaces refreshed, or an exception when the group was not found.
|
19
19
|
def self.by_name(name)
|
20
20
|
new(name).by_name
|
@@ -45,12 +45,12 @@ module Vedeu
|
|
45
45
|
|
46
46
|
private
|
47
47
|
|
48
|
-
# @raise [Vedeu::MissingRequired] When the name is empty or nil.
|
48
|
+
# @raise [Vedeu::Error::MissingRequired] When the name is empty or nil.
|
49
49
|
# @return [String]
|
50
50
|
def group_name
|
51
51
|
return name if present?(name)
|
52
52
|
|
53
|
-
fail Vedeu::MissingRequired,
|
53
|
+
fail Vedeu::Error::MissingRequired,
|
54
54
|
'Cannot refresh group with an empty group name.'
|
55
55
|
end
|
56
56
|
|
@@ -89,11 +89,11 @@ module Vedeu
|
|
89
89
|
# cannot be found.
|
90
90
|
#
|
91
91
|
# @param name [String]
|
92
|
-
# @raise [Vedeu::ModelNotFound] When the model cannot be found with
|
93
|
-
# name.
|
92
|
+
# @raise [Vedeu::Error::ModelNotFound] When the model cannot be found with
|
93
|
+
# this name.
|
94
94
|
# @return [Hash<String => Object>]
|
95
95
|
def find!(name)
|
96
|
-
find(name) || fail(Vedeu::ModelNotFound,
|
96
|
+
find(name) || fail(Vedeu::Error::ModelNotFound,
|
97
97
|
"Cannot find model by name: '#{name}'")
|
98
98
|
end
|
99
99
|
|
@@ -148,12 +148,13 @@ module Vedeu
|
|
148
148
|
# Stores the model instance by name in the repository of the model.
|
149
149
|
#
|
150
150
|
# @param model [void] A model instance.
|
151
|
-
# @raise [Vedeu::MissingRequired] When the name attribute is not
|
151
|
+
# @raise [Vedeu::Error::MissingRequired] When the name attribute is not
|
152
|
+
# defined.
|
152
153
|
# @return [void] The model instance which was stored.
|
153
154
|
def store(model)
|
154
155
|
unless present?(model.name)
|
155
|
-
fail Vedeu::MissingRequired,
|
156
|
-
|
156
|
+
fail Vedeu::Error::MissingRequired,
|
157
|
+
"Cannot store model '#{model.class}' without a name attribute."
|
157
158
|
end
|
158
159
|
|
159
160
|
log_store(model)
|
@@ -24,7 +24,7 @@ module Vedeu
|
|
24
24
|
|
25
25
|
safe_exit_point!
|
26
26
|
end
|
27
|
-
rescue Vedeu::
|
27
|
+
rescue Vedeu::Error::Interrupt
|
28
28
|
Vedeu.log(type: :info,
|
29
29
|
message: 'Vedeu execution interrupted, exiting.')
|
30
30
|
end
|
@@ -40,11 +40,11 @@ module Vedeu
|
|
40
40
|
# :nocov:
|
41
41
|
# Check the application has started and we wish to continue running.
|
42
42
|
#
|
43
|
-
# @raise [Vedeu::
|
43
|
+
# @raise [Vedeu::Error::Interrupt] When we wish to terminate the running
|
44
44
|
# application.
|
45
45
|
# @return [void]
|
46
46
|
def safe_exit_point!
|
47
|
-
fail Vedeu::
|
47
|
+
fail Vedeu::Error::Interrupt if @started && !@loop
|
48
48
|
end
|
49
49
|
# :nocov:
|
50
50
|
|
data/lib/vedeu/runtime/router.rb
CHANGED
@@ -13,11 +13,12 @@ module Vedeu
|
|
13
13
|
#
|
14
14
|
# @param controller [Symbol]
|
15
15
|
# @param klass [String]
|
16
|
-
# @raise [Vedeu::MissingRequired] When the controller name is not
|
16
|
+
# @raise [Vedeu::Error::MissingRequired] When the controller name is not
|
17
|
+
# given.
|
17
18
|
# @return [void]
|
18
19
|
def add_controller(controller, klass)
|
19
20
|
unless present?(controller)
|
20
|
-
fail Vedeu::MissingRequired,
|
21
|
+
fail Vedeu::Error::MissingRequired,
|
21
22
|
'Cannot store controller without a name attribute.'
|
22
23
|
end
|
23
24
|
|
@@ -40,8 +41,8 @@ module Vedeu
|
|
40
41
|
#
|
41
42
|
# @param controller [Symbol]
|
42
43
|
# @param action [Symbol]
|
43
|
-
# @raise [Vedeu::MissingRequired] When the controller name or action
|
44
|
-
# not given.
|
44
|
+
# @raise [Vedeu::Error::MissingRequired] When the controller name or action
|
45
|
+
# name is not given.
|
45
46
|
# @return [void]
|
46
47
|
def add_action(controller, action)
|
47
48
|
if present?(controller) && present?(action)
|
@@ -60,7 +61,7 @@ module Vedeu
|
|
60
61
|
storage
|
61
62
|
|
62
63
|
else
|
63
|
-
fail Vedeu::MissingRequired,
|
64
|
+
fail Vedeu::Error::MissingRequired,
|
64
65
|
'Cannot store action without a controller or name attribute.'
|
65
66
|
|
66
67
|
end
|
@@ -75,7 +76,8 @@ module Vedeu
|
|
75
76
|
# @param controller [Symbol]
|
76
77
|
# @param action [Symbol]
|
77
78
|
# @param args [void]
|
78
|
-
# @raise [Vedeu::ModelNotFound] When the controller is not
|
79
|
+
# @raise [Vedeu::Error::ModelNotFound] When the controller is not
|
80
|
+
# registered.
|
79
81
|
# @return [void]
|
80
82
|
def goto(controller, action, **args)
|
81
83
|
Vedeu.log(type: :debug,
|
@@ -114,11 +116,12 @@ module Vedeu
|
|
114
116
|
if registered?(controller)
|
115
117
|
return true if storage[controller][:actions].include?(action)
|
116
118
|
|
117
|
-
fail Vedeu::ActionNotFound,
|
119
|
+
fail Vedeu::Error::ActionNotFound,
|
118
120
|
"#{action} is not registered for #{controller}."
|
119
121
|
|
120
122
|
else
|
121
|
-
fail Vedeu::ControllerNotFound,
|
123
|
+
fail Vedeu::Error::ControllerNotFound,
|
124
|
+
"#{controller} is not registered."
|
122
125
|
|
123
126
|
end
|
124
127
|
end
|
@@ -138,15 +141,15 @@ module Vedeu
|
|
138
141
|
# Fetch the class for the controller by name.
|
139
142
|
#
|
140
143
|
# @param controller [Symbol]
|
141
|
-
# @raise [Vedeu::MissingRequired] When the given controller name does
|
142
|
-
# have a class defined.
|
144
|
+
# @raise [Vedeu::Error::MissingRequired] When the given controller name does
|
145
|
+
# not have a class defined.
|
143
146
|
# @return [String]
|
144
147
|
def klass_for(controller)
|
145
148
|
if registered?(controller) && klass_defined?(controller)
|
146
149
|
storage[controller][:klass]
|
147
150
|
|
148
151
|
else
|
149
|
-
fail Vedeu::MissingRequired,
|
152
|
+
fail Vedeu::Error::MissingRequired,
|
150
153
|
"Cannot route to #{controller} as no class defined."
|
151
154
|
|
152
155
|
end
|
@@ -9,7 +9,7 @@ module Vedeu
|
|
9
9
|
# @param value [String] The HTML/CSS colour.
|
10
10
|
# @param block [Proc]
|
11
11
|
# @return [Vedeu::Views::Stream]
|
12
|
-
# @raise [Vedeu::InvalidSyntax] The required block was not given.
|
12
|
+
# @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
|
13
13
|
def background(value, &block)
|
14
14
|
define_stream(background: value, &block)
|
15
15
|
end
|
@@ -20,7 +20,7 @@ module Vedeu
|
|
20
20
|
# @option attributes background [String] The HTML/CSS background colour.
|
21
21
|
# @param block [Proc]
|
22
22
|
# @return [Vedeu::Views::Stream]
|
23
|
-
# @raise [Vedeu::InvalidSyntax] The required block was not given.
|
23
|
+
# @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
|
24
24
|
def colour(attributes = {}, &block)
|
25
25
|
define_stream(attributes, &block)
|
26
26
|
end
|
@@ -28,7 +28,7 @@ module Vedeu
|
|
28
28
|
# @param value [String] The HTML/CSS colour.
|
29
29
|
# @param block [Proc]
|
30
30
|
# @return [Vedeu::Views::Stream]
|
31
|
-
# @raise [Vedeu::InvalidSyntax] The required block was not given.
|
31
|
+
# @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
|
32
32
|
def foreground(value, &block)
|
33
33
|
define_stream(foreground: value, &block)
|
34
34
|
end
|
@@ -45,11 +45,11 @@ module Vedeu
|
|
45
45
|
|
46
46
|
# @see Vedeu::Templating::Helpers#colour
|
47
47
|
def define_stream(attributes = {}, &block)
|
48
|
-
fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
|
48
|
+
fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
|
49
49
|
|
50
50
|
encode(
|
51
51
|
Vedeu::Views::Stream.build(
|
52
|
-
colour: Vedeu::Colour.new(attributes),
|
52
|
+
colour: Vedeu::Colours::Colour.new(attributes),
|
53
53
|
style: Vedeu::Style.new(attributes[:style]),
|
54
54
|
value: block.call))
|
55
55
|
end
|
@@ -47,15 +47,15 @@ module Vedeu
|
|
47
47
|
File.read(path)
|
48
48
|
end
|
49
49
|
|
50
|
-
# @raise [Vedeu::MissingRequired]
|
51
|
-
#
|
50
|
+
# @raise [Vedeu::Error::MissingRequired] When the path is empty or does
|
51
|
+
# not exist.
|
52
52
|
# @return [String]
|
53
53
|
def path
|
54
|
-
fail Vedeu::MissingRequired,
|
54
|
+
fail Vedeu::Error::MissingRequired,
|
55
55
|
'No path to template specified.' if @path.empty?
|
56
56
|
|
57
57
|
unless File.exist?(@path)
|
58
|
-
fail Vedeu::MissingRequired,
|
58
|
+
fail Vedeu::Error::MissingRequired,
|
59
59
|
"Template file cannot be found. (#{@path})"
|
60
60
|
end
|
61
61
|
|
@@ -51,7 +51,7 @@ module Vedeu
|
|
51
51
|
# Return the interface colours if a name option is set, otherwise use the
|
52
52
|
# default colours.
|
53
53
|
#
|
54
|
-
# @return [Vedeu::Colour|Hash<Symbol => Symbol>]
|
54
|
+
# @return [Vedeu::Colours::Colour|Hash<Symbol => Symbol>]
|
55
55
|
def default_colour
|
56
56
|
if options[:name]
|
57
57
|
interface.colour
|
@@ -11,10 +11,10 @@ module Vedeu
|
|
11
11
|
# Opens a terminal screen in either `raw` or `cooked` mode. On exit,
|
12
12
|
# attempts to restore the screen. See {Vedeu::Terminal#restore_screen}.
|
13
13
|
#
|
14
|
-
# @raise [Vedeu::InvalidSyntax] The required block was not given.
|
14
|
+
# @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
|
15
15
|
# @return [Array]
|
16
16
|
def open
|
17
|
-
fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
|
17
|
+
fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
|
18
18
|
|
19
19
|
if raw_mode? || fake_mode?
|
20
20
|
console.raw { initialize_screen(mode) { yield } }
|
data/lib/vedeu/version.rb
CHANGED
@@ -2,124 +2,128 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
5
|
+
module Colours
|
6
6
|
|
7
|
-
|
8
|
-
let(:instance) { described.new(colour) }
|
9
|
-
let(:colour) {}
|
7
|
+
describe Background do
|
10
8
|
|
11
|
-
|
9
|
+
let(:described) { Vedeu::Colours::Background }
|
10
|
+
let(:instance) { described.new(colour) }
|
11
|
+
let(:colour) {}
|
12
12
|
|
13
|
-
|
14
|
-
subject { instance.escape_sequence }
|
13
|
+
before { Vedeu.background_colours.reset! }
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
describe '#escape_sequence' do
|
16
|
+
subject { instance.escape_sequence }
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
context 'when the colour is empty' do
|
19
|
+
let(:colour) { '' }
|
20
|
+
|
21
|
+
it { subject.must_equal('') }
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
context 'when the colour is named (3-bit / 8 colours)' do
|
25
|
+
{
|
26
|
+
red: "\e[41m",
|
27
|
+
yellow: "\e[43m",
|
28
|
+
magenta: "\e[45m",
|
29
|
+
white: "\e[107m",
|
30
|
+
default: "\e[49m",
|
31
|
+
unknown: '',
|
32
|
+
}.map do |colour, result|
|
33
|
+
it "returns the correct escape sequence for #{colour}" do
|
34
|
+
described.new(colour).escape_sequence.must_equal(result)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
end
|
35
|
-
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
context 'when the colour is numbered (8-bit / 256 colours)' do
|
40
|
+
{
|
41
|
+
24 => "\e[48;5;24m",
|
42
|
+
56 => "\e[48;5;56m",
|
43
|
+
82 => "\e[48;5;82m",
|
44
|
+
118 => "\e[48;5;118m",
|
45
|
+
143 => "\e[48;5;143m",
|
46
|
+
219 => "\e[48;5;219m",
|
47
|
+
-2 => '',
|
48
|
+
442 => ''
|
49
|
+
}.map do |colour, result|
|
50
|
+
it "returns the correct escape sequence for #{colour}" do
|
51
|
+
described.new(colour).escape_sequence.must_equal(result)
|
52
|
+
end
|
50
53
|
end
|
51
54
|
end
|
52
|
-
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
56
|
+
context 'when the colour is a CSS value (8-bit / 256 colours)' do
|
57
|
+
before { Vedeu::Configuration.stubs(:colour_mode).returns(8) }
|
58
|
+
|
59
|
+
{
|
60
|
+
'#5f0000' => "\e[48;5;52m",
|
61
|
+
'#008700' => "\e[48;5;28m",
|
62
|
+
'#0000d7' => "\e[48;5;20m",
|
63
|
+
'#afafaf' => "\e[48;5;145m",
|
64
|
+
'#afd700' => "\e[48;5;148m",
|
65
|
+
'#af005f' => "\e[48;5;125m",
|
66
|
+
'999999' => '',
|
67
|
+
'#12121' => '',
|
68
|
+
'#h11111' => '',
|
69
|
+
}.map do |colour, result|
|
70
|
+
it "returns the correct escape sequence for #{colour}" do
|
71
|
+
described.new(colour).escape_sequence.must_equal(result)
|
72
|
+
end
|
70
73
|
end
|
71
74
|
end
|
72
|
-
end
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
76
|
+
context 'when the colour is a CSS value (24-bit / 16.8mil colours)' do
|
77
|
+
{
|
78
|
+
'#5f0000' => "\e[48;2;95;0;0m",
|
79
|
+
'#008700' => "\e[48;2;0;135;0m",
|
80
|
+
'#0000d7' => "\e[48;2;0;0;215m",
|
81
|
+
'#afafaf' => "\e[48;2;175;175;175m",
|
82
|
+
'#afd700' => "\e[48;2;175;215;0m",
|
83
|
+
'#af005f' => "\e[48;2;175;0;95m",
|
84
|
+
'999999' => '',
|
85
|
+
'#12121' => '',
|
86
|
+
'#h11111' => '',
|
87
|
+
}.map do |colour, result|
|
88
|
+
it "returns the correct escape sequence for #{colour}" do
|
89
|
+
described.new(colour).escape_sequence.must_equal(result)
|
90
|
+
end
|
88
91
|
end
|
89
92
|
end
|
90
93
|
end
|
91
|
-
end
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
+
describe '.to_html' do
|
96
|
+
subject { instance.to_html }
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
+
context 'when the colour is empty' do
|
99
|
+
let(:colour) {}
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
+
it { subject.must_equal('') }
|
102
|
+
end
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
+
context 'when the colour is named (3-bit / 8 colours)' do
|
105
|
+
let(:colour) { :red }
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
+
it { subject.must_equal('') }
|
108
|
+
end
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
+
context 'when the colour is numbered (8-bit / 256 colours)' do
|
111
|
+
let(:colour) { 118 }
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
+
it { subject.must_equal('') }
|
114
|
+
end
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
+
context 'when the colour is a CSS value' do
|
117
|
+
let(:colour) { '#afd700' }
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
+
it 'returns the colour as a CSS value' do
|
120
|
+
subject.must_equal('#afd700')
|
121
|
+
end
|
119
122
|
end
|
120
123
|
end
|
121
|
-
end
|
122
124
|
|
123
|
-
|
125
|
+
end # Background
|
126
|
+
|
127
|
+
end # Colours
|
124
128
|
|
125
129
|
end # Vedeu
|