vedeu 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/README.md +17 -3
- data/lib/vedeu.rb +12 -7
- data/lib/vedeu/api/api.rb +37 -13
- data/lib/vedeu/api/composition.rb +1 -6
- data/lib/vedeu/api/helpers.rb +2 -0
- data/lib/vedeu/api/interface.rb +47 -55
- data/lib/vedeu/api/line.rb +6 -0
- data/lib/vedeu/api/stream.rb +9 -1
- data/lib/vedeu/application.rb +38 -50
- data/lib/vedeu/configuration.rb +163 -44
- data/lib/vedeu/launcher.rb +3 -6
- data/lib/vedeu/models/attributes/background.rb +9 -1
- data/lib/vedeu/models/attributes/colour_translator.rb +40 -2
- data/lib/vedeu/models/attributes/foreground.rb +9 -1
- data/lib/vedeu/models/colour.rb +6 -0
- data/lib/vedeu/models/composition.rb +8 -1
- data/lib/vedeu/models/geometry.rb +27 -14
- data/lib/vedeu/models/interface.rb +59 -0
- data/lib/vedeu/models/line.rb +4 -0
- data/lib/vedeu/models/stream.rb +10 -0
- data/lib/vedeu/models/style.rb +2 -0
- data/lib/vedeu/support/buffer.rb +12 -1
- data/lib/vedeu/support/buffers.rb +10 -0
- data/lib/vedeu/support/clear.rb +4 -0
- data/lib/vedeu/support/esc.rb +26 -8
- data/lib/vedeu/support/event.rb +28 -0
- data/lib/vedeu/support/events.rb +2 -0
- data/lib/vedeu/support/focus.rb +14 -6
- data/lib/vedeu/support/grid.rb +6 -0
- data/lib/vedeu/support/groups.rb +13 -3
- data/lib/vedeu/support/input.rb +7 -2
- data/lib/vedeu/support/log.rb +7 -1
- data/lib/vedeu/support/position.rb +6 -0
- data/lib/vedeu/support/render.rb +38 -0
- data/lib/vedeu/support/terminal.rb +69 -15
- data/lib/vedeu/support/trace.rb +8 -0
- data/lib/vedeu/support/view.rb +6 -0
- data/test/integration/run_once_test.rb +26 -0
- data/test/lib/vedeu/api/api_test.rb +19 -6
- data/test/lib/vedeu/api/interface_test.rb +67 -1
- data/test/lib/vedeu/api/line_test.rb +10 -0
- data/test/lib/vedeu/api/stream_test.rb +8 -0
- data/test/lib/vedeu/configuration_test.rb +119 -12
- data/test/lib/vedeu/models/attributes/background_test.rb +1 -1
- data/test/lib/vedeu/models/attributes/foreground_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +22 -0
- data/test/lib/vedeu/support/buffer_test.rb +44 -0
- data/test/lib/vedeu/support/events_test.rb +3 -9
- data/test/lib/vedeu/support/input_test.rb +1 -0
- data/test/lib/vedeu/support/terminal_test.rb +128 -5
- data/test/test_helper.rb +2 -2
- data/vedeu.gemspec +1 -1
- metadata +5 -2
data/lib/vedeu/api/line.rb
CHANGED
@@ -5,6 +5,7 @@ module Vedeu
|
|
5
5
|
|
6
6
|
# Define a stream (a subset of a line).
|
7
7
|
#
|
8
|
+
# @api public
|
8
9
|
# @param block [Proc] Block contains directives relating to API::Stream.
|
9
10
|
#
|
10
11
|
# @example
|
@@ -18,6 +19,8 @@ module Vedeu
|
|
18
19
|
#
|
19
20
|
# @return [Array]
|
20
21
|
def stream(&block)
|
22
|
+
fail InvalidSyntax, '`stream` requires a block.' unless block_given?
|
23
|
+
|
21
24
|
attributes[:streams] << API::Stream.build(&block)
|
22
25
|
end
|
23
26
|
|
@@ -25,6 +28,7 @@ module Vedeu
|
|
25
28
|
# attributes for this line but is useful for adding lines straight into
|
26
29
|
# the interface.
|
27
30
|
#
|
31
|
+
# @api public
|
28
32
|
# @param value [String]
|
29
33
|
#
|
30
34
|
# @example
|
@@ -37,6 +41,7 @@ module Vedeu
|
|
37
41
|
attributes[:streams] << { text: value }
|
38
42
|
end
|
39
43
|
|
44
|
+
# @api public
|
40
45
|
# @param value [String]
|
41
46
|
# @param block [Proc]
|
42
47
|
#
|
@@ -53,6 +58,7 @@ module Vedeu
|
|
53
58
|
}, &block)
|
54
59
|
end
|
55
60
|
|
61
|
+
# @api public
|
56
62
|
# @param value [String]
|
57
63
|
# @param block [Proc]
|
58
64
|
#
|
data/lib/vedeu/api/stream.rb
CHANGED
@@ -6,6 +6,7 @@ module Vedeu
|
|
6
6
|
# Specify the alignment of the stream within the line. Useful in
|
7
7
|
# combination with #width to provide simple formatting effects.
|
8
8
|
#
|
9
|
+
# @api public
|
9
10
|
# @param value [Symbol] `:left`, `:centre` and `right` are valid values
|
10
11
|
# and will align accordingly. If not value is specified, the stream will
|
11
12
|
# left align.
|
@@ -18,11 +19,17 @@ module Vedeu
|
|
18
19
|
#
|
19
20
|
# @return [Symbol]
|
20
21
|
def align(value)
|
21
|
-
|
22
|
+
unless [:left, :right, :centre].include?(value.to_sym)
|
23
|
+
fail InvalidSyntax, '`align` requires a value of `:left`, `:right` ' \
|
24
|
+
'or `centre`.'
|
25
|
+
end
|
26
|
+
|
27
|
+
attributes[:align] = value.to_sym
|
22
28
|
end
|
23
29
|
|
24
30
|
# Add textual data to the stream via this method.
|
25
31
|
#
|
32
|
+
# @api public
|
26
33
|
# @param value [String] The text to be added to the stream. If the length
|
27
34
|
# of the text is greater than the interface's width, it will be
|
28
35
|
# truncated and ellipsized.
|
@@ -42,6 +49,7 @@ module Vedeu
|
|
42
49
|
# stream. Useful in combination with #align to provide simple formatting
|
43
50
|
# effects.
|
44
51
|
#
|
52
|
+
# @api public
|
45
53
|
# @param value [Fixnum] The width in characters.
|
46
54
|
#
|
47
55
|
# @example
|
data/lib/vedeu/application.rb
CHANGED
@@ -1,22 +1,32 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class Application
|
3
|
+
class << self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
5
|
+
# @return []
|
6
|
+
def start
|
7
|
+
new.start
|
8
|
+
end
|
9
|
+
alias_method :restart, :start
|
10
10
|
|
11
|
-
# @param options [Hash]
|
12
|
-
# @return [Application]
|
13
|
-
def initialize(options = {})
|
14
|
-
@options = options
|
15
11
|
end
|
16
12
|
|
13
|
+
# @return [Application]
|
14
|
+
def initialize; end
|
15
|
+
|
16
|
+
# Starts the application!
|
17
|
+
# - A new terminal screen is opened (or rather the current terminal is
|
18
|
+
# requested into either :raw or :cooked mode).
|
19
|
+
# - The cursor visibility is then set dependent on this mode. In :raw mode,
|
20
|
+
# the cursor is hidden.
|
21
|
+
# - The `:_initialize_` event is triggered. Vedeu does not handle this
|
22
|
+
# event; the client application may treat this event as Vedeu signalling
|
23
|
+
# that it is now ready.
|
24
|
+
# - We enter into the main sequence where the application will either run
|
25
|
+
# once or continuous, interactively or standalone.
|
26
|
+
#
|
17
27
|
# @return []
|
18
28
|
def start
|
19
|
-
Terminal.open
|
29
|
+
Terminal.open do
|
20
30
|
Terminal.set_cursor_mode
|
21
31
|
|
22
32
|
Vedeu.events.trigger(:_initialize_)
|
@@ -27,63 +37,41 @@ module Vedeu
|
|
27
37
|
|
28
38
|
private
|
29
39
|
|
30
|
-
|
31
|
-
|
40
|
+
# @api private
|
41
|
+
# @return []
|
32
42
|
def runner
|
33
|
-
if
|
34
|
-
|
43
|
+
if Configuration.once?
|
44
|
+
yield
|
35
45
|
|
36
46
|
else
|
37
|
-
|
47
|
+
run_many { yield }
|
38
48
|
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
52
|
+
# @api private
|
53
|
+
# @return []
|
42
54
|
def main_sequence
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def interactive?
|
47
|
-
options.fetch(:interactive)
|
48
|
-
end
|
49
|
-
|
50
|
-
def interactive
|
51
|
-
loop { yield }
|
52
|
-
|
53
|
-
rescue ModeSwitch
|
54
|
-
if Terminal.raw_mode?
|
55
|
-
Application.start({ mode: :cooked })
|
55
|
+
if Configuration.interactive?
|
56
|
+
Input.capture
|
56
57
|
|
57
58
|
else
|
58
|
-
|
59
|
+
# TODO: What should happen here?
|
59
60
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def mode
|
68
|
-
options.fetch(:mode)
|
69
|
-
end
|
64
|
+
# @api private
|
65
|
+
# @return []
|
66
|
+
def run_many
|
67
|
+
loop { yield }
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
end
|
69
|
+
rescue ModeSwitch
|
70
|
+
Terminal.switch_mode!
|
74
71
|
|
75
|
-
|
76
|
-
defaults.merge!(@options)
|
77
|
-
end
|
72
|
+
Application.restart
|
78
73
|
|
79
|
-
def defaults
|
80
|
-
{
|
81
|
-
debug: false,
|
82
|
-
interactive: true,
|
83
|
-
mode: :raw
|
84
|
-
}
|
85
74
|
end
|
86
|
-
# :nocov:
|
87
75
|
|
88
76
|
end
|
89
77
|
end
|
data/lib/vedeu/configuration.rb
CHANGED
@@ -1,97 +1,216 @@
|
|
1
1
|
module Vedeu
|
2
|
-
|
2
|
+
module Configuration
|
3
|
+
extend self
|
3
4
|
|
5
|
+
# Parses arguments passed on the command-line or via {Vedeu::Launcher} into
|
6
|
+
# options used by Vedeu to affect certain behaviours.
|
7
|
+
#
|
4
8
|
# @param args [Array]
|
5
9
|
# @return [Hash]
|
6
|
-
def
|
7
|
-
new
|
8
|
-
|
10
|
+
def configure(args = [])
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
opts.on('-i', '--interactive',
|
15
|
+
'Run the application in interactive mode (default).') do
|
16
|
+
options[:interactive] = true
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
19
|
+
opts.on('-I', '--noninteractive', '--standalone',
|
20
|
+
'Run the application non-interactively; i.e. not requiring ' \
|
21
|
+
'intervention from the user.') do
|
22
|
+
options[:interactive] = false
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
opts.on('-1', '--run-once',
|
26
|
+
'Run the application loop once.') do
|
27
|
+
options[:once] = true
|
28
|
+
end
|
26
29
|
|
27
|
-
opts.on('-
|
28
|
-
|
30
|
+
opts.on('-n', '--run-many',
|
31
|
+
'Run the application loop continuously (default).') do
|
32
|
+
options[:once] = false
|
29
33
|
end
|
30
34
|
|
31
35
|
opts.on('-c', '--cooked', 'Run application in cooked mode.') do
|
32
|
-
|
36
|
+
options[:terminal_mode] = :cooked
|
33
37
|
end
|
34
38
|
|
35
39
|
opts.on('-r', '--raw', 'Run application in raw mode (default).') do
|
36
|
-
|
40
|
+
options[:terminal_mode] = :raw
|
37
41
|
end
|
38
42
|
|
39
43
|
opts.on('-d', '--debug', 'Run application with debugging on.') do
|
40
|
-
|
44
|
+
options[:debug] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on('-D', '--trace', 'Run application with debugging on with ' \
|
48
|
+
'method and event tracing (noisy!).') do
|
49
|
+
options[:debug] = true
|
50
|
+
options[:trace] = true
|
41
51
|
end
|
42
52
|
|
43
|
-
opts.on('-C',
|
44
|
-
'
|
45
|
-
'
|
46
|
-
if [
|
47
|
-
|
53
|
+
opts.on('-C', '--colour-mode [COLOURS]', Integer,
|
54
|
+
'Run application in either `8`, `16` or `256` colour ' \
|
55
|
+
'mode.') do |colours|
|
56
|
+
if [8, 16, 256].include?(colours)
|
57
|
+
options[:colour_mode] = colours
|
48
58
|
|
49
59
|
else
|
50
|
-
|
60
|
+
options[:colour_mode] = 8
|
51
61
|
|
52
62
|
end
|
53
63
|
end
|
54
64
|
end
|
55
65
|
parser.parse!(args)
|
56
66
|
|
57
|
-
|
67
|
+
options
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns the chosen colour mode.
|
71
|
+
#
|
72
|
+
# @return [Fixnum]
|
73
|
+
def colour_mode
|
74
|
+
options[:colour_mode]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns whether debugging is enabled or disabled. Default is false;
|
78
|
+
# meaning nothing apart from warnings are written to the log file.
|
79
|
+
#
|
80
|
+
# @return [TrueClass|FalseClass]
|
81
|
+
def debug?
|
82
|
+
options[:debug]
|
83
|
+
end
|
84
|
+
alias_method :debug, :debug?
|
85
|
+
|
86
|
+
# Returns whether the application is interactive (required user input) or
|
87
|
+
# standalone (will run until terminates of natural causes.) Default is true;
|
88
|
+
# meaning the application will require user input.
|
89
|
+
#
|
90
|
+
# @return [TrueClass|FalseClass]
|
91
|
+
def interactive?
|
92
|
+
options[:interactive]
|
93
|
+
end
|
94
|
+
alias_method :interactive, :interactive?
|
95
|
+
|
96
|
+
# Returns whether the application will run through its main loop once or
|
97
|
+
# not. Default is false; meaning the application will loop forever or until
|
98
|
+
# terminated by the user.
|
99
|
+
#
|
100
|
+
# @return [TrueClass|FalseClass]
|
101
|
+
def once?
|
102
|
+
options[:once]
|
103
|
+
end
|
104
|
+
alias_method :once, :once?
|
105
|
+
|
106
|
+
# Returns the terminal mode for the application. Default is `:raw`.
|
107
|
+
#
|
108
|
+
# @return [Symbol]
|
109
|
+
def terminal_mode
|
110
|
+
options[:terminal_mode]
|
58
111
|
end
|
59
112
|
|
113
|
+
# Returns whether tracing is enabled or disabled. Tracing is very noisy in
|
114
|
+
# the log file (logging method calls and events trigger). Default is false;
|
115
|
+
# meaning tracing is disabled.
|
116
|
+
#
|
117
|
+
# @return [TrueClass|FalseClass]
|
118
|
+
def trace?
|
119
|
+
options[:trace]
|
120
|
+
end
|
121
|
+
alias_method :trace, :trace?
|
122
|
+
|
123
|
+
# Returns all the options current configured.
|
124
|
+
#
|
60
125
|
# @return [Hash]
|
61
126
|
def options
|
62
|
-
@options ||= defaults
|
127
|
+
@options ||= defaults
|
63
128
|
end
|
64
129
|
|
65
|
-
|
130
|
+
# Resets all options to Vedeu defaults.
|
131
|
+
#
|
132
|
+
# @return [Hash]
|
133
|
+
def reset
|
134
|
+
@options = defaults
|
135
|
+
end
|
66
136
|
|
67
|
-
|
137
|
+
private
|
68
138
|
|
139
|
+
# The Vedeu default options, which of course are influenced by enviroment
|
140
|
+
# variables also.
|
141
|
+
#
|
142
|
+
# @api private
|
143
|
+
# @return [Hash]
|
69
144
|
def defaults
|
70
145
|
{
|
71
|
-
colour_mode:
|
72
|
-
debug:
|
73
|
-
interactive:
|
74
|
-
|
146
|
+
colour_mode: detect_colour_mode,
|
147
|
+
debug: detect_debug_mode,
|
148
|
+
interactive: true,
|
149
|
+
once: false,
|
150
|
+
terminal_mode: :raw, #cooked
|
151
|
+
trace: detect_trace_mode,
|
75
152
|
}
|
76
153
|
end
|
77
154
|
|
155
|
+
# Determine the terminal colour mode via enviroment variables, or be
|
156
|
+
# optimistic and settle for 256 colours.
|
157
|
+
#
|
158
|
+
# @api private
|
159
|
+
# @return [Fixnum]
|
78
160
|
def detect_colour_mode
|
79
|
-
if ENV['
|
80
|
-
case ENV['
|
161
|
+
if ENV['VEDEU_TERM']
|
162
|
+
case ENV['VEDEU_TERM']
|
81
163
|
when /-256color$/ then 256
|
82
164
|
when /-truecolor$/ then 16777216
|
83
|
-
else
|
84
|
-
256
|
165
|
+
else 256
|
85
166
|
end
|
86
167
|
|
87
|
-
|
168
|
+
elsif ENV['TERM']
|
88
169
|
case ENV['TERM']
|
89
170
|
when /-256color$/, 'xterm' then 256
|
90
171
|
when /-color$/, 'rxvt' then 16
|
91
|
-
else
|
92
|
-
256
|
172
|
+
else 256
|
93
173
|
end
|
94
174
|
|
175
|
+
else
|
176
|
+
256
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# Determine the debug mode via an enviroment variable.
|
182
|
+
#
|
183
|
+
# @api private
|
184
|
+
# @return [TrueClass|FalseClass]
|
185
|
+
def detect_debug_mode
|
186
|
+
if ENV['VEDEU_DEBUG']
|
187
|
+
case ENV['VEDEU_DEBUG']
|
188
|
+
when 'true' then true
|
189
|
+
when 'false' then false
|
190
|
+
else false
|
191
|
+
end
|
192
|
+
|
193
|
+
else
|
194
|
+
false
|
195
|
+
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# Determine the trace mode via an environment variable.
|
200
|
+
#
|
201
|
+
# @api private
|
202
|
+
# @return [TrueClass|FalseClass]
|
203
|
+
def detect_trace_mode
|
204
|
+
if ENV['VEDEU_TRACE']
|
205
|
+
case ENV['VEDEU_TRACE']
|
206
|
+
when 'true' then true
|
207
|
+
when 'false' then false
|
208
|
+
else false
|
209
|
+
end
|
210
|
+
|
211
|
+
else
|
212
|
+
false
|
213
|
+
|
95
214
|
end
|
96
215
|
end
|
97
216
|
|