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
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'vedeu/cursor/cursor'
|
2
|
+
require 'vedeu/support/position_validator'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
|
6
|
+
# Adjusts the position of the cursor.
|
7
|
+
#
|
8
|
+
class MoveCursor
|
9
|
+
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
def_delegators :@interface, :border,
|
13
|
+
:border?,
|
14
|
+
:geometry
|
15
|
+
|
16
|
+
def_delegators :geometry, :left,
|
17
|
+
:top,
|
18
|
+
:height,
|
19
|
+
:width,
|
20
|
+
:x,
|
21
|
+
:y
|
22
|
+
|
23
|
+
# @param cursor [Cursor]
|
24
|
+
# @param interface [Interface]
|
25
|
+
# @param dy [Fixnum] Move up (-1), or down (1), or no action (0).
|
26
|
+
# @param dx [Fixnum] Move left (-1), or right (1), or no action (0).
|
27
|
+
# @return [MoveCursor]
|
28
|
+
def initialize(cursor, interface, dy, dx)
|
29
|
+
@cursor = cursor
|
30
|
+
@dy = dy
|
31
|
+
@dx = dx
|
32
|
+
@interface = interface
|
33
|
+
end
|
34
|
+
|
35
|
+
# Moves the cursor down by one row.
|
36
|
+
#
|
37
|
+
# @return [Cursor]
|
38
|
+
def self.down(cursor, interface)
|
39
|
+
new(cursor, interface, 1, 0).move
|
40
|
+
end
|
41
|
+
|
42
|
+
# Moves the cursor left by one column.
|
43
|
+
#
|
44
|
+
# @return [Cursor]
|
45
|
+
def self.left(cursor, interface)
|
46
|
+
return cursor unless cursor.ox > 0
|
47
|
+
|
48
|
+
new(cursor, interface, 0, -1).move
|
49
|
+
end
|
50
|
+
|
51
|
+
# Moves the cursor right by one column.
|
52
|
+
#
|
53
|
+
# @return [Cursor]
|
54
|
+
def self.right(cursor, interface)
|
55
|
+
new(cursor, interface, 0, 1).move
|
56
|
+
end
|
57
|
+
|
58
|
+
# Moves the cursor up by one row.
|
59
|
+
#
|
60
|
+
# @return [Cursor]
|
61
|
+
def self.up(cursor, interface)
|
62
|
+
return cursor unless cursor.oy > 0
|
63
|
+
|
64
|
+
new(cursor, interface, -1, 0).move
|
65
|
+
end
|
66
|
+
|
67
|
+
# Moves the cursor to the top left coordinate of the interface.
|
68
|
+
#
|
69
|
+
# @return [Cursor]
|
70
|
+
def self.origin(cursor, interface)
|
71
|
+
new(cursor, interface, (0 - cursor.y), (0 - cursor.x)).move
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns a newly positioned and stored Cursor.
|
75
|
+
#
|
76
|
+
# @return [Cursor]
|
77
|
+
def move
|
78
|
+
Cursor.new(cursor.attributes.merge(moved_attributes)).store
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
attr_reader :cursor, :dx, :dy, :interface
|
84
|
+
|
85
|
+
# @return [Hash]
|
86
|
+
def moved_attributes
|
87
|
+
{
|
88
|
+
x: validator.x,
|
89
|
+
y: validator.y,
|
90
|
+
ox: ox,
|
91
|
+
oy: oy,
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [PositionValidator]
|
96
|
+
def validator
|
97
|
+
@validator ||= Vedeu::PositionValidator.validate(interface,
|
98
|
+
coordinate.x_position(ox),
|
99
|
+
coordinate.y_position(oy))
|
100
|
+
end
|
101
|
+
|
102
|
+
# @return [Fixnum]
|
103
|
+
def ox
|
104
|
+
ox = cursor.ox + dx
|
105
|
+
ox = 0 if ox < 0
|
106
|
+
ox
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [Fixnum]
|
110
|
+
def oy
|
111
|
+
oy = cursor.oy + dy
|
112
|
+
oy = 0 if oy < 0
|
113
|
+
oy
|
114
|
+
end
|
115
|
+
|
116
|
+
# @return [Coordinate]
|
117
|
+
def coordinate
|
118
|
+
@coordinate ||= Coordinate.new(bordered_height, bordered_width, left, top)
|
119
|
+
end
|
120
|
+
|
121
|
+
# @return [Fixnum]
|
122
|
+
def bordered_height
|
123
|
+
return border.height if border?
|
124
|
+
|
125
|
+
height
|
126
|
+
end
|
127
|
+
|
128
|
+
# @return [Fixnum]
|
129
|
+
def bordered_width
|
130
|
+
return border.width if border?
|
131
|
+
|
132
|
+
width
|
133
|
+
end
|
134
|
+
|
135
|
+
end # MoveCursor
|
136
|
+
|
137
|
+
end # Vedeu
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Adjusts the visibility of the cursor.
|
4
|
+
#
|
5
|
+
class ToggleCursor
|
6
|
+
|
7
|
+
# @param cursor [Cursor]
|
8
|
+
# @return [ToggleCursor]
|
9
|
+
def initialize(cursor)
|
10
|
+
@cursor = cursor
|
11
|
+
end
|
12
|
+
|
13
|
+
# Hides the cursor.
|
14
|
+
#
|
15
|
+
# @param cursor [Cursor]
|
16
|
+
# @return [Cursor]
|
17
|
+
def self.hide(cursor)
|
18
|
+
return cursor if cursor.invisible?
|
19
|
+
|
20
|
+
new(cursor).hide
|
21
|
+
end
|
22
|
+
|
23
|
+
# Shows the cursor.
|
24
|
+
#
|
25
|
+
# @param cursor [Cursor]
|
26
|
+
# @return [Cursor]
|
27
|
+
def self.show(cursor)
|
28
|
+
return cursor if cursor.visible?
|
29
|
+
|
30
|
+
new(cursor).show
|
31
|
+
end
|
32
|
+
|
33
|
+
# Hides the cursor.
|
34
|
+
#
|
35
|
+
# @return [Cursor]
|
36
|
+
def hide
|
37
|
+
cursor.class.new(cursor.attributes.merge({ state: false })).store
|
38
|
+
end
|
39
|
+
|
40
|
+
# Shows the cursor.
|
41
|
+
#
|
42
|
+
# @return [Cursor]
|
43
|
+
def show
|
44
|
+
cursor.class.new(cursor.attributes.merge({ state: true })).store
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
attr_reader :cursor
|
50
|
+
|
51
|
+
end # ToggleCursor
|
52
|
+
|
53
|
+
end # Vedeu
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'vedeu/dsl/components/all'
|
2
|
+
require 'vedeu/dsl/shared/all'
|
3
|
+
|
4
|
+
require 'vedeu/dsl/composition'
|
5
|
+
require 'vedeu/dsl/interface'
|
6
|
+
require 'vedeu/dsl/line'
|
7
|
+
require 'vedeu/dsl/stream'
|
8
|
+
require 'vedeu/dsl/view'
|
9
|
+
|
10
|
+
module Vedeu
|
11
|
+
|
12
|
+
module DSL
|
13
|
+
|
14
|
+
# Attempts to find the missing method on the client object.
|
15
|
+
#
|
16
|
+
# @param method [Symbol] The name of the method sought.
|
17
|
+
# @param args [Array] The arguments which the method was to be invoked with.
|
18
|
+
# @param block [Proc] The optional block provided to the method.
|
19
|
+
# @return []
|
20
|
+
def method_missing(method, *args, &block)
|
21
|
+
Vedeu.log("!!!method_missing '#{method}'")
|
22
|
+
|
23
|
+
client.send(method, *args, &block) if client
|
24
|
+
end
|
25
|
+
|
26
|
+
end # DSL
|
27
|
+
|
28
|
+
end # Vedeu
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'vedeu/dsl/shared/all'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
module DSL
|
6
|
+
|
7
|
+
# DSL for creating borders for interfaces.
|
8
|
+
#
|
9
|
+
# Allows customisation for the border's sides and corners; a custom
|
10
|
+
# foreground and background, style, and whether a particular side should be
|
11
|
+
# drawn or not.
|
12
|
+
class Border
|
13
|
+
|
14
|
+
include Vedeu::DSL
|
15
|
+
include Vedeu::DSL::Colour
|
16
|
+
include Vedeu::DSL::Style
|
17
|
+
|
18
|
+
# Returns an instance of DSL::Border.
|
19
|
+
#
|
20
|
+
# @param model [Border]
|
21
|
+
def initialize(model, client = nil)
|
22
|
+
@model = model
|
23
|
+
@client = client
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param char [String] Character to be used as the bottom left border
|
27
|
+
# character.
|
28
|
+
# @return [String]
|
29
|
+
def bottom_left(char)
|
30
|
+
model.attributes[:bottom_left] = char
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param char [String] Character to be used as the bottom right border
|
34
|
+
# character.
|
35
|
+
# @return [String]
|
36
|
+
def bottom_right(char)
|
37
|
+
model.attributes[:bottom_right] = char
|
38
|
+
end
|
39
|
+
|
40
|
+
# @param char [String] Character to be used as the horizontal border
|
41
|
+
# character.
|
42
|
+
# @return [String]
|
43
|
+
def horizontal(char)
|
44
|
+
model.attributes[:horizontal] = char
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param boolean [Boolean] All values evaluate as true except nil and
|
48
|
+
# false.
|
49
|
+
# @return [Boolean]
|
50
|
+
def show_bottom(boolean)
|
51
|
+
model.attributes[:show_bottom] = !!boolean
|
52
|
+
end
|
53
|
+
|
54
|
+
# @param boolean [Boolean] All values evaluate as true except nil and
|
55
|
+
# false.
|
56
|
+
# @return [Boolean]
|
57
|
+
def show_left(boolean)
|
58
|
+
model.attributes[:show_left] = !!boolean
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param boolean [Boolean] All values evaluate as true except nil and
|
62
|
+
# false.
|
63
|
+
# @return [Boolean]
|
64
|
+
def show_right(boolean)
|
65
|
+
model.attributes[:show_right] = !!boolean
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param boolean [Boolean] All values evaluate as true except nil and
|
69
|
+
# false.
|
70
|
+
# @return [Boolean]
|
71
|
+
def show_top(boolean)
|
72
|
+
model.attributes[:show_top] = !!boolean
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param char [String] Character to be used as the top left border
|
76
|
+
# character.
|
77
|
+
# @return [String]
|
78
|
+
def top_left(char)
|
79
|
+
model.attributes[:top_left] = char
|
80
|
+
end
|
81
|
+
|
82
|
+
# @param char [String] Character to be used as the top right border
|
83
|
+
# character.
|
84
|
+
# @return [String]
|
85
|
+
def top_right(char)
|
86
|
+
model.attributes[:top_right] = char
|
87
|
+
end
|
88
|
+
|
89
|
+
# @param char [String] Character to be used as the vertical border
|
90
|
+
# character.
|
91
|
+
# @return [String]
|
92
|
+
def vertical(char)
|
93
|
+
model.attributes[:vertical] = char
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
attr_reader :client, :model
|
99
|
+
|
100
|
+
end # Border
|
101
|
+
|
102
|
+
end # DSL
|
103
|
+
|
104
|
+
end # Vedeu
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'vedeu/dsl/shared/use'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
module DSL
|
6
|
+
|
7
|
+
# Provide DSL methods for configuring the geometry of an interface.
|
8
|
+
#
|
9
|
+
class Geometry
|
10
|
+
|
11
|
+
include Vedeu::DSL
|
12
|
+
include Vedeu::DSL::Use
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
def geometry(name, &block)
|
17
|
+
fail InvalidSyntax, 'block not given' unless block_given?
|
18
|
+
|
19
|
+
Vedeu::Geometry.build({ name: name }, &block).store
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns an instance of DSL::Geometry.
|
25
|
+
#
|
26
|
+
# @param model [Geometry]
|
27
|
+
def initialize(model, client = nil)
|
28
|
+
@model = model
|
29
|
+
@client = client
|
30
|
+
end
|
31
|
+
|
32
|
+
# Instructs Vedeu to calculate x and y geometry automatically based on the
|
33
|
+
# centre character of the terminal, the width and the height.
|
34
|
+
#
|
35
|
+
# @param value [Boolean] Any value other than nil or false will evaluate
|
36
|
+
# to true.
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# interface 'my_interface' do
|
40
|
+
# geometry do
|
41
|
+
# centred!
|
42
|
+
#
|
43
|
+
# interface 'my_interface' do
|
44
|
+
# geometry do
|
45
|
+
# centred false
|
46
|
+
# ...
|
47
|
+
#
|
48
|
+
# @return [Boolean]
|
49
|
+
def centred(value = true)
|
50
|
+
model.centred = !!value
|
51
|
+
end
|
52
|
+
alias_method :centred!, :centred
|
53
|
+
|
54
|
+
# Specify the number of characters/rows/lines tall the interface will be.
|
55
|
+
#
|
56
|
+
# @param value [Fixnum]
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# interface 'my_interface' do
|
60
|
+
# geometry do
|
61
|
+
# height 8
|
62
|
+
# ...
|
63
|
+
#
|
64
|
+
# @return [Fixnum]
|
65
|
+
def height(value)
|
66
|
+
model.height = value
|
67
|
+
end
|
68
|
+
|
69
|
+
# Specify the name of the interface for which the geometry belongs.
|
70
|
+
#
|
71
|
+
# @example
|
72
|
+
# interface 'my_interface' do
|
73
|
+
# geometry do
|
74
|
+
# name 'my_interface'
|
75
|
+
# ...
|
76
|
+
#
|
77
|
+
# @param value [String]
|
78
|
+
# @return [String]
|
79
|
+
def name(value)
|
80
|
+
model.name = value
|
81
|
+
end
|
82
|
+
|
83
|
+
# Specify the number of characters/columns wide the interface will be.
|
84
|
+
#
|
85
|
+
# @param value [Fixnum]
|
86
|
+
#
|
87
|
+
# @example
|
88
|
+
# interface 'my_interface' do
|
89
|
+
# geometry do
|
90
|
+
# width 25
|
91
|
+
# ...
|
92
|
+
#
|
93
|
+
# @return [Fixnum]
|
94
|
+
def width(value)
|
95
|
+
model.width = value
|
96
|
+
end
|
97
|
+
|
98
|
+
# Specify the starting x position (column) of the interface.
|
99
|
+
#
|
100
|
+
# @param value [Fixnum]
|
101
|
+
# @param block [Proc]
|
102
|
+
#
|
103
|
+
# @example
|
104
|
+
# interface 'my_interface' do
|
105
|
+
# geometry do
|
106
|
+
# x 7 # start on column 7.
|
107
|
+
#
|
108
|
+
# interface 'other_interface' do
|
109
|
+
# geometry do
|
110
|
+
# x { use('my_interface').east } # start on column 8, if
|
111
|
+
# # `my_interface` changes position,
|
112
|
+
# # `other_interface` will too.
|
113
|
+
#
|
114
|
+
# @return [Fixnum]
|
115
|
+
def x(value = 0, &block)
|
116
|
+
return model.x = block if block_given?
|
117
|
+
|
118
|
+
model.x = value
|
119
|
+
end
|
120
|
+
|
121
|
+
# Specify the starting y position (row/line) of the interface.
|
122
|
+
#
|
123
|
+
# @param value [Fixnum]
|
124
|
+
# @param block [Proc]
|
125
|
+
#
|
126
|
+
# @example
|
127
|
+
# interface 'my_interface' do
|
128
|
+
# geometry do
|
129
|
+
# y 4
|
130
|
+
# ...
|
131
|
+
#
|
132
|
+
# interface 'other_interface' do
|
133
|
+
# geometry do
|
134
|
+
# y { use('my_interface').north } # start on row/line 3, if
|
135
|
+
# ... # `my_interface` changes position,
|
136
|
+
# # `other_interface` will too.
|
137
|
+
#
|
138
|
+
# @return [Fixnum]
|
139
|
+
def y(value = 0, &block)
|
140
|
+
return model.y = block if block_given?
|
141
|
+
|
142
|
+
model.y = value
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
attr_reader :client, :model
|
148
|
+
|
149
|
+
end # Geometry
|
150
|
+
|
151
|
+
end # DSL
|
152
|
+
|
153
|
+
end # Vedeu
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'vedeu/exceptions'
|
2
|
+
require 'vedeu/support/common'
|
3
|
+
require 'vedeu/input/key'
|
4
|
+
|
5
|
+
module Vedeu
|
6
|
+
|
7
|
+
module DSL
|
8
|
+
|
9
|
+
# Provides methods to be used to define keypress mapped to actions.
|
10
|
+
#
|
11
|
+
# @api public
|
12
|
+
class Keymap
|
13
|
+
|
14
|
+
include Vedeu::Common
|
15
|
+
include Vedeu::DSL
|
16
|
+
|
17
|
+
# Returns an instance of DSL::Keymap.
|
18
|
+
#
|
19
|
+
# @param model [Keymap]
|
20
|
+
def initialize(model, client = nil)
|
21
|
+
@model = model
|
22
|
+
@client = client
|
23
|
+
end
|
24
|
+
|
25
|
+
# Define keypress(es) to perform an action.
|
26
|
+
#
|
27
|
+
# @param value_or_values [Array<String>|Array<Symbol>|String|Symbol]
|
28
|
+
# The key(s) pressed. Special keys can be found in
|
29
|
+
# {Vedeu::Input#specials}. When more than one key is defined, then the
|
30
|
+
# extras are treated as aliases.
|
31
|
+
# @param block [Proc] The action to perform when this key is pressed. Can
|
32
|
+
# be a method call or event triggered.
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# Vedeu.keymap do
|
36
|
+
# key('s') { Vedeu.trigger(:save) }
|
37
|
+
# key('h', :left) { Vedeu.trigger(:left) }
|
38
|
+
# key('j', :down) { Vedeu.trigger(:down) }
|
39
|
+
# key('p') do
|
40
|
+
# ...
|
41
|
+
# end
|
42
|
+
# ...
|
43
|
+
#
|
44
|
+
# @raise [InvalidSyntax] When the required block is not given, the
|
45
|
+
# value_or_values parameter is undefined, or when processing the
|
46
|
+
# collection, a member is undefined.
|
47
|
+
# @return [Array] A collection containing the keypress(es).
|
48
|
+
def key(*value_or_values, &block)
|
49
|
+
fail InvalidSyntax, 'No action defined for `key`.' unless block_given?
|
50
|
+
|
51
|
+
unless defined_value?(value_or_values)
|
52
|
+
fail InvalidSyntax, 'No keypress(es) defined for `key`.'
|
53
|
+
end
|
54
|
+
|
55
|
+
value_or_values.each do |value|
|
56
|
+
unless defined_value?(value)
|
57
|
+
fail InvalidSyntax, 'An invalid value for `key` was encountered.'
|
58
|
+
end
|
59
|
+
|
60
|
+
unless model.key_defined?(value)
|
61
|
+
model.add(Vedeu::Key.define(value, &block))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Define the name of the keymap.
|
67
|
+
#
|
68
|
+
# To only allow certain keys to work with specific interfaces, use the
|
69
|
+
# same name as the interface.
|
70
|
+
#
|
71
|
+
# When the name '_global_' is used, all keys in the keymap block will be
|
72
|
+
# available to all interfaces. Once a key has been defined in the
|
73
|
+
# '_global_' keymap, it cannot be used for a specific interface.
|
74
|
+
#
|
75
|
+
# @note Using the name of a keymap that already exists will overwrite that
|
76
|
+
# keymap. Do not use the name '_system_' as unexpected behaviour may
|
77
|
+
# occur.
|
78
|
+
#
|
79
|
+
# @param value [String]
|
80
|
+
# @return [String]
|
81
|
+
def name(value)
|
82
|
+
model.name = value
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
attr_reader :client, :model
|
88
|
+
|
89
|
+
end # Keymap
|
90
|
+
|
91
|
+
end # DSL
|
92
|
+
|
93
|
+
end # Vedeu
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module DSL
|
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 Vedeu::DSL
|
12
|
+
|
13
|
+
# Return a new instance of DSL::Menu.
|
14
|
+
#
|
15
|
+
# @param model [Vedeu::Menu]
|
16
|
+
# @return [DSL::Menu]
|
17
|
+
def initialize(model, client = nil)
|
18
|
+
@model = model
|
19
|
+
@client = client
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add an individual item to the menu.
|
23
|
+
#
|
24
|
+
# @param element [Object] An object you wish to add to the collection.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# menu 'my_menu' do
|
28
|
+
# item SomeClass.new
|
29
|
+
# item SomeClass.new
|
30
|
+
#
|
31
|
+
# @return [Array]
|
32
|
+
def item(element)
|
33
|
+
model.collection << element
|
34
|
+
end
|
35
|
+
|
36
|
+
# Define the items for the menu. Most powerful when used with one of your
|
37
|
+
# model classes.
|
38
|
+
#
|
39
|
+
# In the 'my_playlist' example below, your `Track` model may return a
|
40
|
+
# collection of tracks to populate the menu.
|
41
|
+
#
|
42
|
+
# @param collection [Array<Object>] A collection of objects which make up
|
43
|
+
# the menu items.
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# menu 'my_menu' do
|
47
|
+
# items [:item_1, :item_2, :item_3]
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# menu 'my_playlist' do
|
51
|
+
# items Track.all_my_favourites
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# @return [Array]
|
55
|
+
def items(collection = [])
|
56
|
+
model.collection = collection
|
57
|
+
end
|
58
|
+
|
59
|
+
# The name of the menu. Used to reference the menu throughout your
|
60
|
+
# application's execution lifetime.
|
61
|
+
#
|
62
|
+
# @param value [String]
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# menu do
|
66
|
+
# name 'my_menu'
|
67
|
+
# ...
|
68
|
+
#
|
69
|
+
# @return [String]
|
70
|
+
def name(value)
|
71
|
+
model.name = value
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
attr_reader :client, :model
|
77
|
+
|
78
|
+
end # Menu
|
79
|
+
|
80
|
+
end # DSL
|
81
|
+
|
82
|
+
end # Vedeu
|