vedeu 0.2.12 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Guardfile +13 -0
- data/README.md +11 -9
- data/Rakefile +10 -1
- data/bin/vedeu_test +14 -0
- data/config/cucumber.yml +8 -0
- data/docs/api.md +45 -16
- data/docs/events.md +21 -9
- data/docs/getting_started.md +16 -0
- data/docs/views.md +158 -0
- data/examples/borders_app.rb +236 -110
- data/examples/colour_support.sh +98 -0
- data/examples/colours_app.rb +41 -0
- data/examples/configuration_app.rb +11 -6
- data/examples/cursor_app.rb +60 -61
- data/examples/focus_app.rb +72 -34
- data/examples/hello_world.rb +13 -8
- data/examples/lines_app.rb +37 -28
- data/features/start_stop.feature +27 -0
- data/features/support/env.rb +14 -0
- data/lib/vedeu/all.rb +29 -0
- data/lib/vedeu/api.rb +39 -0
- data/lib/vedeu/application.rb +15 -7
- data/lib/vedeu/bindings.rb +121 -0
- data/lib/vedeu/buffers/all.rb +10 -0
- data/lib/vedeu/{repositories/models → buffers}/buffer.rb +47 -64
- data/lib/vedeu/buffers/display_buffer.rb +118 -0
- data/lib/vedeu/configuration/all.rb +6 -0
- data/lib/vedeu/configuration/api.rb +3 -1
- data/lib/vedeu/configuration/cli.rb +3 -1
- data/lib/vedeu/configuration/configuration.rb +23 -2
- data/lib/vedeu/cursor/all.rb +23 -0
- data/lib/vedeu/cursor/cursor.rb +116 -0
- data/lib/vedeu/cursor/move_cursor.rb +137 -0
- data/lib/vedeu/cursor/toggle_cursor.rb +53 -0
- data/lib/vedeu/dsl/all.rb +28 -0
- data/lib/vedeu/dsl/components/all.rb +7 -0
- data/lib/vedeu/dsl/components/border.rb +104 -0
- data/lib/vedeu/dsl/components/geometry.rb +153 -0
- data/lib/vedeu/dsl/components/keymap.rb +93 -0
- data/lib/vedeu/dsl/components/menu.rb +82 -0
- data/lib/vedeu/dsl/composition.rb +72 -0
- data/lib/vedeu/dsl/interface.rb +210 -0
- data/lib/vedeu/dsl/line.rb +135 -0
- data/lib/vedeu/dsl/shared/all.rb +7 -0
- data/lib/vedeu/dsl/shared/colour.rb +85 -0
- data/lib/vedeu/dsl/shared/style.rb +38 -0
- data/lib/vedeu/dsl/shared/text.rb +102 -0
- data/lib/vedeu/dsl/shared/use.rb +47 -0
- data/lib/vedeu/dsl/stream.rb +49 -0
- data/lib/vedeu/dsl/view.rb +136 -0
- data/lib/vedeu/events/all.rb +10 -0
- data/lib/vedeu/{repositories/models → events}/event.rb +97 -8
- data/lib/vedeu/events/trigger.rb +58 -0
- data/lib/vedeu/exceptions.rb +34 -0
- data/lib/vedeu/input/all.rb +29 -0
- data/lib/vedeu/input/input.rb +26 -0
- data/lib/vedeu/{models → input}/key.rb +21 -11
- data/lib/vedeu/input/keymap.rb +130 -0
- data/lib/vedeu/input/keys.rb +8 -0
- data/lib/vedeu/input/mapper.rb +112 -0
- data/lib/vedeu/launcher.rb +7 -4
- data/lib/vedeu/models/all.rb +12 -0
- data/lib/vedeu/models/collection.rb +71 -0
- data/lib/vedeu/{repositories → models}/focus.rb +63 -21
- data/lib/vedeu/models/geometry.rb +100 -259
- data/lib/vedeu/{repositories/models → models}/group.rb +16 -14
- data/lib/vedeu/{repositories/models → models}/menu.rb +85 -22
- data/lib/vedeu/models/model.rb +51 -0
- data/lib/vedeu/models/view/all.rb +12 -0
- data/lib/vedeu/models/view/char.rb +84 -0
- data/lib/vedeu/models/view/chars.rb +8 -0
- data/lib/vedeu/models/view/composition.rb +101 -0
- data/lib/vedeu/models/view/interface.rb +215 -0
- data/lib/vedeu/models/view/interfaces.rb +8 -0
- data/lib/vedeu/models/view/line.rb +134 -0
- data/lib/vedeu/models/view/lines.rb +8 -0
- data/lib/vedeu/models/view/stream.rb +144 -0
- data/lib/vedeu/models/view/streams.rb +8 -0
- data/lib/vedeu/output/all.rb +8 -0
- data/lib/vedeu/output/border.rb +387 -0
- data/lib/vedeu/output/compositor.rb +41 -30
- data/lib/vedeu/output/output.rb +6 -13
- data/lib/vedeu/output/viewport.rb +78 -94
- data/lib/vedeu/output/writer.rb +29 -0
- data/lib/vedeu/presentation/all.rb +9 -0
- data/lib/vedeu/{colours → presentation}/background.rb +1 -9
- data/lib/vedeu/{colours → presentation}/colour.rb +21 -8
- data/lib/vedeu/{colours → presentation}/foreground.rb +5 -9
- data/lib/vedeu/presentation/presentation.rb +91 -0
- data/lib/vedeu/presentation/style.rb +47 -0
- data/lib/vedeu/{colours → presentation}/translator.rb +11 -5
- data/lib/vedeu/repositories/all.rb +5 -0
- data/lib/vedeu/repositories/menus.rb +5 -42
- data/lib/vedeu/{support → repositories}/repository.rb +78 -41
- data/lib/vedeu/support/all.rb +22 -0
- data/lib/vedeu/support/bounding_area.rb +2 -1
- data/lib/vedeu/support/coercions.rb +18 -1
- data/lib/vedeu/support/console.rb +73 -0
- data/lib/vedeu/support/content_geometry.rb +69 -0
- data/lib/vedeu/support/coordinate.rb +246 -0
- data/lib/vedeu/support/esc.rb +29 -2
- data/lib/vedeu/support/log.rb +36 -2
- data/lib/vedeu/support/node.rb +61 -0
- data/lib/vedeu/support/position.rb +28 -13
- data/lib/vedeu/support/position_validator.rb +79 -0
- data/lib/vedeu/support/read.rb +65 -0
- data/lib/vedeu/support/refresh.rb +8 -32
- data/lib/vedeu/support/terminal.rb +34 -4
- data/lib/vedeu/support/text.rb +104 -0
- data/lib/vedeu/support/trace.rb +11 -23
- data/lib/vedeu/support/visible.rb +75 -0
- data/lib/vedeu/support/write.rb +85 -0
- data/lib/vedeu/traps.rb +18 -0
- data/lib/vedeu.rb +41 -101
- data/test/integration/dsl/compositions_test.rb +27 -0
- data/test/integration/dsl/interfaces_test.rb +261 -0
- data/test/integration/dsl/keymaps_test.rb +42 -0
- data/test/integration/dsl/lines_test.rb +146 -0
- data/test/integration/dsl/menus_test.rb +59 -0
- data/test/integration/dsl/streams_test.rb +129 -0
- data/test/integration/dsl/views_test.rb +63 -0
- data/test/lib/vedeu/api_test.rb +163 -0
- data/test/lib/vedeu/application_test.rb +19 -10
- data/test/lib/vedeu/bindings_test.rb +54 -0
- data/test/lib/vedeu/buffers/all_test.rb +11 -0
- data/test/lib/vedeu/buffers/buffer_test.rb +196 -0
- data/test/lib/vedeu/buffers/display_buffer_test.rb +58 -0
- data/test/lib/vedeu/configuration/api_test.rb +42 -58
- data/test/lib/vedeu/configuration/cli_test.rb +4 -4
- data/test/lib/vedeu/configuration/configuration_test.rb +11 -29
- data/test/lib/vedeu/cursor/all_test.rb +33 -0
- data/test/lib/vedeu/cursor/cursor_test.rb +85 -0
- data/test/lib/vedeu/cursor/move_cursor_test.rb +212 -0
- data/test/lib/vedeu/cursor/toggle_cursor_test.rb +63 -0
- data/test/lib/vedeu/dsl/components/border_test.rb +414 -0
- data/test/lib/vedeu/dsl/components/geometry_test.rb +231 -0
- data/test/lib/vedeu/dsl/components/keymap_test.rb +80 -0
- data/test/lib/vedeu/dsl/components/menu_test.rb +115 -0
- data/test/lib/vedeu/dsl/composition_test.rb +41 -0
- data/test/lib/vedeu/dsl/interface_test.rb +470 -0
- data/test/lib/vedeu/dsl/line_test.rb +60 -0
- data/test/lib/vedeu/dsl/shared/colour_test.rb +100 -0
- data/test/lib/vedeu/dsl/shared/style_test.rb +22 -0
- data/test/lib/vedeu/dsl/shared/text_test.rb +15 -0
- data/test/lib/vedeu/dsl/shared/use_test.rb +27 -0
- data/test/lib/vedeu/dsl/stream_test.rb +26 -0
- data/test/lib/vedeu/dsl/view_test.rb +73 -0
- data/test/lib/vedeu/events/all_test.rb +11 -0
- data/test/lib/vedeu/events/event_test.rb +109 -0
- data/test/lib/vedeu/events/trigger_test.rb +60 -0
- data/test/lib/vedeu/input/all_test.rb +11 -0
- data/test/lib/vedeu/input/input_test.rb +7 -3
- data/test/lib/vedeu/input/key_test.rb +72 -0
- data/test/lib/vedeu/input/keymap_test.rb +89 -0
- data/test/lib/vedeu/input/mapper_test.rb +94 -0
- data/test/lib/vedeu/launcher_test.rb +19 -20
- data/test/lib/vedeu/models/collection_test.rb +114 -0
- data/test/lib/vedeu/{repositories → models}/focus_test.rb +46 -13
- data/test/lib/vedeu/models/geometry_test.rb +35 -39
- data/test/lib/vedeu/models/group_test.rb +100 -0
- data/test/lib/vedeu/models/menu_test.rb +288 -0
- data/test/lib/vedeu/models/model_test.rb +31 -0
- data/test/lib/vedeu/models/view/char_test.rb +166 -0
- data/test/lib/vedeu/models/view/chars_test.rb +18 -0
- data/test/lib/vedeu/models/view/composition_test.rb +41 -0
- data/test/lib/vedeu/models/view/interface_test.rb +128 -0
- data/test/lib/vedeu/models/view/interfaces_test.rb +18 -0
- data/test/lib/vedeu/models/view/line_test.rb +214 -0
- data/test/lib/vedeu/models/view/lines_test.rb +18 -0
- data/test/lib/vedeu/models/view/stream_test.rb +106 -0
- data/test/lib/vedeu/models/view/streams_test.rb +18 -0
- data/test/lib/vedeu/output/border_test.rb +357 -0
- data/test/lib/vedeu/output/compositor_test.rb +61 -15
- data/test/lib/vedeu/output/output_test.rb +25 -84
- data/test/lib/vedeu/output/viewport_test.rb +171 -45
- data/test/lib/vedeu/output/writer_test.rb +45 -0
- data/test/lib/vedeu/{colours → presentation}/background_test.rb +0 -0
- data/test/lib/vedeu/{colours → presentation}/colour_test.rb +5 -5
- data/test/lib/vedeu/{colours → presentation}/foreground_test.rb +0 -0
- data/test/lib/vedeu/presentation/presentation_test.rb +56 -0
- data/test/lib/vedeu/presentation/style_test.rb +69 -0
- data/test/lib/vedeu/presentation/translator_test.rb +63 -0
- data/test/lib/vedeu/repositories/all_test.rb +7 -0
- data/test/lib/vedeu/repositories/menus_test.rb +3 -156
- data/test/lib/vedeu/repositories/repository_test.rb +271 -0
- data/test/lib/vedeu/support/bounding_area_test.rb +3 -3
- data/test/lib/vedeu/support/coercions_test.rb +39 -0
- data/test/lib/vedeu/support/common_test.rb +31 -16
- data/test/lib/vedeu/support/console_test.rb +85 -0
- data/test/lib/vedeu/support/content_geometry_test.rb +107 -0
- data/test/lib/vedeu/support/coordinate_test.rb +190 -0
- data/test/lib/vedeu/support/esc_test.rb +18 -0
- data/test/lib/vedeu/support/grid_test.rb +15 -10
- data/test/lib/vedeu/support/log_test.rb +3 -0
- data/test/lib/vedeu/support/position_test.rb +22 -2
- data/test/lib/vedeu/support/position_validator_test.rb +11 -0
- data/test/lib/vedeu/support/read_test.rb +88 -0
- data/test/lib/vedeu/support/refresh_test.rb +44 -12
- data/test/lib/vedeu/support/sentence_test.rb +6 -4
- data/test/lib/vedeu/support/terminal_test.rb +81 -70
- data/test/lib/vedeu/support/text_test.rb +93 -0
- data/test/lib/vedeu/support/trace_test.rb +21 -9
- data/test/lib/vedeu/support/visible_test.rb +148 -0
- data/test/lib/vedeu/support/write_test.rb +136 -0
- data/test/lib/vedeu/traps_test.rb +11 -0
- data/test/lib/vedeu_test.rb +2 -0
- data/test/support/helpers/all.rb +7 -0
- data/test/support/helpers/dsl_model_test_class.rb +25 -0
- data/test/support/{test_classes → helpers}/helpers.rb +0 -2
- data/test/support/helpers/misc.rb +15 -0
- data/test/support/helpers/model_test_class.rb +34 -0
- data/test/support/{test_classes → helpers}/presentation.rb +0 -0
- data/test/support/{test_classes → helpers}/repositories.rb +3 -3
- data/test/support/{test_modules/repository.rb → helpers/repository_test_module.rb} +5 -1
- data/test/test_helper.rb +19 -22
- data/vedeu.gemspec +11 -6
- metadata +322 -181
- data/lib/vedeu/api/api.rb +0 -239
- data/lib/vedeu/api/composition.rb +0 -38
- data/lib/vedeu/api/defined.rb +0 -52
- data/lib/vedeu/api/helpers.rb +0 -161
- data/lib/vedeu/api/interface.rb +0 -287
- data/lib/vedeu/api/keymap.rb +0 -75
- data/lib/vedeu/api/line.rb +0 -107
- data/lib/vedeu/api/menu.rb +0 -111
- data/lib/vedeu/api/stream.rb +0 -96
- data/lib/vedeu/models/border.rb +0 -238
- data/lib/vedeu/models/char.rb +0 -43
- data/lib/vedeu/models/composition.rb +0 -72
- data/lib/vedeu/models/line.rb +0 -100
- data/lib/vedeu/models/stream.rb +0 -130
- data/lib/vedeu/models/style.rb +0 -52
- data/lib/vedeu/repositories/buffers.rb +0 -52
- data/lib/vedeu/repositories/cursors.rb +0 -64
- data/lib/vedeu/repositories/events.rb +0 -147
- data/lib/vedeu/repositories/groups.rb +0 -47
- data/lib/vedeu/repositories/interfaces.rb +0 -78
- data/lib/vedeu/repositories/keymaps.rb +0 -196
- data/lib/vedeu/repositories/models/cursor.rb +0 -209
- data/lib/vedeu/repositories/models/interface.rb +0 -163
- data/lib/vedeu/repositories/models/keymap.rb +0 -111
- data/lib/vedeu/repositories/models/offset.rb +0 -91
- data/lib/vedeu/repositories/offsets.rb +0 -69
- data/lib/vedeu/support/exceptions.rb +0 -34
- data/lib/vedeu/support/keymap_validator.rb +0 -100
- data/lib/vedeu/support/model.rb +0 -14
- data/lib/vedeu/support/presentation.rb +0 -86
- data/lib/vedeu/support/registrar.rb +0 -53
- data/test/integration/api/api_test.rb +0 -97
- data/test/integration/api_dsl/dsl_api_test.rb +0 -4
- data/test/integration/api_dsl/dsl_composition_test.rb +0 -4
- data/test/integration/api_dsl/dsl_defined_test.rb +0 -4
- data/test/integration/api_dsl/dsl_helpers_test.rb +0 -4
- data/test/integration/api_dsl/dsl_interface_test.rb +0 -4
- data/test/integration/api_dsl/dsl_keymap.rb +0 -4
- data/test/integration/api_dsl/dsl_line_test.rb +0 -4
- data/test/integration/api_dsl/dsl_menu_test.rb +0 -4
- data/test/integration/api_dsl/dsl_stream_test.rb +0 -138
- data/test/integration/cursors_test.rb +0 -9
- data/test/integration/defining_interfaces_test.rb +0 -26
- data/test/integration/run_once_test.rb +0 -26
- data/test/integration/views/basic_view_test.rb +0 -807
- data/test/lib/vedeu/api/api_test.rb +0 -204
- data/test/lib/vedeu/api/composition_test.rb +0 -31
- data/test/lib/vedeu/api/defined_test.rb +0 -79
- data/test/lib/vedeu/api/helpers_test.rb +0 -111
- data/test/lib/vedeu/api/interface_test.rb +0 -410
- data/test/lib/vedeu/api/keymap_test.rb +0 -65
- data/test/lib/vedeu/api/line_test.rb +0 -83
- data/test/lib/vedeu/api/menu_test.rb +0 -85
- data/test/lib/vedeu/api/stream_test.rb +0 -59
- data/test/lib/vedeu/colours/translator_test.rb +0 -22
- data/test/lib/vedeu/models/border_test.rb +0 -197
- data/test/lib/vedeu/models/char_test.rb +0 -52
- data/test/lib/vedeu/models/composition_test.rb +0 -45
- data/test/lib/vedeu/models/key_test.rb +0 -43
- data/test/lib/vedeu/models/line_test.rb +0 -123
- data/test/lib/vedeu/models/stream_test.rb +0 -233
- data/test/lib/vedeu/models/style_test.rb +0 -59
- data/test/lib/vedeu/repositories/buffers_test.rb +0 -37
- data/test/lib/vedeu/repositories/cursors_test.rb +0 -62
- data/test/lib/vedeu/repositories/events_test.rb +0 -57
- data/test/lib/vedeu/repositories/groups_test.rb +0 -28
- data/test/lib/vedeu/repositories/interfaces_test.rb +0 -51
- data/test/lib/vedeu/repositories/keymaps_test.rb +0 -223
- data/test/lib/vedeu/repositories/models/buffer_test.rb +0 -174
- data/test/lib/vedeu/repositories/models/cursor_test.rb +0 -158
- data/test/lib/vedeu/repositories/models/event_test.rb +0 -53
- data/test/lib/vedeu/repositories/models/group_test.rb +0 -98
- data/test/lib/vedeu/repositories/models/interface_test.rb +0 -130
- data/test/lib/vedeu/repositories/models/keymap_test.rb +0 -27
- data/test/lib/vedeu/repositories/models/menu_test.rb +0 -246
- data/test/lib/vedeu/repositories/models/offset_test.rb +0 -128
- data/test/lib/vedeu/repositories/offsets_test.rb +0 -39
- data/test/lib/vedeu/support/keymap_validator_test.rb +0 -62
- data/test/lib/vedeu/support/model_test.rb +0 -23
- data/test/lib/vedeu/support/presentation_test.rb +0 -53
- data/test/lib/vedeu/support/registrar_test.rb +0 -94
- data/test/lib/vedeu/support/repository_test.rb +0 -208
- data/test/support/test_classes/all.rb +0 -5
- data/test/support/test_classes/coercions.rb +0 -16
- data/test/support/test_classes/model.rb +0 -23
- data/test/support/test_modules/all.rb +0 -1
data/lib/vedeu/api/interface.rb
DELETED
@@ -1,287 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module API
|
4
|
-
|
5
|
-
# Provides methods to be used to define interfaces or views.
|
6
|
-
#
|
7
|
-
# @api public
|
8
|
-
class Interface < Vedeu::Interface
|
9
|
-
|
10
|
-
include Helpers
|
11
|
-
|
12
|
-
# Allows the setting of a border for the interface. Via the `values`
|
13
|
-
# parameter, the various characters for the borders sides and corners can
|
14
|
-
# be set, a custom foreground and background, a custom style, and whether
|
15
|
-
# a particular side should be drawn or not. See {Border#initialize} for
|
16
|
-
# more details.
|
17
|
-
#
|
18
|
-
# @return [Hash]
|
19
|
-
def border(values = {})
|
20
|
-
auto_enable = { enabled: true }
|
21
|
-
attributes[:border] = auto_enable.merge(values)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Instructs Vedeu to calculate x and y geometry automatically based on the
|
25
|
-
# centre character of the terminal, the width and the height.
|
26
|
-
#
|
27
|
-
# @param value [Boolean] Any value other than nil or false will evaluate
|
28
|
-
# to true.
|
29
|
-
#
|
30
|
-
# @example
|
31
|
-
# interface 'my_interface' do
|
32
|
-
# centred!
|
33
|
-
#
|
34
|
-
# interface 'my_interface' do
|
35
|
-
# centred false
|
36
|
-
# ...
|
37
|
-
#
|
38
|
-
# @return [Boolean]
|
39
|
-
def centred(value = true)
|
40
|
-
attributes[:geometry][:centred] = !!(value)
|
41
|
-
end
|
42
|
-
alias_method :centred!, :centred
|
43
|
-
|
44
|
-
# Set the cursor visibility on an interface.
|
45
|
-
#
|
46
|
-
# @param value [Boolean] Any value other than nil or false will evaluate
|
47
|
-
# to true.
|
48
|
-
#
|
49
|
-
# @example
|
50
|
-
# interface 'my_interface' do
|
51
|
-
# cursor true
|
52
|
-
# ...
|
53
|
-
#
|
54
|
-
# view 'my_interface' do
|
55
|
-
# cursor true
|
56
|
-
# ...
|
57
|
-
#
|
58
|
-
# @return [Symbol]
|
59
|
-
def cursor(value = true)
|
60
|
-
attributes[:cursor] = if !!value
|
61
|
-
:show
|
62
|
-
|
63
|
-
else
|
64
|
-
:hide
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# To maintain performance interfaces can be delayed from refreshing too
|
70
|
-
# often, the reduces artefacts particularly when resizing the terminal
|
71
|
-
# screen.
|
72
|
-
#
|
73
|
-
# @param value [Fixnum|Float]
|
74
|
-
#
|
75
|
-
# @example
|
76
|
-
# interface 'my_interface' do
|
77
|
-
# delay 0.5 # interface will not update more often than every 500ms.
|
78
|
-
# ...
|
79
|
-
#
|
80
|
-
# @return [Fixnum|Float]
|
81
|
-
def delay(value)
|
82
|
-
attributes[:delay] = value
|
83
|
-
end
|
84
|
-
|
85
|
-
# Specify this interface as being in focus when the application starts.
|
86
|
-
# If multiple interfaces are defined, and this is included in each, then
|
87
|
-
# the last defined will be the interface in focus.
|
88
|
-
#
|
89
|
-
# @return [String] The name of the interface in focus.
|
90
|
-
def focus!
|
91
|
-
attributes[:focus] = true
|
92
|
-
end
|
93
|
-
|
94
|
-
# Specify a group for an interface. Interfaces of the same group can be
|
95
|
-
# targetted together; for example you may want to refresh multiple
|
96
|
-
# interfaces at once.
|
97
|
-
#
|
98
|
-
# @param value [String]
|
99
|
-
#
|
100
|
-
# @example
|
101
|
-
# interface 'my_interface' do
|
102
|
-
# group 'main_screen'
|
103
|
-
# ...
|
104
|
-
#
|
105
|
-
# @return [String]
|
106
|
-
def group(value)
|
107
|
-
attributes[:group] = value
|
108
|
-
end
|
109
|
-
|
110
|
-
# Specify the number of characters/rows/lines tall the interface will be.
|
111
|
-
#
|
112
|
-
# @param value [Fixnum]
|
113
|
-
#
|
114
|
-
# @example
|
115
|
-
# interface 'my_interface' do
|
116
|
-
# height 8
|
117
|
-
# ...
|
118
|
-
#
|
119
|
-
# @return [Fixnum]
|
120
|
-
def height(value)
|
121
|
-
Vedeu.log(out_of_bounds('height')) if y_out_of_bounds?(value)
|
122
|
-
|
123
|
-
attributes[:geometry][:height] = value
|
124
|
-
end
|
125
|
-
|
126
|
-
# @see Vedeu::API#keys
|
127
|
-
def keys(&block)
|
128
|
-
Keymap.keys(attributes[:name], &block)
|
129
|
-
end
|
130
|
-
|
131
|
-
# Specify a single line in a view.
|
132
|
-
#
|
133
|
-
# @param value [String]
|
134
|
-
# @param block [Proc]
|
135
|
-
#
|
136
|
-
# @example
|
137
|
-
# view 'my_interface' do
|
138
|
-
# line 'This is a line of text...'
|
139
|
-
# line 'and so is this...'
|
140
|
-
# ...
|
141
|
-
#
|
142
|
-
# view 'my_interface' do
|
143
|
-
# line do
|
144
|
-
# ... see {API::Line} and {API::Stream}
|
145
|
-
# end
|
146
|
-
# end
|
147
|
-
#
|
148
|
-
# @return [API::Line]
|
149
|
-
def line(value = '', &block)
|
150
|
-
if block_given?
|
151
|
-
attributes[:lines] << API::Line
|
152
|
-
.build({ parent: self.view_attributes }, &block)
|
153
|
-
|
154
|
-
else
|
155
|
-
attributes[:lines] << API::Line
|
156
|
-
.build({ streams: { text: value }, parent: self.view_attributes })
|
157
|
-
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
# The name of the interface. Used to reference the interface throughout
|
162
|
-
# your application's execution lifetime.
|
163
|
-
#
|
164
|
-
# @param value [String]
|
165
|
-
#
|
166
|
-
# @example
|
167
|
-
# interface do
|
168
|
-
# name 'my_interface'
|
169
|
-
# ...
|
170
|
-
#
|
171
|
-
# @return [String]
|
172
|
-
def name(value)
|
173
|
-
attributes[:name] = value
|
174
|
-
end
|
175
|
-
|
176
|
-
# Use the specified interface; useful for sharing attributes with other
|
177
|
-
# interfaces. Any public method of #{Vedeu::Interface} is available.
|
178
|
-
#
|
179
|
-
# @example
|
180
|
-
# interface 'my_interface' do
|
181
|
-
# use('my_other_interface').width # use the width of another interface
|
182
|
-
# ...
|
183
|
-
#
|
184
|
-
# Vedeu.use('my_other_interface').width # can be used in your code to
|
185
|
-
# # get this value
|
186
|
-
#
|
187
|
-
# @param value [String]
|
188
|
-
# @see Vedeu::API#use
|
189
|
-
def use(value)
|
190
|
-
Vedeu.use(value)
|
191
|
-
end
|
192
|
-
|
193
|
-
# Specify the number of characters/columns wide the interface will be.
|
194
|
-
#
|
195
|
-
# @param value [Fixnum]
|
196
|
-
#
|
197
|
-
# @example
|
198
|
-
# interface 'my_interface' do
|
199
|
-
# width 25
|
200
|
-
# ...
|
201
|
-
#
|
202
|
-
# @return [Fixnum]
|
203
|
-
def width(value)
|
204
|
-
Vedeu.log(out_of_bounds('width')) if x_out_of_bounds?(value)
|
205
|
-
|
206
|
-
attributes[:geometry][:width] = value
|
207
|
-
end
|
208
|
-
|
209
|
-
# Specify the starting x position (column) of the interface.
|
210
|
-
#
|
211
|
-
# @param value [Fixnum]
|
212
|
-
# @param block [Proc]
|
213
|
-
#
|
214
|
-
# @example
|
215
|
-
# interface 'my_interface' do
|
216
|
-
# x 7 # start on column 7.
|
217
|
-
#
|
218
|
-
# interface 'other_interface' do
|
219
|
-
# x { use('my_interface').east } # start on column 8, if
|
220
|
-
# # `my_interface` changes position,
|
221
|
-
# # `other_interface` will too.
|
222
|
-
#
|
223
|
-
# @return [Fixnum]
|
224
|
-
def x(value = 0, &block)
|
225
|
-
return attributes[:geometry][:x] = block if block_given?
|
226
|
-
|
227
|
-
Vedeu.log(out_of_bounds('x')) if x_out_of_bounds?(value)
|
228
|
-
|
229
|
-
attributes[:geometry][:x] = value
|
230
|
-
end
|
231
|
-
|
232
|
-
# Specify the starting y position (row/line) of the interface.
|
233
|
-
#
|
234
|
-
# @param value [Fixnum]
|
235
|
-
# @param block [Proc]
|
236
|
-
#
|
237
|
-
# @example
|
238
|
-
# interface 'my_interface' do
|
239
|
-
# y 4
|
240
|
-
# ...
|
241
|
-
#
|
242
|
-
# interface 'other_interface' do
|
243
|
-
# y { use('my_interface').north } # start on row/line 3, if
|
244
|
-
# ... # `my_interface` changes position,
|
245
|
-
# # `other_interface` will too.
|
246
|
-
#
|
247
|
-
# @return [Fixnum]
|
248
|
-
def y(value = 0, &block)
|
249
|
-
return attributes[:geometry][:y] = block if block_given?
|
250
|
-
|
251
|
-
Vedeu.log(out_of_bounds('y')) if y_out_of_bounds?(value)
|
252
|
-
|
253
|
-
attributes[:geometry][:y] = value
|
254
|
-
end
|
255
|
-
|
256
|
-
private
|
257
|
-
|
258
|
-
# Returns the out of bounds error message for the given named attribute.
|
259
|
-
#
|
260
|
-
# @param name [String]
|
261
|
-
# @return [String]
|
262
|
-
def out_of_bounds(name)
|
263
|
-
"Note: For this terminal, the value of '#{name}' may lead to content " \
|
264
|
-
"that is outside the viewable area."
|
265
|
-
end
|
266
|
-
|
267
|
-
# Checks the value is within the terminal's confines.
|
268
|
-
#
|
269
|
-
# @param value [Fixnum]
|
270
|
-
# @return [Boolean]
|
271
|
-
def y_out_of_bounds?(value)
|
272
|
-
value < 1 || value > Terminal.height
|
273
|
-
end
|
274
|
-
|
275
|
-
# Checks the value is within the terminal's confines.
|
276
|
-
#
|
277
|
-
# @param value [Fixnum]
|
278
|
-
# @return [Boolean]
|
279
|
-
def x_out_of_bounds?(value)
|
280
|
-
value < 1 || value > Terminal.width
|
281
|
-
end
|
282
|
-
|
283
|
-
end # Interface
|
284
|
-
|
285
|
-
end # API
|
286
|
-
|
287
|
-
end # Vedeu
|
data/lib/vedeu/api/keymap.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module API
|
4
|
-
|
5
|
-
# Provides methods to be used to define keypress mapped to actions.
|
6
|
-
#
|
7
|
-
# @api public
|
8
|
-
class Keymap < Vedeu::Keymap
|
9
|
-
|
10
|
-
# Define keypress(es) to perform an action.
|
11
|
-
#
|
12
|
-
# @param value_or_values [String|Symbol] The key(s) pressed. Special keys
|
13
|
-
# can be found in {Vedeu::Input#specials}. When more than one key is
|
14
|
-
# defined, then the extras are treated as aliases.
|
15
|
-
# @param block [Proc] The action to perform when this key is pressed. Can
|
16
|
-
# be a method call or event triggered.
|
17
|
-
#
|
18
|
-
# @example
|
19
|
-
# keys do
|
20
|
-
# key('s') { trigger(:save) }
|
21
|
-
# key('h', :left) { trigger(:left) }
|
22
|
-
# key('j', :down) { trigger(:down) }
|
23
|
-
# ...
|
24
|
-
#
|
25
|
-
# @raise [InvalidSyntax] When the required block is not given, the
|
26
|
-
# value_or_values parameter is undefined, or when processing the
|
27
|
-
# collection, a member is undefined.
|
28
|
-
# @return [Array] A collection containing the keypress(es).
|
29
|
-
def key(*value_or_values, &block)
|
30
|
-
fail InvalidSyntax,
|
31
|
-
'No action defined for `key`.' unless block_given?
|
32
|
-
fail InvalidSyntax, 'No keypress(es) defined for `key`.' unless
|
33
|
-
defined_value?(value_or_values)
|
34
|
-
|
35
|
-
value_or_values.each do |value|
|
36
|
-
fail InvalidSyntax,
|
37
|
-
'An invalid value for `key` was encountered.' unless
|
38
|
-
defined_value?(value)
|
39
|
-
|
40
|
-
attributes[:keys] << { key: value, action: block }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# The interface(s) which will handle these keys.
|
45
|
-
#
|
46
|
-
# @param name_or_names [String] The name or names of the interface(s)
|
47
|
-
# which will handle these keys.
|
48
|
-
#
|
49
|
-
# @example
|
50
|
-
# keys do
|
51
|
-
# interface 'my_interface'
|
52
|
-
# key('s') { :something }
|
53
|
-
# name 'my_keymap'
|
54
|
-
# ...
|
55
|
-
#
|
56
|
-
# keys do
|
57
|
-
# interface('main', 'other')
|
58
|
-
# key('s') { :something }
|
59
|
-
# ...
|
60
|
-
#
|
61
|
-
# keys do
|
62
|
-
# interfaces('main', 'other')
|
63
|
-
# ...
|
64
|
-
#
|
65
|
-
# @return [Array]
|
66
|
-
def interface(*name_or_names)
|
67
|
-
attributes[:interfaces] = name_or_names
|
68
|
-
end
|
69
|
-
alias_method :interfaces, :interface
|
70
|
-
|
71
|
-
end # Keymap
|
72
|
-
|
73
|
-
end # API
|
74
|
-
|
75
|
-
end # Vedeu
|
data/lib/vedeu/api/line.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module API
|
4
|
-
|
5
|
-
# Provides methods to be used to define views.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# line do
|
9
|
-
#
|
10
|
-
# background '#ffffff'
|
11
|
-
#
|
12
|
-
# colour background: '#222222', foreground: '#ff0000'
|
13
|
-
#
|
14
|
-
# foreground '#000000'
|
15
|
-
#
|
16
|
-
# stream do
|
17
|
-
# # see {API::Stream} for directives
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# style 'normal' # or a collection: ['bold', 'underline']
|
21
|
-
#
|
22
|
-
# text 'Some text...'
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# @api public
|
26
|
-
class Line < Vedeu::Line
|
27
|
-
|
28
|
-
include Helpers
|
29
|
-
|
30
|
-
# @param value [String]
|
31
|
-
# @param block [Proc]
|
32
|
-
#
|
33
|
-
# @example
|
34
|
-
# ...
|
35
|
-
# line do
|
36
|
-
# background '#0022ff' do
|
37
|
-
# ... other stream directives ...
|
38
|
-
#
|
39
|
-
# @return [Array]
|
40
|
-
def background(value = '', &block)
|
41
|
-
stream = API::Stream.build({ colour: { background: value },
|
42
|
-
parent: self.view_attributes }, &block)
|
43
|
-
|
44
|
-
attributes[:streams] << stream
|
45
|
-
end
|
46
|
-
|
47
|
-
# @param value [String]
|
48
|
-
# @param block [Proc]
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# ...
|
52
|
-
# line do
|
53
|
-
# foreground '#00ff00' do
|
54
|
-
# ... other stream directives ...
|
55
|
-
#
|
56
|
-
# @return [Array]
|
57
|
-
def foreground(value = '', &block)
|
58
|
-
stream = API::Stream.build({ colour: { foreground: value },
|
59
|
-
parent: self.view_attributes }, &block)
|
60
|
-
|
61
|
-
attributes[:streams] << stream
|
62
|
-
end
|
63
|
-
|
64
|
-
# Define a stream (a subset of a line).
|
65
|
-
#
|
66
|
-
# @param block [Proc] Block contains directives relating to API::Stream.
|
67
|
-
#
|
68
|
-
# @example
|
69
|
-
# ...
|
70
|
-
# line do
|
71
|
-
# stream do
|
72
|
-
# ...
|
73
|
-
#
|
74
|
-
# @raise [InvalidSyntax] When the required block is not given.
|
75
|
-
# @return [Array]
|
76
|
-
def stream(&block)
|
77
|
-
fail InvalidSyntax, '`stream` requires a block.' unless block_given?
|
78
|
-
|
79
|
-
attributes[:streams] << API::Stream
|
80
|
-
.build({ parent: self.view_attributes }, &block)
|
81
|
-
end
|
82
|
-
|
83
|
-
# Define text for a line. Using this directive will not allow stream
|
84
|
-
# attributes for this line but is useful for adding lines straight into
|
85
|
-
# the interface.
|
86
|
-
#
|
87
|
-
# @param value [String]
|
88
|
-
#
|
89
|
-
# @example
|
90
|
-
# ...
|
91
|
-
# line do
|
92
|
-
# text 'Some text goes here...'
|
93
|
-
#
|
94
|
-
# ...
|
95
|
-
# stream do
|
96
|
-
# text 'Some text goes here...'
|
97
|
-
#
|
98
|
-
# @return [Array]
|
99
|
-
def text(value)
|
100
|
-
attributes[:streams] << { text: value }
|
101
|
-
end
|
102
|
-
|
103
|
-
end # Line
|
104
|
-
|
105
|
-
end # API
|
106
|
-
|
107
|
-
end # Vedeu
|
data/lib/vedeu/api/menu.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module API
|
4
|
-
|
5
|
-
# Provides the mechanism to create menus within client applications and use
|
6
|
-
# events to drive them.
|
7
|
-
#
|
8
|
-
# @api public
|
9
|
-
class Menu
|
10
|
-
|
11
|
-
include Common
|
12
|
-
|
13
|
-
attr_reader :attributes
|
14
|
-
|
15
|
-
# Define a new Menu.
|
16
|
-
#
|
17
|
-
# @param attributes [Hash]
|
18
|
-
# @param block [Proc]
|
19
|
-
# @return [API::Menu]
|
20
|
-
def self.define(attributes = {}, &block)
|
21
|
-
new(attributes).define(&block)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Return a new instance of Menu.
|
25
|
-
#
|
26
|
-
# @param attributes [Hash]
|
27
|
-
# @return [API::Menu]
|
28
|
-
def initialize(attributes = {})
|
29
|
-
@attributes = defaults.merge(attributes)
|
30
|
-
end
|
31
|
-
|
32
|
-
# @param block [Proc]
|
33
|
-
# @raise [InvalidSyntax] When the required block is not given.
|
34
|
-
# @return [API::Menu]
|
35
|
-
def define(&block)
|
36
|
-
fail InvalidSyntax, '`menu` requires a block.' unless block_given?
|
37
|
-
|
38
|
-
@self_before_instance_eval = eval('self', block.binding)
|
39
|
-
|
40
|
-
instance_eval(&block)
|
41
|
-
|
42
|
-
Vedeu::Menus.add(attributes)
|
43
|
-
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
# Define the items for the menu. Most powerful when used with one of your
|
48
|
-
# model classes.
|
49
|
-
#
|
50
|
-
# In the 'my_playlist' example below, your `Track` model may return a
|
51
|
-
# collection of tracks to populate the menu.
|
52
|
-
#
|
53
|
-
# @param collection [Array]
|
54
|
-
#
|
55
|
-
# @example
|
56
|
-
# menu 'my_menu' do
|
57
|
-
# items [:item_1, :item_2, :item_3]
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# menu 'my_playlist' do
|
61
|
-
# items Track.all_my_favourites
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# @return [Vedeu::Menu]
|
65
|
-
def items(collection = [])
|
66
|
-
attributes[:items] = collection
|
67
|
-
end
|
68
|
-
|
69
|
-
# The name of the menu. Used to reference the menu throughout your
|
70
|
-
# application's execution lifetime.
|
71
|
-
#
|
72
|
-
# @param value [String]
|
73
|
-
#
|
74
|
-
# @example
|
75
|
-
# menu do
|
76
|
-
# name 'my_menu'
|
77
|
-
# ...
|
78
|
-
#
|
79
|
-
# @return [String]
|
80
|
-
def name(value)
|
81
|
-
attributes[:name] = value
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
# The default values for a new instance of Menu.
|
87
|
-
#
|
88
|
-
# @return [Hash]
|
89
|
-
def defaults
|
90
|
-
{
|
91
|
-
name: '',
|
92
|
-
items: []
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
# @param method [Symbol] The name of the method sought.
|
97
|
-
# @param args [Array] The arguments which the method was to be invoked
|
98
|
-
# with.
|
99
|
-
# @param block [Proc] The optional block provided to the method.
|
100
|
-
# @return []
|
101
|
-
def method_missing(method, *args, &block)
|
102
|
-
Vedeu.log("API::Menu#method_missing '#{method}' (args: #{args.inspect})")
|
103
|
-
|
104
|
-
@self_before_instance_eval.send(method, *args, &block) if @self_before_instance_eval
|
105
|
-
end
|
106
|
-
|
107
|
-
end # Menu
|
108
|
-
|
109
|
-
end # API
|
110
|
-
|
111
|
-
end # Vedeu
|
data/lib/vedeu/api/stream.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module API
|
4
|
-
|
5
|
-
# Provides methods to be used to define views.
|
6
|
-
#
|
7
|
-
# @api public
|
8
|
-
class Stream < Vedeu::Stream
|
9
|
-
|
10
|
-
include Helpers
|
11
|
-
|
12
|
-
# Specify the alignment of the stream within the line. Useful in
|
13
|
-
# combination with {#width} to provide simple formatting effects.
|
14
|
-
#
|
15
|
-
# @param value [Symbol] `:left`, `:centre` and `right` are valid values
|
16
|
-
# and will align accordingly. If not value is specified, the stream will
|
17
|
-
# left align.
|
18
|
-
#
|
19
|
-
# @example
|
20
|
-
# ...
|
21
|
-
# stream do
|
22
|
-
# align :right
|
23
|
-
# ...
|
24
|
-
#
|
25
|
-
# @raise [InvalidSyntax] When the value parameter is not one of +:left+,
|
26
|
-
# +:right+ or +:centre+.
|
27
|
-
# @return [Symbol]
|
28
|
-
def align(value)
|
29
|
-
unless [:left, :right, :centre].include?(value.to_sym)
|
30
|
-
fail InvalidSyntax, '`align` requires a value of `left`, `right` ' \
|
31
|
-
'or `centre`.'
|
32
|
-
end
|
33
|
-
|
34
|
-
attributes[:align] = value.to_sym
|
35
|
-
end
|
36
|
-
|
37
|
-
# Syntactic sugar used with {#align} to left align content.
|
38
|
-
#
|
39
|
-
# @return [Symbol]
|
40
|
-
def left
|
41
|
-
:left
|
42
|
-
end
|
43
|
-
|
44
|
-
# Syntactic sugar used with {#align} to right align content.
|
45
|
-
#
|
46
|
-
# @return [Symbol]
|
47
|
-
def right
|
48
|
-
:right
|
49
|
-
end
|
50
|
-
|
51
|
-
# Syntactic sugar used with {#align} to centre align content.
|
52
|
-
#
|
53
|
-
# @return [Symbol]
|
54
|
-
def centre
|
55
|
-
:centre
|
56
|
-
end
|
57
|
-
|
58
|
-
# Add textual data to the stream via this method.
|
59
|
-
#
|
60
|
-
# @param value [String] The text to be added to the stream. If the length
|
61
|
-
# of the text is greater than the interface's width, it will be
|
62
|
-
# truncated and ellipsized.
|
63
|
-
#
|
64
|
-
# @example
|
65
|
-
# ...
|
66
|
-
# stream do
|
67
|
-
# text 'Some text to display...'
|
68
|
-
# ...
|
69
|
-
#
|
70
|
-
# @return [String]
|
71
|
-
def text(value)
|
72
|
-
attributes[:text] = value
|
73
|
-
end
|
74
|
-
|
75
|
-
# Provides the ability to arbitrarily set the width of content for a
|
76
|
-
# stream. Useful in combination with #align to provide simple formatting
|
77
|
-
# effects.
|
78
|
-
#
|
79
|
-
# @param value [Fixnum] The width in characters.
|
80
|
-
#
|
81
|
-
# @example
|
82
|
-
# ...
|
83
|
-
# stream do
|
84
|
-
# width 20
|
85
|
-
# ...
|
86
|
-
#
|
87
|
-
# @return [Fixnum]
|
88
|
-
def width(value)
|
89
|
-
attributes[:width] = value
|
90
|
-
end
|
91
|
-
|
92
|
-
end # Stream
|
93
|
-
|
94
|
-
end # API
|
95
|
-
|
96
|
-
end # Vedeu
|