vedeu 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/docs/dsl.md +4 -4
  4. data/lib/vedeu/all.rb +6 -18
  5. data/lib/vedeu/api.rb +14 -13
  6. data/lib/vedeu/bindings/system.rb +5 -4
  7. data/lib/vedeu/buffers/virtual_buffer.rb +13 -11
  8. data/lib/vedeu/configuration/api.rb +4 -3
  9. data/lib/vedeu/cursors/cursor.rb +23 -18
  10. data/lib/vedeu/distributed/client.rb +11 -6
  11. data/lib/vedeu/distributed/server.rb +4 -3
  12. data/lib/vedeu/dsl/keymap.rb +6 -6
  13. data/lib/vedeu/editor/all.rb +19 -0
  14. data/lib/vedeu/{input/editor → editor}/capture.rb +1 -1
  15. data/lib/vedeu/{input/editor → editor}/cropper.rb +0 -0
  16. data/lib/vedeu/{input/editor → editor}/cursor.rb +0 -0
  17. data/lib/vedeu/{input/editor → editor}/document.rb +0 -0
  18. data/lib/vedeu/{input/editor → editor}/documents.rb +0 -0
  19. data/lib/vedeu/{input/editor → editor}/editor.rb +0 -0
  20. data/lib/vedeu/{input/editor → editor}/insert.rb +0 -0
  21. data/lib/vedeu/{input/editor → editor}/line.rb +0 -0
  22. data/lib/vedeu/{input/editor → editor}/lines.rb +0 -0
  23. data/lib/vedeu/error.rb +21 -18
  24. data/lib/vedeu/esc/borders.rb +6 -4
  25. data/lib/vedeu/esc/colours.rb +13 -12
  26. data/lib/vedeu/esc/esc.rb +11 -10
  27. data/lib/vedeu/input/all.rb +15 -0
  28. data/lib/vedeu/input/input.rb +55 -52
  29. data/lib/vedeu/input/key.rb +36 -30
  30. data/lib/vedeu/input/keymap.rb +101 -92
  31. data/lib/vedeu/input/keymaps.rb +10 -6
  32. data/lib/vedeu/input/keys.rb +8 -4
  33. data/lib/vedeu/input/mapper.rb +125 -121
  34. data/lib/vedeu/input/translator.rb +159 -0
  35. data/lib/vedeu/internal_api.rb +16 -15
  36. data/lib/vedeu/logging/all.rb +13 -0
  37. data/lib/vedeu/logging/debug.rb +84 -0
  38. data/lib/vedeu/logging/lockless_log_device.rb +65 -0
  39. data/lib/vedeu/logging/log.rb +179 -0
  40. data/lib/vedeu/logging/mono_logger.rb +26 -0
  41. data/lib/vedeu/logging/timer.rb +68 -0
  42. data/lib/vedeu/menus/all.rb +12 -0
  43. data/lib/vedeu/{dsl/menu.rb → menus/dsl.rb} +19 -18
  44. data/lib/vedeu/menus/menu.rb +234 -0
  45. data/lib/vedeu/{null/menu.rb → menus/null.rb} +6 -6
  46. data/lib/vedeu/menus/repository.rb +18 -0
  47. data/lib/vedeu/models/cell.rb +62 -55
  48. data/lib/vedeu/models/escape.rb +55 -50
  49. data/lib/vedeu/models/page.rb +74 -69
  50. data/lib/vedeu/models/row.rb +55 -51
  51. data/lib/vedeu/models/views/all.rb +1 -0
  52. data/lib/vedeu/models/views/char.rb +1 -1
  53. data/lib/vedeu/models/views/html_char.rb +165 -0
  54. data/lib/vedeu/output/renderers/html.rb +5 -4
  55. data/lib/vedeu/repositories/model.rb +2 -0
  56. data/lib/vedeu/runtime/application.rb +110 -103
  57. data/lib/vedeu/runtime/bootstrap.rb +109 -103
  58. data/lib/vedeu/runtime/flags.rb +45 -41
  59. data/lib/vedeu/runtime/launcher.rb +1 -1
  60. data/lib/vedeu/runtime/main_loop.rb +51 -46
  61. data/lib/vedeu/runtime/traps.rb +20 -16
  62. data/lib/vedeu/version.rb +1 -1
  63. data/lib/vedeu.rb +2 -2
  64. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +1 -1
  65. data/test/lib/vedeu/cursors/cursor_test.rb +11 -5
  66. data/test/lib/vedeu/dsl/interface_test.rb +1 -1
  67. data/test/lib/vedeu/dsl/keymap_test.rb +2 -2
  68. data/test/lib/vedeu/{input/editor → editor}/capture_test.rb +0 -0
  69. data/test/lib/vedeu/{input/editor → editor}/cropper_test.rb +0 -0
  70. data/test/lib/vedeu/{input/editor → editor}/cursor_test.rb +0 -0
  71. data/test/lib/vedeu/{input/editor → editor}/document_test.rb +0 -0
  72. data/test/lib/vedeu/{input/editor → editor}/documents_test.rb +0 -0
  73. data/test/lib/vedeu/{input/editor → editor}/editor_test.rb +0 -0
  74. data/test/lib/vedeu/{input/editor → editor}/insert_test.rb +0 -0
  75. data/test/lib/vedeu/{input/editor → editor}/line_test.rb +0 -0
  76. data/test/lib/vedeu/{input/editor → editor}/lines_test.rb +0 -0
  77. data/test/lib/vedeu/input/input_test.rb +58 -54
  78. data/test/lib/vedeu/input/key_test.rb +29 -25
  79. data/test/lib/vedeu/input/keymap_test.rb +74 -70
  80. data/test/lib/vedeu/input/keymaps_test.rb +8 -4
  81. data/test/lib/vedeu/input/keys_test.rb +12 -8
  82. data/test/lib/vedeu/input/mapper_test.rb +64 -56
  83. data/test/lib/vedeu/input/translator_test.rb +36 -0
  84. data/test/lib/vedeu/logging/debug_test.rb +39 -0
  85. data/test/lib/vedeu/logging/lockless_log_device_test.rb +42 -0
  86. data/test/lib/vedeu/logging/log_test.rb +52 -0
  87. data/test/lib/vedeu/logging/mono_logger_test.rb +43 -0
  88. data/test/lib/vedeu/logging/timer_test.rb +44 -0
  89. data/test/lib/vedeu/{dsl/menu_test.rb → menus/dsl_test.rb} +6 -6
  90. data/test/lib/vedeu/menus/menu_test.rb +305 -0
  91. data/test/lib/vedeu/{null/menu_test.rb → menus/null_test.rb} +5 -5
  92. data/test/lib/vedeu/menus/repository_test.rb +17 -0
  93. data/test/lib/vedeu/models/cell_test.rb +54 -50
  94. data/test/lib/vedeu/models/escape_test.rb +49 -45
  95. data/test/lib/vedeu/models/page_test.rb +167 -160
  96. data/test/lib/vedeu/models/row_test.rb +71 -67
  97. data/test/lib/vedeu/models/views/html_char_test.rb +110 -0
  98. data/test/lib/vedeu/output/compressor_test.rb +44 -22
  99. data/test/lib/vedeu/output/renderers_test.rb +4 -2
  100. data/test/lib/vedeu/runtime/application_test.rb +36 -32
  101. data/test/lib/vedeu/runtime/bootstrap_test.rb +31 -26
  102. data/test/lib/vedeu/runtime/flags_test.rb +33 -29
  103. data/test/lib/vedeu/runtime/launcher_test.rb +4 -2
  104. data/test/lib/vedeu/runtime/main_loop_test.rb +28 -24
  105. data/test/lib/vedeu/runtime/traps_test.rb +8 -4
  106. data/test/test_helper.rb +4 -2
  107. metadata +66 -63
  108. data/lib/vedeu/input/editor/all.rb +0 -19
  109. data/lib/vedeu/input/input_translator.rb +0 -155
  110. data/lib/vedeu/log/debug.rb +0 -79
  111. data/lib/vedeu/log/lockless_log_device.rb +0 -61
  112. data/lib/vedeu/log/log.rb +0 -172
  113. data/lib/vedeu/log/mono_logger.rb +0 -21
  114. data/lib/vedeu/log/timer.rb +0 -63
  115. data/lib/vedeu/models/menu.rb +0 -217
  116. data/lib/vedeu/models/menus.rb +0 -14
  117. data/lib/vedeu/output/html_char.rb +0 -161
  118. data/test/lib/vedeu/input/input_translator_test.rb +0 -32
  119. data/test/lib/vedeu/log/debug_test.rb +0 -35
  120. data/test/lib/vedeu/log/lockless_log_device_test.rb +0 -29
  121. data/test/lib/vedeu/log/log_test.rb +0 -48
  122. data/test/lib/vedeu/log/mono_logger_test.rb +0 -31
  123. data/test/lib/vedeu/log/timer_test.rb +0 -40
  124. data/test/lib/vedeu/models/menu_test.rb +0 -301
  125. data/test/lib/vedeu/models/menus_test.rb +0 -13
  126. data/test/lib/vedeu/output/html_char_test.rb +0 -106
