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
@@ -1,64 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
# Repository for storing, retrieving and manipulating the cursor position and
|
4
|
-
# visibility for an interface.
|
5
|
-
#
|
6
|
-
# @api private
|
7
|
-
module Cursors
|
8
|
-
|
9
|
-
include Repository
|
10
|
-
extend self
|
11
|
-
|
12
|
-
# Add or update the cursor coordinates.
|
13
|
-
#
|
14
|
-
# @param attributes [Hash]
|
15
|
-
# @return [Offset]
|
16
|
-
def add(attributes)
|
17
|
-
validate_attributes!(attributes)
|
18
|
-
|
19
|
-
Vedeu.log("#{action(__callee__)} positional (#{model}): " \
|
20
|
-
"'#{attributes[:name]}'")
|
21
|
-
|
22
|
-
model.new(attributes).store
|
23
|
-
end
|
24
|
-
alias_method :update, :add
|
25
|
-
|
26
|
-
# Make the cursor of this interface invisible.
|
27
|
-
#
|
28
|
-
# @return [Cursor]
|
29
|
-
def hide
|
30
|
-
find_or_create(Focus.current).hide
|
31
|
-
end
|
32
|
-
|
33
|
-
# Make the cursor of this interface visible.
|
34
|
-
#
|
35
|
-
# @return [Cursor]
|
36
|
-
def show
|
37
|
-
find_or_create(Focus.current).show
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
# @return [Class] The model class for this repository.
|
43
|
-
def model
|
44
|
-
Vedeu::Cursor
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns an empty collection ready for the storing of cursors by name with
|
48
|
-
# current attributes.
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# { 'holmium' => {
|
52
|
-
# name: 'holmium',
|
53
|
-
# state: :show,
|
54
|
-
# x: 1,
|
55
|
-
# y: 1 } }
|
56
|
-
#
|
57
|
-
# @return [Hash]
|
58
|
-
def in_memory
|
59
|
-
{}
|
60
|
-
end
|
61
|
-
|
62
|
-
end # Cursors
|
63
|
-
|
64
|
-
end # Vedeu
|
@@ -1,147 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
# Provides a mechanism for storing and retrieving events by name. A single
|
4
|
-
# name can contain many events. Also, an event can trigger other events.
|
5
|
-
#
|
6
|
-
# @todo I really don't like the 'hashiness' of this. (GL 2014-10-29)
|
7
|
-
#
|
8
|
-
# @api private
|
9
|
-
module Events
|
10
|
-
|
11
|
-
include Repository
|
12
|
-
extend self
|
13
|
-
|
14
|
-
# @see Vedeu::API#unevent
|
15
|
-
alias_method :unevent, :remove
|
16
|
-
|
17
|
-
# Register an event by name with optional delay (throttling) which when
|
18
|
-
# triggered will execute the code contained within the passed block.
|
19
|
-
#
|
20
|
-
# @param name [Symbol] The name of the event which will be triggered later.
|
21
|
-
# @param [Hash] opts The options to register the event with.
|
22
|
-
# @option opts :delay [Fixnum|Float] Limits the execution of the
|
23
|
-
# triggered event to only execute when first triggered, with subsequent
|
24
|
-
# triggering being ignored until the delay has expired.
|
25
|
-
# @option opts :debounce [Fixnum|Float] Limits the execution of the
|
26
|
-
# triggered event to only execute once the debounce has expired.
|
27
|
-
# Subsequent triggers before debounce expiry are ignored.
|
28
|
-
# @param block [Proc] The event to be executed when triggered. This block
|
29
|
-
# could be a method call, or the triggering of another event, or sequence
|
30
|
-
# of either/both.
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# Vedeu.event :my_event do |some, args|
|
34
|
-
# ... some code here ...
|
35
|
-
#
|
36
|
-
# Vedeu.trigger(:my_other_event)
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# T = Triggered, X = Executed, i = Ignored.
|
40
|
-
#
|
41
|
-
# 0.0.....0.2.....0.4.....0.6.....0.8.....1.0.....1.2.....1.4.....1.6...
|
42
|
-
# .T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T
|
43
|
-
# .X...i...i...i...i...X...i...i...i...i...X...i...i...i...i...i...i...i
|
44
|
-
#
|
45
|
-
# Vedeu.event(:my_delayed_event, { delay: 0.5 })
|
46
|
-
# ... some code here ...
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# T = Triggered, X = Executed, i = Ignored.
|
50
|
-
#
|
51
|
-
# 0.0.....0.2.....0.4.....0.6.....0.8.....1.0.....1.2.....1.4.....1.6...
|
52
|
-
# .T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T
|
53
|
-
# .i...i...i...i...i...i...i...X...i...i...i...i...i...i...X...i...i...i
|
54
|
-
#
|
55
|
-
# Vedeu.event(:my_debounced_event, { debounce: 0.7 })
|
56
|
-
# ... some code here ...
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# @return [Hash]
|
60
|
-
def add(name, options = {}, &block)
|
61
|
-
Vedeu.log("Registering event: '#{name}'")
|
62
|
-
|
63
|
-
events(name) << model.new(name, options, block)
|
64
|
-
end
|
65
|
-
alias_method :event, :add
|
66
|
-
|
67
|
-
# @see Vedeu::API#trigger
|
68
|
-
def use(name, *args)
|
69
|
-
results = events(name).map { |event| event.trigger(*args) }
|
70
|
-
|
71
|
-
return results.first if results.one?
|
72
|
-
|
73
|
-
results
|
74
|
-
end
|
75
|
-
alias_method :trigger, :use
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
# @return [Class] The model class for this repository.
|
80
|
-
def model
|
81
|
-
Vedeu::Event
|
82
|
-
end
|
83
|
-
|
84
|
-
def events(name)
|
85
|
-
storage[name][:events]
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns an empty collection ready for the storing of events by name with
|
89
|
-
# associated event instance.
|
90
|
-
#
|
91
|
-
# @return [Hash]
|
92
|
-
def in_memory
|
93
|
-
Hash.new { |hash, key| hash[key] = { events: [] } }
|
94
|
-
end
|
95
|
-
|
96
|
-
# System events needed by Vedeu to run.
|
97
|
-
event(:_clear_) { Vedeu::Terminal.clear_screen }
|
98
|
-
event(:_exit_) { Vedeu::Application.stop }
|
99
|
-
event(:_initialize_) { Vedeu.trigger(:_refresh_) }
|
100
|
-
event(:_keypress_) { |key| Vedeu.keypress(key) }
|
101
|
-
event(:_log_) { |msg| Vedeu.log(msg) }
|
102
|
-
event(:_mode_switch_) { fail ModeSwitch }
|
103
|
-
event(:_resize_, { delay: 0.25 }) { Vedeu.resize }
|
104
|
-
|
105
|
-
# System events which when called will update the cursor visibility
|
106
|
-
# accordingly for the interface in focus.
|
107
|
-
# From: Cursors (top)
|
108
|
-
event(:_cursor_hide_) { Vedeu::Cursors.hide }
|
109
|
-
event(:_cursor_show_) { Vedeu::Cursors.show }
|
110
|
-
|
111
|
-
# System events which when called will change which interface is currently
|
112
|
-
# focussed. When the interface is brought into focus, its cursor position
|
113
|
-
# and visibility is restored.
|
114
|
-
# From: Focus (top)
|
115
|
-
event(:_focus_by_name_) { |name| Vedeu::Focus.by_name(name) }
|
116
|
-
event(:_focus_next_) { Vedeu::Focus.next_item }
|
117
|
-
event(:_focus_prev_) { Vedeu::Focus.prev_item }
|
118
|
-
|
119
|
-
# System events which when called will move in the direction specified;
|
120
|
-
# these will update the cursor position or content offset (scrolling)
|
121
|
-
# according to the interface in focus.
|
122
|
-
# From: Offsets (bottom)
|
123
|
-
event(:_cursor_down_) { Vedeu::Offsets.down }
|
124
|
-
event(:_cursor_left_) { Vedeu::Offsets.left }
|
125
|
-
event(:_cursor_right_) { Vedeu::Offsets.right }
|
126
|
-
event(:_cursor_up_) { Vedeu::Offsets.up }
|
127
|
-
|
128
|
-
# System events which when called with the appropriate menu name will
|
129
|
-
# update the menu accordingly.
|
130
|
-
# From: Menus (top)
|
131
|
-
event(:_menu_bottom_) { |name| Vedeu::Menus.use(name).bottom_item }
|
132
|
-
event(:_menu_current_) { |name| Vedeu::Menus.use(name).current_item }
|
133
|
-
event(:_menu_deselect_) { |name| Vedeu::Menus.use(name).deselect_item }
|
134
|
-
event(:_menu_items_) { |name| Vedeu::Menus.use(name).items }
|
135
|
-
event(:_menu_next_) { |name| Vedeu::Menus.use(name).next_item }
|
136
|
-
event(:_menu_prev_) { |name| Vedeu::Menus.use(name).prev_item }
|
137
|
-
event(:_menu_selected_) { |name| Vedeu::Menus.use(name).selected_item }
|
138
|
-
event(:_menu_select_) { |name| Vedeu::Menus.use(name).select_item }
|
139
|
-
event(:_menu_top_) { |name| Vedeu::Menus.use(name).top_item }
|
140
|
-
event(:_menu_view_) { |name| Vedeu::Menus.use(name).view }
|
141
|
-
|
142
|
-
# System event to refresh all registered interfaces.
|
143
|
-
event(:_refresh_) { Vedeu::Refresh.all }
|
144
|
-
|
145
|
-
end # Events
|
146
|
-
|
147
|
-
end # Vedeu
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
# Repository for storing and retrieving interfaces by their group name.
|
4
|
-
#
|
5
|
-
# @api private
|
6
|
-
module Groups
|
7
|
-
|
8
|
-
include Repository
|
9
|
-
extend self
|
10
|
-
|
11
|
-
# Add an interface name to a group, creating the group if it doesn't already
|
12
|
-
# exist, and rejecting the interface if it is already known.
|
13
|
-
#
|
14
|
-
# @param attributes [Hash]
|
15
|
-
# @return [Boolean]
|
16
|
-
def add(attributes)
|
17
|
-
validate_attributes!(attributes)
|
18
|
-
|
19
|
-
return false unless defined_value?(attributes[:group])
|
20
|
-
|
21
|
-
storage[attributes[:group]] << attributes[:name]
|
22
|
-
|
23
|
-
register_event(attributes)
|
24
|
-
|
25
|
-
true
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# @see Vedeu::Refresh.register_event
|
31
|
-
# @param attributes [Hash]
|
32
|
-
# @return [Boolean]
|
33
|
-
def register_event(attributes)
|
34
|
-
group_name = attributes[:group]
|
35
|
-
delay = attributes[:delay] || 0.0
|
36
|
-
|
37
|
-
Vedeu::Refresh.register_event(:by_group, group_name, delay)
|
38
|
-
end
|
39
|
-
|
40
|
-
# @return [Hash]
|
41
|
-
def in_memory
|
42
|
-
Hash.new { |hash, key| hash[key] = Set.new }
|
43
|
-
end
|
44
|
-
|
45
|
-
end # Groups
|
46
|
-
|
47
|
-
end # Vedeu
|
@@ -1,78 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
# Repository for storing and retrieving defined interfaces.
|
4
|
-
#
|
5
|
-
# @api private
|
6
|
-
module Interfaces
|
7
|
-
|
8
|
-
include Repository
|
9
|
-
extend self
|
10
|
-
|
11
|
-
# Stores the interface attributes defined by the API.
|
12
|
-
#
|
13
|
-
# @param attributes [Hash]
|
14
|
-
# @return [Hash|FalseClass]
|
15
|
-
def add(attributes)
|
16
|
-
validate_attributes!(attributes)
|
17
|
-
|
18
|
-
Vedeu.log("Registering interface: '#{attributes[:name]}'")
|
19
|
-
|
20
|
-
storage.store(attributes[:name], attributes)
|
21
|
-
|
22
|
-
register_event(attributes)
|
23
|
-
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
# Create an instance of Interface from the stored attributes.
|
28
|
-
#
|
29
|
-
# @param name [String]
|
30
|
-
# @return [Interface]
|
31
|
-
def build(name)
|
32
|
-
model.new(find(name))
|
33
|
-
end
|
34
|
-
|
35
|
-
# Reset the interfaces repository; removing all registered interfaces.
|
36
|
-
# This will delete the interfaces themselves, and the client application
|
37
|
-
# will need to either redefine interfaces before using them, or restart.
|
38
|
-
#
|
39
|
-
# Note: It also resets repositories which depend on interfaces being
|
40
|
-
# registered.
|
41
|
-
#
|
42
|
-
# @return [Hash]
|
43
|
-
def reset
|
44
|
-
@_storage = in_memory
|
45
|
-
|
46
|
-
Vedeu::Buffers.reset
|
47
|
-
Vedeu::Cursors.reset
|
48
|
-
Vedeu::Focus.reset
|
49
|
-
Vedeu::Groups.reset
|
50
|
-
|
51
|
-
@_storage
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
# @return [Class] The model class for this repository.
|
57
|
-
def model
|
58
|
-
Vedeu::Interface
|
59
|
-
end
|
60
|
-
|
61
|
-
# @see Vedeu::Refresh.register_event
|
62
|
-
# @param attributes [Hash]
|
63
|
-
# @return [Boolean]
|
64
|
-
def register_event(attributes)
|
65
|
-
name = attributes[:name]
|
66
|
-
delay = attributes[:delay] || 0.0
|
67
|
-
|
68
|
-
Vedeu::Refresh.register_event(:by_name, name, delay)
|
69
|
-
end
|
70
|
-
|
71
|
-
# @return [Hash]
|
72
|
-
def in_memory
|
73
|
-
{}
|
74
|
-
end
|
75
|
-
|
76
|
-
end # Interfaces
|
77
|
-
|
78
|
-
end # Vedeu
|
@@ -1,196 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
# Repository for storing, retrieving and using defined keymaps.
|
4
|
-
#
|
5
|
-
# @api private
|
6
|
-
module Keymaps
|
7
|
-
|
8
|
-
include Repository
|
9
|
-
extend self
|
10
|
-
|
11
|
-
# Stores the keymap attributes defined by the API.
|
12
|
-
#
|
13
|
-
# @param attributes [Hash]
|
14
|
-
# @option attributes :interfaces [Array] A list of the names of interfaces for which the
|
15
|
-
# keys are active for.
|
16
|
-
# @option attributes :keys [Array] A collection of key/action pairs.
|
17
|
-
# @return [TrueClass|KeyInUse|FalseClass]
|
18
|
-
def add(attributes)
|
19
|
-
return false unless defined_value?(attributes[:keys])
|
20
|
-
|
21
|
-
if defined_value?(attributes[:interfaces])
|
22
|
-
attributes[:interfaces].map do |interface|
|
23
|
-
storage.store(interface, {}) unless registered?(interface)
|
24
|
-
|
25
|
-
register(attributes, interface)
|
26
|
-
end
|
27
|
-
|
28
|
-
else
|
29
|
-
register(attributes)
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
true
|
34
|
-
end
|
35
|
-
|
36
|
-
# Find a keymap by named interface. Return an empty collection when there =
|
37
|
-
# are no specific keys defined for the named interface.
|
38
|
-
#
|
39
|
-
# @param name [String]
|
40
|
-
# @return [Hash]
|
41
|
-
def find(name)
|
42
|
-
storage.fetch(name, {})
|
43
|
-
end
|
44
|
-
|
45
|
-
# Return a boolean indicating whether the key is registered as a global key.
|
46
|
-
#
|
47
|
-
# @param key [String|Symbol]
|
48
|
-
# @return [Boolean]
|
49
|
-
def global_key?(key)
|
50
|
-
global_keys.include?(key)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Return the collection of global keys.
|
54
|
-
#
|
55
|
-
# @return [Array]
|
56
|
-
def global_keys
|
57
|
-
storage.fetch('_global_keymap_', {}).keys
|
58
|
-
end
|
59
|
-
|
60
|
-
# Return a boolean indicating whether the key is registered as an interface
|
61
|
-
# key. When an interface argument is provided, only that interface is
|
62
|
-
# checked.
|
63
|
-
#
|
64
|
-
# @param key [String|Symbol]
|
65
|
-
# @param interface [String]
|
66
|
-
# @return [Boolean]
|
67
|
-
def interface_key?(key, interface = '')
|
68
|
-
if defined_value?(interface)
|
69
|
-
find(interface).keys.include?(key)
|
70
|
-
|
71
|
-
else
|
72
|
-
interface_keys.include?(key)
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Return a collection of interface keys. When the optional 'name' parameter
|
78
|
-
# is provided, then only the keys associated with that interface are
|
79
|
-
# returned.
|
80
|
-
#
|
81
|
-
# @param interface [String]
|
82
|
-
# @return [Hash]
|
83
|
-
def interface_keys(interface = nil)
|
84
|
-
return find(interface).keys if interface
|
85
|
-
|
86
|
-
storage.reject do |k, _|
|
87
|
-
k == '_global_keymap_'
|
88
|
-
end.map { |_, v| v.keys }.flatten.uniq
|
89
|
-
end
|
90
|
-
|
91
|
-
# Return a boolean indicating whether the key is registered as a system key.
|
92
|
-
#
|
93
|
-
# @param key [String|Symbol]
|
94
|
-
# @return [Boolean]
|
95
|
-
def system_key?(key)
|
96
|
-
system_keys.include?(key)
|
97
|
-
end
|
98
|
-
|
99
|
-
# Return the collection of system keys.
|
100
|
-
#
|
101
|
-
# @return [Array]
|
102
|
-
def system_keys
|
103
|
-
Configuration.system_keys.invert.keys
|
104
|
-
end
|
105
|
-
|
106
|
-
# Handles the keypress in your application. Can also be used to simulate a
|
107
|
-
# keypress.
|
108
|
-
#
|
109
|
-
# 1) Log the keypress if debugging is enabled.
|
110
|
-
# 2) Trigger the client application's `:key` event (it may not exist).
|
111
|
-
# 3) Determine if the key pertains to the focussed interface and action it,
|
112
|
-
# or check both global, then system keys to action it. Returns false if
|
113
|
-
# nothing can deal with it.
|
114
|
-
#
|
115
|
-
# @param key [String|Symbol] The key which was pressed. Escape sequences
|
116
|
-
# are also supported. Special keys like the F-keys are named as symbols;
|
117
|
-
# i.e. `:f4`. A list of these translations can be found at {Vedeu::Input}.
|
118
|
-
#
|
119
|
-
# @example
|
120
|
-
# Vedeu.keypress('s')
|
121
|
-
#
|
122
|
-
# @return [Array|FalseClass]
|
123
|
-
def use(key)
|
124
|
-
Vedeu.log("Key pressed: '#{key}'")
|
125
|
-
|
126
|
-
Vedeu.trigger(:key, key)
|
127
|
-
|
128
|
-
focussed_interface = Vedeu::Focus.current
|
129
|
-
|
130
|
-
if interface_key?(key, focussed_interface)
|
131
|
-
find(focussed_interface).fetch(key, noop).call(:noop_interface)
|
132
|
-
|
133
|
-
elsif global_key?(key)
|
134
|
-
find('_global_keymap_').fetch(key, noop).call(:noop_global)
|
135
|
-
|
136
|
-
elsif system_key?(key)
|
137
|
-
system_key(key)
|
138
|
-
|
139
|
-
else
|
140
|
-
false
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|
144
|
-
alias_method :keypress, :use
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
# @return [Class] The model class for this repository.
|
149
|
-
def model
|
150
|
-
Vedeu::Keymap
|
151
|
-
end
|
152
|
-
|
153
|
-
# Triggers the system event defined for this key.
|
154
|
-
#
|
155
|
-
# @param key [String|Symbol]
|
156
|
-
# @return [Array] The result(s) of triggering the event.
|
157
|
-
def system_key(key)
|
158
|
-
action = Vedeu::Configuration.system_keys.key(key)
|
159
|
-
event = ['_', action, '_'].join.to_sym
|
160
|
-
|
161
|
-
Vedeu.trigger(event)
|
162
|
-
end
|
163
|
-
|
164
|
-
# Registers the key.
|
165
|
-
#
|
166
|
-
# @param attributes [Hash]
|
167
|
-
# @param interface [String]
|
168
|
-
# @return [Array]
|
169
|
-
def register(attributes, interface = '_global_keymap_')
|
170
|
-
attributes[:keys].map do |keymap|
|
171
|
-
KeymapValidator.check(storage, keymap[:key], interface)
|
172
|
-
|
173
|
-
Vedeu.log("Registering key: '#{keymap[:key]}' with '#{interface}'")
|
174
|
-
|
175
|
-
storage[interface].merge!({ keymap[:key] => keymap[:action] })
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
# Returns a noop proc which when called returns the argument or :noop.
|
180
|
-
#
|
181
|
-
# @param value [Symbol]
|
182
|
-
# @return [Proc]
|
183
|
-
def noop(value = :noop)
|
184
|
-
proc { value }
|
185
|
-
end
|
186
|
-
|
187
|
-
# @return [Hash]
|
188
|
-
def in_memory
|
189
|
-
{
|
190
|
-
'_global_keymap_' => {}
|
191
|
-
}
|
192
|
-
end
|
193
|
-
|
194
|
-
end # Keymaps
|
195
|
-
|
196
|
-
end # Vedeu
|