vedeu 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/LICENSE.txt +5 -0
- data/bin/vedeu +3 -1
- data/docs/api.md +2 -0
- data/examples/cursor_app/cursor_app.rb +22 -7
- data/examples/hello_world.rb +42 -0
- data/lib/vedeu.rb +5 -5
- data/lib/vedeu/api/api.rb +16 -33
- data/lib/vedeu/api/helpers.rb +86 -0
- data/lib/vedeu/api/interface.rb +60 -17
- data/lib/vedeu/api/keymap.rb +5 -0
- data/lib/vedeu/api/line.rb +52 -34
- data/lib/vedeu/api/menu.rb +1 -1
- data/lib/vedeu/api/stream.rb +0 -34
- data/lib/vedeu/configuration/api.rb +10 -10
- data/lib/vedeu/configuration/cli.rb +1 -1
- data/lib/vedeu/launcher.rb +21 -6
- data/lib/vedeu/models/background.rb +1 -1
- data/lib/vedeu/models/composition.rb +1 -1
- data/lib/vedeu/models/cursor.rb +25 -35
- data/lib/vedeu/models/foreground.rb +1 -1
- data/lib/vedeu/models/geometry.rb +216 -6
- data/lib/vedeu/models/interface.rb +14 -16
- data/lib/vedeu/models/keymap.rb +38 -6
- data/lib/vedeu/models/line.rb +1 -1
- data/lib/vedeu/models/stream.rb +1 -1
- data/lib/vedeu/output/compositor.rb +1 -1
- data/lib/vedeu/output/render.rb +1 -5
- data/lib/vedeu/output/viewport.rb +37 -2
- data/lib/vedeu/repositories/buffers.rb +21 -27
- data/lib/vedeu/repositories/cursors.rb +3 -15
- data/lib/vedeu/repositories/focus.rb +2 -6
- data/lib/vedeu/repositories/groups.rb +1 -1
- data/lib/vedeu/repositories/interfaces.rb +1 -1
- data/lib/vedeu/repositories/keymaps.rb +26 -22
- data/lib/vedeu/repositories/menus.rb +1 -1
- data/lib/vedeu/repositories/offsets.rb +30 -12
- data/lib/vedeu/repositories/positional.rb +23 -0
- data/lib/vedeu/support/colour_translator.rb +1 -16
- data/lib/vedeu/support/esc.rb +23 -28
- data/lib/vedeu/support/event.rb +6 -14
- data/lib/vedeu/{output → support}/refresh.rb +0 -0
- data/lib/vedeu/support/registrar.rb +6 -14
- data/lib/vedeu/support/repository.rb +3 -2
- data/lib/vedeu/support/terminal.rb +9 -13
- data/lib/vedeu/support/trace.rb +2 -3
- data/test/integration/cursors_test.rb +9 -0
- data/test/integration/views/basic_view_test.rb +19 -0
- data/test/lib/vedeu/api/api_test.rb +28 -5
- data/test/lib/vedeu/api/composition_test.rb +7 -3
- data/test/lib/vedeu/api/defined_test.rb +9 -3
- data/test/lib/vedeu/api/helpers_test.rb +39 -5
- data/test/lib/vedeu/api/interface_test.rb +88 -8
- data/test/lib/vedeu/api/keymap_test.rb +5 -3
- data/test/lib/vedeu/api/line_test.rb +9 -3
- data/test/lib/vedeu/api/menu_test.rb +11 -7
- data/test/lib/vedeu/api/stream_test.rb +9 -31
- data/test/lib/vedeu/application_test.rb +25 -2
- data/test/lib/vedeu/configuration/api_test.rb +5 -3
- data/test/lib/vedeu/configuration/cli_test.rb +5 -3
- data/test/lib/vedeu/configuration/configuration_test.rb +5 -2
- data/test/lib/vedeu/input/input_test.rb +5 -2
- data/test/lib/vedeu/launcher_test.rb +37 -2
- data/test/lib/vedeu/models/background_test.rb +6 -2
- data/test/lib/vedeu/models/char_test.rb +9 -6
- data/test/lib/vedeu/models/colour_test.rb +6 -2
- data/test/lib/vedeu/models/composition_test.rb +4 -2
- data/test/lib/vedeu/models/cursor_test.rb +27 -16
- data/test/lib/vedeu/models/foreground_test.rb +6 -2
- data/test/lib/vedeu/models/geometry_test.rb +6 -2
- data/test/lib/vedeu/models/interface_test.rb +5 -2
- data/test/lib/vedeu/models/keymap_test.rb +6 -4
- data/test/lib/vedeu/models/line_test.rb +5 -2
- data/test/lib/vedeu/models/offset_test.rb +7 -3
- data/test/lib/vedeu/models/stream_test.rb +4 -2
- data/test/lib/vedeu/models/style_test.rb +5 -2
- data/test/lib/vedeu/output/clear_test.rb +6 -2
- data/test/lib/vedeu/output/compositor_test.rb +8 -4
- data/test/lib/vedeu/output/render_test.rb +9 -6
- data/test/lib/vedeu/output/view_test.rb +7 -3
- data/test/lib/vedeu/output/viewport_test.rb +42 -9
- data/test/lib/vedeu/repositories/buffers_test.rb +52 -12
- data/test/lib/vedeu/repositories/cursors_test.rb +4 -26
- data/test/lib/vedeu/repositories/events_test.rb +6 -2
- data/test/lib/vedeu/repositories/focus_test.rb +5 -2
- data/test/lib/vedeu/repositories/groups_test.rb +5 -2
- data/test/lib/vedeu/repositories/interfaces_test.rb +4 -2
- data/test/lib/vedeu/repositories/keymaps_test.rb +8 -2
- data/test/lib/vedeu/repositories/menus_test.rb +3 -2
- data/test/lib/vedeu/repositories/offsets_test.rb +26 -19
- data/test/lib/vedeu/repositories/positional_test.rb +50 -0
- data/test/lib/vedeu/support/coercions_test.rb +7 -3
- data/test/lib/vedeu/support/colour_translator_test.rb +6 -2
- data/test/lib/vedeu/support/common_test.rb +5 -3
- data/test/lib/vedeu/support/esc_test.rb +6 -2
- data/test/lib/vedeu/support/event_test.rb +6 -2
- data/test/lib/vedeu/support/grid_test.rb +9 -3
- data/test/lib/vedeu/support/keymap_validator_test.rb +5 -2
- data/test/lib/vedeu/support/log_test.rb +4 -2
- data/test/lib/vedeu/support/menu_test.rb +10 -2
- data/test/lib/vedeu/support/position_test.rb +10 -2
- data/test/lib/vedeu/support/presentation_test.rb +6 -3
- data/test/lib/vedeu/{output → support}/refresh_test.rb +6 -2
- data/test/lib/vedeu/support/registrar_test.rb +2 -2
- data/test/lib/vedeu/support/repository_test.rb +4 -3
- data/test/lib/vedeu/support/terminal_test.rb +6 -2
- data/test/lib/vedeu/support/trace_test.rb +17 -2
- data/test/lib/vedeu_test.rb +1 -1
- data/vedeu.gemspec +2 -2
- metadata +13 -13
- data/lib/vedeu/output/area.rb +0 -284
- data/lib/vedeu/support/move.rb +0 -50
- data/test/lib/vedeu/output/area_test.rb +0 -242
- data/test/lib/vedeu/support/move_test.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d92eea450aa078936ad63e48458e87bffc1b94ef
|
4
|
+
data.tar.gz: 7b58b5c6c47151c7635971abc608b7951e1cfa77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9363fca14b44becccaa8b29c32185175270e1ae9769d9ec0410db5c71a48cfcb199e3797e79a7bca7b4771743225641aeb44462bfe1d9c7205f3e2e06d215382
|
7
|
+
data.tar.gz: da6d294f0a25f2b010972e6cdcee7ec8a3fe8b3cadf21cc28f34d6f602d1ff73e2a7c11aa03df2f3d2d0e2cf478af48812cca6f34e494eebff76fa2d7029c2cd
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Copyright (c) 2014 Gavin Laking
|
2
2
|
Copyright (c) 2013 Steve Klabnik - Monologger
|
3
3
|
(https://github.com/steveklabnik/mono_logger)
|
4
|
+
Note: Code used inline in Vedeu::Log.
|
5
|
+
Copyright (c) 2013 Michael Grosser - Ruco
|
6
|
+
(https://github.com/grosser/ruco)
|
7
|
+
Note: Code from ruco's Window class was used as basis of
|
8
|
+
Vedeu::Viewport.
|
4
9
|
|
5
10
|
MIT License
|
6
11
|
|
data/bin/vedeu
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
|
+
lib_dir = File.dirname(__FILE__) + '/../lib'
|
4
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
3
5
|
|
4
6
|
-> { its -> { a } }
|
5
7
|
trap('INT') { exit! }
|
data/docs/api.md
CHANGED
@@ -60,6 +60,7 @@ Note: Nesting indicates where an API method is allowed/supposed to be used.
|
|
60
60
|
|
61
61
|
- interface
|
62
62
|
- centred (or centred!)
|
63
|
+
- cursor
|
63
64
|
- colour
|
64
65
|
- delay
|
65
66
|
- group
|
@@ -79,6 +80,7 @@ Note: Nesting indicates where an API method is allowed/supposed to be used.
|
|
79
80
|
- view
|
80
81
|
- view
|
81
82
|
- colour
|
83
|
+
- cursor
|
82
84
|
- line
|
83
85
|
- background
|
84
86
|
- colour
|
@@ -11,16 +11,26 @@ require 'vedeu'
|
|
11
11
|
class VedeuCursorApp
|
12
12
|
include Vedeu
|
13
13
|
|
14
|
-
event(:_initialize_) { trigger(:_refresh_) }
|
14
|
+
event(:_initialize_) { Vedeu.trigger(:_refresh_) }
|
15
15
|
|
16
16
|
interface 'iron' do
|
17
|
+
cursor true
|
17
18
|
centred true
|
18
19
|
colour foreground: '#ff0000', background: '#000000'
|
19
20
|
height 4
|
20
21
|
width 15
|
22
|
+
|
23
|
+
# provide 'vim' direction keys
|
24
|
+
keys do
|
25
|
+
key('k') { Vedeu.trigger(:_cursor_up_) }
|
26
|
+
key('l') { Vedeu.trigger(:_cursor_right_) }
|
27
|
+
key('j') { Vedeu.trigger(:_cursor_down_) }
|
28
|
+
key('h') { Vedeu.trigger(:_cursor_left_) }
|
29
|
+
end
|
21
30
|
end
|
22
31
|
|
23
32
|
interface 'gold' do
|
33
|
+
cursor false
|
24
34
|
colour foreground: '#00ff00', background: '#001100'
|
25
35
|
height 4
|
26
36
|
width 15
|
@@ -29,14 +39,12 @@ class VedeuCursorApp
|
|
29
39
|
end
|
30
40
|
|
31
41
|
keys do
|
32
|
-
key(:up) { trigger(:_cursor_up_) }
|
33
|
-
key(:right) { trigger(:_cursor_right_) }
|
34
|
-
key(:down) { trigger(:_cursor_down_) }
|
35
|
-
key(:left) { trigger(:_cursor_left_) }
|
42
|
+
key(:up) { Vedeu.trigger(:_cursor_up_) }
|
43
|
+
key(:right) { Vedeu.trigger(:_cursor_right_) }
|
44
|
+
key(:down) { Vedeu.trigger(:_cursor_down_) }
|
45
|
+
key(:left) { Vedeu.trigger(:_cursor_left_) }
|
36
46
|
end
|
37
47
|
|
38
|
-
focus('iron')
|
39
|
-
|
40
48
|
render do
|
41
49
|
view 'iron' do
|
42
50
|
line do
|
@@ -87,8 +95,15 @@ class VedeuCursorApp
|
|
87
95
|
end
|
88
96
|
end
|
89
97
|
end
|
98
|
+
|
99
|
+
view 'gold' do
|
100
|
+
cursor false
|
101
|
+
line 'Cursor: '
|
102
|
+
end
|
90
103
|
end
|
91
104
|
|
105
|
+
focus('iron') # not working right?!
|
106
|
+
|
92
107
|
def self.start
|
93
108
|
Vedeu::Launcher.new(['--debug']).execute!
|
94
109
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib_dir = File.dirname(__FILE__) + '/../lib'
|
4
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
5
|
+
|
6
|
+
trap('INT') { exit! }
|
7
|
+
|
8
|
+
# require 'bundler/setup' # uncomment to remove the need to do `bundle exec`.
|
9
|
+
require 'vedeu'
|
10
|
+
|
11
|
+
class HelloWorldApp
|
12
|
+
include Vedeu
|
13
|
+
|
14
|
+
configure do
|
15
|
+
debug!
|
16
|
+
log '/tmp/hello_world_vedeu.log'
|
17
|
+
end
|
18
|
+
|
19
|
+
event(:_initialize_) { Vedeu.trigger(:_refresh_) }
|
20
|
+
|
21
|
+
interface 'messages' do
|
22
|
+
background '#000000'
|
23
|
+
centred!
|
24
|
+
foreground '#00ff00'
|
25
|
+
height 3
|
26
|
+
width 20
|
27
|
+
end
|
28
|
+
|
29
|
+
render do
|
30
|
+
view 'messages' do
|
31
|
+
line ' Hello World!'
|
32
|
+
line
|
33
|
+
line " Press 'q' to exit. "
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.start
|
38
|
+
Vedeu::Launcher.execute!(ARGV)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
HelloWorldApp.start
|
data/lib/vedeu.rb
CHANGED
@@ -36,6 +36,8 @@ require 'vedeu/configuration/configuration'
|
|
36
36
|
require 'vedeu/support/log'
|
37
37
|
require 'vedeu/support/trace'
|
38
38
|
|
39
|
+
require 'vedeu/models/keymap'
|
40
|
+
require 'vedeu/api/keymap'
|
39
41
|
require 'vedeu/api/api'
|
40
42
|
|
41
43
|
require 'vedeu/support/coercions'
|
@@ -56,7 +58,7 @@ require 'vedeu/models/colour'
|
|
56
58
|
require 'vedeu/models/style'
|
57
59
|
require 'vedeu/models/interface'
|
58
60
|
require 'vedeu/models/cursor'
|
59
|
-
|
61
|
+
|
60
62
|
require 'vedeu/models/char'
|
61
63
|
require 'vedeu/models/line'
|
62
64
|
require 'vedeu/models/stream'
|
@@ -68,12 +70,12 @@ require 'vedeu/api/defined'
|
|
68
70
|
require 'vedeu/api/composition'
|
69
71
|
require 'vedeu/api/helpers'
|
70
72
|
require 'vedeu/api/interface'
|
71
|
-
require 'vedeu/api/keymap'
|
72
73
|
require 'vedeu/api/line'
|
73
74
|
require 'vedeu/api/menu'
|
74
75
|
require 'vedeu/api/stream'
|
75
76
|
|
76
77
|
require 'vedeu/support/keymap_validator'
|
78
|
+
require 'vedeu/repositories/positional'
|
77
79
|
require 'vedeu/repositories/offsets'
|
78
80
|
require 'vedeu/repositories/menus'
|
79
81
|
require 'vedeu/repositories/keymaps'
|
@@ -85,18 +87,16 @@ require 'vedeu/repositories/buffers'
|
|
85
87
|
require 'vedeu/repositories/cursors'
|
86
88
|
|
87
89
|
require 'vedeu/support/registrar'
|
90
|
+
require 'vedeu/support/refresh'
|
88
91
|
|
89
|
-
require 'vedeu/output/area'
|
90
92
|
require 'vedeu/output/clear'
|
91
93
|
require 'vedeu/output/compositor'
|
92
|
-
require 'vedeu/output/refresh'
|
93
94
|
require 'vedeu/output/render'
|
94
95
|
require 'vedeu/output/view'
|
95
96
|
require 'vedeu/output/viewport'
|
96
97
|
|
97
98
|
require 'vedeu/support/grid'
|
98
99
|
require 'vedeu/support/menu'
|
99
|
-
require 'vedeu/support/move'
|
100
100
|
|
101
101
|
require 'vedeu/input/input'
|
102
102
|
|
data/lib/vedeu/api/api.rb
CHANGED
@@ -6,6 +6,10 @@ module Vedeu
|
|
6
6
|
# @api public
|
7
7
|
module API
|
8
8
|
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def_delegators Keymap, :keys
|
12
|
+
|
9
13
|
# Configure Vedeu using a simple configuration DSL.
|
10
14
|
#
|
11
15
|
# @param block [Proc]
|
@@ -119,6 +123,8 @@ module Vedeu
|
|
119
123
|
|
120
124
|
# Simulate a keypress.
|
121
125
|
#
|
126
|
+
# @todo Replace with: def_delegators Keymaps, :keypress
|
127
|
+
#
|
122
128
|
# @example
|
123
129
|
# Vedeu.keypress('s')
|
124
130
|
#
|
@@ -127,38 +133,6 @@ module Vedeu
|
|
127
133
|
Vedeu::Keymaps.use(key)
|
128
134
|
end
|
129
135
|
|
130
|
-
# Define actions for keypresses for when specific interfaces are in focus.
|
131
|
-
# Unless an interface is specified, the key will be assumed to be global,
|
132
|
-
# meaning its action will happen regardless of the interface in focus.
|
133
|
-
#
|
134
|
-
# @api public
|
135
|
-
# @param name_or_names [String] The name or names of the interface(s) which
|
136
|
-
# will handle these keys.
|
137
|
-
# @param block [Proc]
|
138
|
-
#
|
139
|
-
# @example
|
140
|
-
# keys do # => will be global
|
141
|
-
# key('s') { :something }
|
142
|
-
# ...
|
143
|
-
#
|
144
|
-
# keys 'my_interface' do # => will only function when 'my_interface'
|
145
|
-
# ... # is in focus
|
146
|
-
#
|
147
|
-
# keys('main', 'other') do # => will function for both 'main' and
|
148
|
-
# ... # 'other' interfaces
|
149
|
-
#
|
150
|
-
# keys do
|
151
|
-
# interface 'my_interface' # => will only function when 'my_interface'
|
152
|
-
# ... # is in focus
|
153
|
-
#
|
154
|
-
# @raise [InvalidSyntax] When the required block is not given.
|
155
|
-
# @return [API::Keymap]
|
156
|
-
def keys(*name_or_names, &block)
|
157
|
-
fail InvalidSyntax, '`keys` requires a block.' unless block_given?
|
158
|
-
|
159
|
-
API::Keymap.define({ interfaces: name_or_names }, &block)
|
160
|
-
end
|
161
|
-
|
162
136
|
# Write a message to the Vedeu log file located at `$HOME/.vedeu/vedeu.log`
|
163
137
|
#
|
164
138
|
# @param message [String] The message you wish to emit to the log
|
@@ -214,6 +188,10 @@ module Vedeu
|
|
214
188
|
# view 'my_interface' do
|
215
189
|
# ...
|
216
190
|
#
|
191
|
+
# Vedeu.render do
|
192
|
+
# view 'my_interface' do
|
193
|
+
# ...
|
194
|
+
#
|
217
195
|
# @raise [InvalidSyntax] When the required block is not given.
|
218
196
|
# @return [Array] A collection of strings, each defining containing the
|
219
197
|
# escape sequences and content. This data has already been sent to the
|
@@ -294,6 +272,11 @@ module Vedeu
|
|
294
272
|
|
295
273
|
# Instruct Vedeu to treat contents of block as a single composition.
|
296
274
|
#
|
275
|
+
# @note The views declared within this block are stored in their respective
|
276
|
+
# interface back buffers until a refresh event occurs. When the refresh
|
277
|
+
# event is triggered, the back buffers are swapped into the front buffers
|
278
|
+
# and the content here will be rendered to {Terminal.output}.
|
279
|
+
#
|
297
280
|
# @param block [Proc] Instructs Vedeu to treat all of the 'view' directives
|
298
281
|
# therein as one instruction. Useful for redrawing multiple interfaces at
|
299
282
|
# once.
|
@@ -314,7 +297,7 @@ module Vedeu
|
|
314
297
|
# ...
|
315
298
|
#
|
316
299
|
# @raise [InvalidSyntax] When the required block is not given.
|
317
|
-
# @return [
|
300
|
+
# @return [Array]
|
318
301
|
def views(&block)
|
319
302
|
fail InvalidSyntax, '`views` requires a block.' unless block_given?
|
320
303
|
|
data/lib/vedeu/api/helpers.rb
CHANGED
@@ -8,6 +8,50 @@ module Vedeu
|
|
8
8
|
# @api public
|
9
9
|
module Helpers
|
10
10
|
|
11
|
+
include Common
|
12
|
+
|
13
|
+
# Define the background colour for an interface, line, or a stream. When
|
14
|
+
# called with a block, will create a new stream with the background colour
|
15
|
+
# specified; see {Vedeu::API::Stream} for directives which are valid
|
16
|
+
# within the block. When the block terminates, the background will return
|
17
|
+
# to that of the parent.
|
18
|
+
#
|
19
|
+
# @param value [String]
|
20
|
+
# @param block [Proc]
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# interface 'my_interface' do
|
24
|
+
# background '#0022ff'
|
25
|
+
# ...
|
26
|
+
#
|
27
|
+
# line do
|
28
|
+
# background '#0022ff'
|
29
|
+
# ...
|
30
|
+
#
|
31
|
+
# stream do
|
32
|
+
# background '#0022ff'
|
33
|
+
# ...
|
34
|
+
#
|
35
|
+
# foreground('#0022ff') { 'This will be blue.' }
|
36
|
+
#
|
37
|
+
# @raise [InvalidSyntax] When the value is not defined.
|
38
|
+
# @return [Hash]
|
39
|
+
def background(value = '', &block)
|
40
|
+
unless defined_value?(value)
|
41
|
+
fail InvalidSyntax, '`background` requires a value.'
|
42
|
+
end
|
43
|
+
|
44
|
+
if block_given?
|
45
|
+
attributes[:streams] << API::Stream
|
46
|
+
.build({ colour: { background: value },
|
47
|
+
parent: self.view_attributes }, &block)
|
48
|
+
|
49
|
+
else
|
50
|
+
attributes[:colour].merge!({ background: value })
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
11
55
|
# Define either or both foreground and background colours for an
|
12
56
|
# interface, line or a stream.
|
13
57
|
#
|
@@ -38,6 +82,48 @@ module Vedeu
|
|
38
82
|
attributes[:colour] = values
|
39
83
|
end
|
40
84
|
|
85
|
+
# Define the foreground colour for an interface, line, or a stream. When
|
86
|
+
# called with a block, will create a new stream with the foreground colour
|
87
|
+
# specified; see {Vedeu::API::Stream} for directives which are valid
|
88
|
+
# within the block. When the block terminates, the foreground will return
|
89
|
+
# to that of the parent.
|
90
|
+
#
|
91
|
+
# @param value [String]
|
92
|
+
# @param block [Proc]
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# interface 'my_interface' do
|
96
|
+
# foreground '#0022ff'
|
97
|
+
# ...
|
98
|
+
#
|
99
|
+
# line do
|
100
|
+
# foreground '#0022ff'
|
101
|
+
# ...
|
102
|
+
#
|
103
|
+
# stream do
|
104
|
+
# foreground '#0022ff'
|
105
|
+
# ...
|
106
|
+
#
|
107
|
+
# foreground('#0022ff') { 'This will be blue.' }
|
108
|
+
#
|
109
|
+
# @raise [InvalidSyntax] When the value is not defined.
|
110
|
+
# @return [Hash]
|
111
|
+
def foreground(value = '', &block)
|
112
|
+
unless defined_value?(value)
|
113
|
+
fail InvalidSyntax, '`foreground` requires a value.'
|
114
|
+
end
|
115
|
+
|
116
|
+
if block_given?
|
117
|
+
attributes[:streams] << API::Stream
|
118
|
+
.build({ colour: { foreground: value },
|
119
|
+
parent: self.view_attributes }, &block)
|
120
|
+
|
121
|
+
else
|
122
|
+
attributes[:colour].merge!({ foreground: value })
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
41
127
|
# Define a style or styles for an interface, line or a stream.
|
42
128
|
#
|
43
129
|
# @param values [Array|String]
|
data/lib/vedeu/api/interface.rb
CHANGED
@@ -23,24 +23,54 @@ module Vedeu
|
|
23
23
|
# centred false
|
24
24
|
# ...
|
25
25
|
#
|
26
|
-
# @return [
|
26
|
+
# @return [Boolean]
|
27
27
|
def centred(value = true)
|
28
28
|
attributes[:geometry][:centred] = !!(value)
|
29
29
|
end
|
30
30
|
alias_method :centred!, :centred
|
31
31
|
|
32
|
+
# Set the cursor visibility on an interface or view.
|
33
|
+
#
|
34
|
+
# @param value [Boolean] Any value other than nil or false will evaluate
|
35
|
+
# to true.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# interface 'my_interface' do
|
39
|
+
# cursor true
|
40
|
+
# ...
|
41
|
+
#
|
42
|
+
# view 'my_interface' do
|
43
|
+
# cursor true
|
44
|
+
# ...
|
45
|
+
#
|
46
|
+
# @return [Symbol]
|
47
|
+
def cursor(value = true)
|
48
|
+
attributes[:cursor] = if !!value
|
49
|
+
:show
|
50
|
+
|
51
|
+
else
|
52
|
+
:hide
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
32
57
|
# To maintain performance interfaces can be delayed from refreshing too
|
33
58
|
# often, the reduces artefacts particularly when resizing the terminal
|
34
59
|
# screen.
|
35
60
|
#
|
36
61
|
# @param value [Fixnum|Float]
|
37
62
|
#
|
38
|
-
# @
|
63
|
+
# @example
|
64
|
+
# interface 'my_interface' do
|
65
|
+
# delay 0.5 # interface will not update more often than every 500ms.
|
66
|
+
# ...
|
67
|
+
#
|
68
|
+
# @return [Fixnum|Float]
|
39
69
|
def delay(value)
|
40
70
|
attributes[:delay] = value
|
41
71
|
end
|
42
72
|
|
43
|
-
#
|
73
|
+
# Specify a group for an interface. Interfaces of the same group can be
|
44
74
|
# targetted together; for example you may want to refresh multiple
|
45
75
|
# interfaces at once.
|
46
76
|
#
|
@@ -51,12 +81,12 @@ module Vedeu
|
|
51
81
|
# group 'main_screen'
|
52
82
|
# ...
|
53
83
|
#
|
54
|
-
# @return [
|
84
|
+
# @return [String]
|
55
85
|
def group(value)
|
56
86
|
attributes[:group] = value
|
57
87
|
end
|
58
88
|
|
59
|
-
#
|
89
|
+
# Specify the number of characters/rows/lines tall the interface will be.
|
60
90
|
#
|
61
91
|
# @param value [Fixnum]
|
62
92
|
#
|
@@ -65,14 +95,19 @@ module Vedeu
|
|
65
95
|
# height 8
|
66
96
|
# ...
|
67
97
|
#
|
68
|
-
# @return [
|
98
|
+
# @return [Fixnum]
|
69
99
|
def height(value)
|
70
100
|
Vedeu.log(out_of_bounds('height')) if y_out_of_bounds?(value)
|
71
101
|
|
72
102
|
attributes[:geometry][:height] = value
|
73
103
|
end
|
74
104
|
|
75
|
-
#
|
105
|
+
# @see Vedeu::API#keys
|
106
|
+
def keys(&block)
|
107
|
+
Keymap.keys(attributes[:name], &block)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Specify a single line in a view.
|
76
111
|
#
|
77
112
|
# @param value [String]
|
78
113
|
# @param block [Proc]
|
@@ -85,11 +120,11 @@ module Vedeu
|
|
85
120
|
#
|
86
121
|
# view 'my_interface' do
|
87
122
|
# line do
|
88
|
-
# ...
|
123
|
+
# ... see {API::Line} and {API::Stream}
|
89
124
|
# end
|
90
125
|
# end
|
91
126
|
#
|
92
|
-
# @return [API::
|
127
|
+
# @return [API::Line]
|
93
128
|
def line(value = '', &block)
|
94
129
|
if block_given?
|
95
130
|
attributes[:lines] << API::Line
|
@@ -112,13 +147,21 @@ module Vedeu
|
|
112
147
|
# name 'my_interface'
|
113
148
|
# ...
|
114
149
|
#
|
115
|
-
# @return [
|
150
|
+
# @return [String]
|
116
151
|
def name(value)
|
117
152
|
attributes[:name] = value
|
118
153
|
end
|
119
154
|
|
120
155
|
# Use the specified interface; useful for sharing attributes with other
|
121
|
-
# interfaces.
|
156
|
+
# interfaces. Any public method of #{Vedeu::Interface} is available.
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# interface 'my_interface' do
|
160
|
+
# use('my_other_interface').width # use the width of another interface
|
161
|
+
# ...
|
162
|
+
#
|
163
|
+
# Vedeu.use('my_other_interface').width # can be used in your code to
|
164
|
+
# # get this value
|
122
165
|
#
|
123
166
|
# @param value [String]
|
124
167
|
# @see Vedeu::API#use
|
@@ -126,7 +169,7 @@ module Vedeu
|
|
126
169
|
Vedeu.use(value)
|
127
170
|
end
|
128
171
|
|
129
|
-
#
|
172
|
+
# Specify the number of characters/columns wide the interface will be.
|
130
173
|
#
|
131
174
|
# @param value [Fixnum]
|
132
175
|
#
|
@@ -135,14 +178,14 @@ module Vedeu
|
|
135
178
|
# width 25
|
136
179
|
# ...
|
137
180
|
#
|
138
|
-
# @return [
|
181
|
+
# @return [Fixnum]
|
139
182
|
def width(value)
|
140
183
|
Vedeu.log(out_of_bounds('width')) if x_out_of_bounds?(value)
|
141
184
|
|
142
185
|
attributes[:geometry][:width] = value
|
143
186
|
end
|
144
187
|
|
145
|
-
#
|
188
|
+
# Specify the starting x position (column) of the interface.
|
146
189
|
#
|
147
190
|
# @param value [Fixnum]
|
148
191
|
# @param block [Proc]
|
@@ -156,7 +199,7 @@ module Vedeu
|
|
156
199
|
# # `my_interface` changes position,
|
157
200
|
# # `other_interface` will too.
|
158
201
|
#
|
159
|
-
# @return [
|
202
|
+
# @return [Fixnum]
|
160
203
|
def x(value = 0, &block)
|
161
204
|
return attributes[:geometry][:x] = block if block_given?
|
162
205
|
|
@@ -165,7 +208,7 @@ module Vedeu
|
|
165
208
|
attributes[:geometry][:x] = value
|
166
209
|
end
|
167
210
|
|
168
|
-
#
|
211
|
+
# Specify the starting y position (row/line) of the interface.
|
169
212
|
#
|
170
213
|
# @param value [Fixnum]
|
171
214
|
# @param block [Proc]
|
@@ -180,7 +223,7 @@ module Vedeu
|
|
180
223
|
# ... # `my_interface` changes position,
|
181
224
|
# # `other_interface` will too.
|
182
225
|
#
|
183
|
-
# @return [
|
226
|
+
# @return [Fixnum]
|
184
227
|
def y(value = 0, &block)
|
185
228
|
return attributes[:geometry][:y] = block if block_given?
|
186
229
|
|