@@ -10,8 +10,8 @@ module Vedeu
10
10
 
11
11
  extend self
12
12
 
13
- # Produces the background named colour escape sequence hash from the
14
- # foreground escape sequence hash.
13
+ # Produces the background named colour escape sequence hash from
14
+ # the foreground escape sequence hash.
15
15
  #
16
16
  # @return [Hash<Symbol => Fixnum>]
17
17
  def background_codes
@@ -22,10 +22,10 @@ module Vedeu
22
22
  end
23
23
 
24
24
  # Produces the foreground named colour escape sequence hash. The
25
- # background escape sequences are also generated from this by adding 10 to
26
- # the values.
27
- # This hash gives rise to methods you can call directly on `Esc` to
28
- # produce the desired colours:
25
+ # background escape sequences are also generated from this by
26
+ # adding 10 to the values.
27
+ # This hash gives rise to methods you can call directly on `Esc`
28
+ # to produce the desired colours:
29
29
  #
30
30
  # @example
31
31
  # Esc.red # => "\e[31m"
@@ -37,9 +37,10 @@ module Vedeu
37
37
  # Esc.on_blue { 'some text' } # => "\e[44msome text\e[49m"
38
38
  #
39
39
  # # Valid names:
40
- # :black, :red, :green, :yellow, :blue, :magenta, :cyan, :light_grey,
41
- # :default, :dark_grey, :light_red, :light_green, :light_yellow,
42
- # :light_blue, :light_magenta, :light_cyan, :white
40
+ # :black, :red, :green, :yellow, :blue, :magenta, :cyan,
41
+ # :light_grey, :default, :dark_grey, :light_red, :light_green,
42
+ # :light_yellow, :light_blue, :light_magenta, :light_cyan,
43
+ # :white
43
44
  #
44
45
  # @return [Hash<Symbol => Fixnum>]
45
46
  def foreground_codes
@@ -82,9 +83,9 @@ module Vedeu
82
83
  end
83
84
  end
84
85
 
85
- # Dynamically creates methods for each terminal named colour. When a block
86
- # is given, then the colour is reset to 'default' once the block is
87
- # called.
86
+ # Dynamically creates methods for each terminal named colour.
87
+ # When a block is given, then the colour is reset to 'default'
88
+ # once the block is called.
88
89
  #
89
90
  # @return [void]
90
91
  def define_foregrounds!
data/lib/vedeu/esc/esc.rb CHANGED
@@ -4,8 +4,8 @@ require 'vedeu/esc/colours'
4
4
 
5
5
  module Vedeu
6
6
 
7
- # Provides escape sequence strings for setting the cursor position and various
8
- # display related functions.
7
+ # Provides escape sequence strings for setting the cursor position
8
+ # and various display related functions.
9
9
  #
10
10
  module Esc
11
11
 
@@ -14,10 +14,10 @@ module Vedeu
14
14
  include Vedeu::EscapeSequences::Colours
15
15
  extend self
16
16
 
17
- # Return the stream with the escape sequences escaped so that they can be
18
- # printed to the terminal instead of being interpreted by the terminal which
19
- # will render them. This way we can see what escape sequences are being sent
20
- # along with the content.
17
+ # Return the stream with the escape sequences escaped so that they
18
+ # can be printed to the terminal instead of being interpreted by
19
+ # the terminal which will render them. This way we can see what
20
+ # escape sequences are being sent along with the content.
21
21
  #
22
22
  # @param stream [String]
23
23
  # @return [String]
@@ -27,8 +27,9 @@ module Vedeu
27
27
  stream.gsub(/\e/, '\\e')
28
28
  end
29
29
 
30
- # Return the escape sequence string from the list of recognised sequence
31
- # 'commands', or an empty string when the 'command' cannot be found.
30
+ # Return the escape sequence string from the list of recognised
31
+ # sequence 'commands', or an empty string when the 'command'
32
+ # cannot be found.
32
33
  #
33
34
  # @param value [String|Symbol]
34
35
  # @return [String]
@@ -43,8 +44,8 @@ module Vedeu
43
44
  # Return the escape sequence to render a border character.
44
45
  #
45
46
  # @return [String]
46
- # @yieldreturn [void] The border character to wrap with border on and off
47
- # escape sequences.
47
+ # @yieldreturn [void] The border character to wrap with border on
48
+ # and off escape sequences.
48
49
  def border
49
50
  return '' unless block_given?
50
51
 
@@ -0,0 +1,15 @@
1
+ module Vedeu
2
+
3
+ module Input
4
+
5
+ end # Input
6
+
7
+ end # Vedeu
8
+
9
+ require 'vedeu/input/input'
10
+ require 'vedeu/input/key'
11
+ require 'vedeu/input/keymap'
12
+ require 'vedeu/input/keymaps'
13
+ require 'vedeu/input/keys'
14
+ require 'vedeu/input/mapper'
15
+ require 'vedeu/input/translator'
@@ -1,70 +1,73 @@
1
1
  module Vedeu
2
2
 
3
- # Captures input from the user via {Vedeu::Terminal#input} and translates
4
- # special characters into symbols.
5
- #
6
- class Input
3
+ module Input
7
4
 
8
- # Instantiate Input and capture keypress(es).
5
+ # Captures input from the user via {Vedeu::Terminal#input} and
6
+ # translates special characters into symbols.
9
7
  #
10
- # @param (see #initialize)
11
- # @return [String|Symbol]
12
- def self.capture(reader)
13
- new(reader).capture
14
- end
8
+ class Input
15
9
 
16
- # Returns a new instance of Vedeu::Input.
17
- #
18
- # @param reader [IO] An object that responds to `#read`. Typically, this is
19
- # Vedeu::Terminal.
20
- # @return [Vedeu::Input]
21
- def initialize(reader)
22
- @reader = reader
23
- end
24
-
25
- # Triggers either a ':_command_' event with the command when the reader is
26
- # in cooked mode, or when in raw mode, the keypress event with the key(s)
27
- # pressed.
28
- #
29
- # @return [Array|String|Symbol]
30
- def capture
31
- if reader.raw_mode?
32
- Vedeu.trigger(:_keypress_, keypress)
10
+ # Instantiate Vedeu::Input::Input and capture keypress(es).
11
+ #
12
+ # @param (see #initialize)
13
+ # @return [String|Symbol]
14
+ def self.capture(reader)
15
+ new(reader).capture
16
+ end
17
+
18
+ # Returns a new instance of Vedeu::Input::Input.
19
+ #
20
+ # @param reader [IO] An object that responds to `#read`.
21
+ # Typically, this is Vedeu::Terminal.
22
+ # @return [Vedeu::Input::Input]
23
+ def initialize(reader)
24
+ @reader = reader
25
+ end
26
+
27
+ # Triggers either a ':_command_' event with the command when the
28
+ # reader is in cooked mode, or when in raw mode, the keypress
29
+ # event with the key(s) pressed.
30
+ #
31
+ # @return [Array|String|Symbol]
32
+ def capture
33
+ if reader.raw_mode?
34
+ Vedeu.trigger(:_keypress_, keypress)
33
35
 
34
- elsif reader.fake_mode?
35
- Vedeu.trigger(:_editor_, keypress)
36
+ elsif reader.fake_mode?
37
+ Vedeu.trigger(:_editor_, keypress)
36
38
 
37
- else
38
- Vedeu.trigger(:_command_, command)
39
+ else
40
+ Vedeu.trigger(:_command_, command)
39
41
 
42
+ end
40
43
  end
41
- end
42
44
 
43
- protected
45
+ protected
44
46
 
45
- # @!attribute [r] reader
46
- # @return [IO]
47
- attr_reader :reader
47
+ # @!attribute [r] reader
48
+ # @return [IO]
49
+ attr_reader :reader
48
50
 
49
- private
51
+ private
50
52
 
51
- # Returns the translated (when possible) keypress(es) as either a String or
52
- # a Symbol.
53
- #
54
- # @return [String|Symbol]
55
- def keypress
56
- key = input
53
+ # Returns the translated (when possible) keypress(es).
54
+ #
55
+ # @return [String|Symbol]
56
+ def keypress
57
+ key = input
57
58
 
58
- Vedeu::InputTranslator.translate(key)
59
- end
59
+ Vedeu::Input::Translator.translate(key)
60
+ end
60
61
 
61
- # Returns the input from the terminal.
62
- #
63
- # @return [String]
64
- def input
65
- @input ||= reader.read
66
- end
67
- alias_method :command, :input
62
+ # Returns the input from the terminal.
63
+ #
64
+ # @return [String]
65
+ def input
66
+ @input ||= reader.read
67
+ end
68
+ alias_method :command, :input
69
+
70
+ end # Input
68
71
 
69
72
  end # Input
70
73
 
@@ -1,36 +1,42 @@
1
1
  module Vedeu
2
2
 
3
- # A single keypress or combination of keypresses bound to a specific action.
4
- #
5
- class Key
3
+ module Input
6
4
 
7
- # @!attribute [r] input
8
- # @return [String|Symbol] Returns the key defined.
9
- attr_reader :input
10
- alias_method :key, :input
11
-
12
- # Returns a new instance of Vedeu::Key.
13
- #
14
- # @param input [String|Symbol]
15
- # @param block [Proc]
16
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
17
- # @return [Vedeu::Key]
18
- def initialize(input = nil, &block)
19
- fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
20
-
21
- @input = input
22
- @output = block
23
- end
24
-
25
- # Pressing the key will call the procedure.
5
+ # A single keypress or combination of keypresses bound to a
6
+ # specific action.
26
7
  #
27
- # @return [|Symbol]
28
- def output
29
- @output.call
30
- end
31
- alias_method :action, :output
32
- alias_method :press, :output
33
-
34
- end # Key
8
+ class Key
9
+
10
+ # @!attribute [r] input
11
+ # @return [String|Symbol] Returns the key defined.
12
+ attr_reader :input
13
+ alias_method :key, :input
14
+
15
+ # Returns a new instance of Vedeu::Input::Key.
16
+ #
17
+ # @param input [String|Symbol]
18
+ # @param block [Proc]
19
+ # @raise [Vedeu::Error::InvalidSyntax] The required block was
20
+ # not given.
21
+ # @return [Vedeu::Input::Key]
22
+ def initialize(input = nil, &block)
23
+ fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
24
+
25
+ @input = input
26
+ @output = block
27
+ end
28
+
29
+ # Pressing the key will call the procedure.
30
+ #
31
+ # @return [|Symbol]
32
+ def output
33
+ @output.call
34
+ end
35
+ alias_method :action, :output
36
+ alias_method :press, :output
37
+
38
+ end # Key
39
+
40
+ end # Input
35
41
 
36
42
  end # Vedeu
@@ -1,98 +1,107 @@
1
1
  module Vedeu
2
2
 
3
- # A container class for keys associated with a particular interface.
4
- #
5
- class Keymap
3
+ module Input
6
4
 
7
- include Vedeu::Model
8
-
9
- collection Vedeu::Keys
10
- member Vedeu::Key
11
-
12
- # @!attribute [rw] name
13
- # @return [String]
14
- attr_accessor :name
15
-
16
- # Returns a new instance of Vedeu::Keymap.
17
- #
18
- # @param attributes [Hash]
19
- # @option attributes name [String] The name of the keymap.
20
- # @option attributes keys [Vedeu::Keys|Array] A collection of keys.
21
- # @option attributes repository [Vedeu::Repository] This model's storage.
22
- # @return [Vedeu::Keymap]
23
- def initialize(attributes = {})
24
- @attributes = defaults.merge!(attributes)
25
-
26
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
27
- end
28
-
29
- # Add a key to the keymap.
30
- #
31
- # @param key [Vedeu::Key]
32
- # @return [void]
33
- def add(key)
34
- return false unless valid?(key)
35
-
36
- @keys = keys.add(key)
37
- end
38
-
39
- # Returns the collection of keys defined for this keymap.
40
- #
41
- # @return [Vedeu::Keys]
42
- def keys
43
- collection.coerce(@keys, self)
44
- end
45
-
46
- # Check whether the key is already defined for this keymap.
47
- #
48
- # @param input [String|Symbol]
49
- # @return [Boolean] A boolean indicating the input provided is already in
50
- # use for this keymap.
51
- def key_defined?(input)
52
- keys.any? { |key| key.input == input }
53
- end
54
-
55
- # When the given input is registered with this keymap, this method triggers
56
- # the action associated with the key.
5
+ # A container class for keys associated with a particular interface.
57
6
  #
58
- # @param input [String|Symbol]
59
- # @return [Array|FalseClass]
60
- def use(input)
61
- return false unless key_defined?(input)
62
-
63
- Vedeu.log(type: :input, message: "Key pressed: '#{input}'")
64
-
65
- Vedeu.trigger(:key, input)
66
-
67
- keys.select { |key| key.input == input }.map(&:press)
68
- end
69
-
70
- private
71
-
72
- # Returns the default options/attributes for this class.
73
- #
74
- # @return [Hash]
75
- def defaults
76
- {
77
- name: '',
78
- keys: [],
79
- repository: Vedeu::Keymaps.keymaps,
80
- }
81
- end
82
-
83
- # Checks that the provided key is not already registered with this keymap.
84
- #
85
- # @param key [Vedeu::Key]
86
- # @return [Boolean]
87
- def valid?(key)
88
- return true unless key_defined?(key.input)
89
-
90
- Vedeu.log(type: :input,
91
- message: "Keymap '#{name}' already defines '#{key.input}'.")
92
-
93
- false
94
- end
95
-
96
- end # Keymap
7
+ class Keymap
8
+
9
+ include Vedeu::Model
10
+
11
+ collection Vedeu::Input::Keys
12
+ member Vedeu::Input::Key
13
+
14
+ # @!attribute [rw] name
15
+ # @return [String]
16
+ attr_accessor :name
17
+
18
+ # Returns a new instance of Vedeu::Input::Keymap.
19
+ #
20
+ # @param attributes [Hash]
21
+ # @option attributes name [String] The name of the keymap.
22
+ # @option attributes keys [Vedeu::Input::Keys|Array]
23
+ # A collection of keys.
24
+ # @option attributes repository [Vedeu::Repository]
25
+ # This model's storage.
26
+ # @return [Vedeu::Input::Keymap]
27
+ def initialize(attributes = {})
28
+ @attributes = defaults.merge!(attributes)
29
+
30
+ @attributes.each do |key, value|
31
+ instance_variable_set("@#{key}", value)
32
+ end
33
+ end
34
+
35
+ # Add a key to the keymap.
36
+ #
37
+ # @param key [Vedeu::Input::Key]
38
+ # @return [void]
39
+ def add(key)
40
+ return false unless valid?(key)
41
+
42
+ @keys = keys.add(key)
43
+ end
44
+
45
+ # Returns the collection of keys defined for this keymap.
46
+ #
47
+ # @return [Vedeu::Input::Keys]
48
+ def keys
49
+ collection.coerce(@keys, self)
50
+ end
51
+
52
+ # Check whether the key is already defined for this keymap.
53
+ #
54
+ # @param input [String|Symbol]
55
+ # @return [Boolean] A boolean indicating the input provided is
56
+ # already in use for this keymap.
57
+ def key_defined?(input)
58
+ keys.any? { |key| key.input == input }
59
+ end
60
+
61
+ # When the given input is registered with this keymap, this method
62
+ # triggers the action associated with the key.
63
+ #
64
+ # @param input [String|Symbol]
65
+ # @return [Array|FalseClass]
66
+ def use(input)
67
+ return false unless key_defined?(input)
68
+
69
+ Vedeu.log(type: :input, message: "Key pressed: '#{input}'")
70
+
71
+ Vedeu.trigger(:key, input)
72
+
73
+ keys.select { |key| key.input == input }.map(&:press)
74
+ end
75
+
76
+ private
77
+
78
+ # Returns the default options/attributes for this class.
79
+ #
80
+ # @return [Hash]
81
+ def defaults
82
+ {
83
+ name: '',
84
+ keys: [],
85
+ repository: Vedeu::Input::Keymaps.keymaps,
86
+ }
87
+ end
88
+
89
+ # Checks that the provided key is not already registered with this
90
+ # keymap.
91
+ #
92
+ # @param key [Vedeu::Input::Key]
93
+ # @return [Boolean]
94
+ def valid?(key)
95
+ return true unless key_defined?(key.input)
96
+
97
+ Vedeu.log(type: :input,
98
+ message: "Keymap '#{name}' already defines '#{key.input}'.")
99
+
100
+ false
101
+ end
102
+
103
+ end # Keymap
104
+
105
+ end # Input
97
106
 
98
107
  end # Vedeu
@@ -1,13 +1,17 @@
1
1
  module Vedeu
2
2
 
3
- # Allows the storing of keymaps.
4
- #
5
- class Keymaps < Vedeu::Repository
3
+ module Input
6
4
 
7
- singleton_class.send(:alias_method, :keymaps, :repository)
5
+ # Allows the storing of keymaps.
6
+ #
7
+ class Keymaps < Vedeu::Repository
8
8
 
9
- real Vedeu::Keymap
9
+ singleton_class.send(:alias_method, :keymaps, :repository)
10
10
 
11
- end # Keymaps
11
+ real Vedeu::Input::Keymap
12
+
13
+ end # Keymaps
14
+
15
+ end # Input
12
16
 
13
17
  end # Vedeu
@@ -1,9 +1,13 @@
1
1
  module Vedeu
2
2
 
3
- # A collection of {Vedeu::Key} instances.
4
- #
5
- class Keys < Vedeu::Collection
3
+ module Input
6
4
 
7
- end # Keys
5
+ # A collection of {Vedeu::Input::Key} instances.
6
+ #
7
+ class Keys < Vedeu::Collection
8
+
9
+ end # Keys
10
+
11
+ end # Input
8
12
 
9
13
  end # Vedeu