vedeu 0.6.39 → 0.6.40

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba1c61c6e18c58f67aa29538d0f7c7765199fad5
4
- data.tar.gz: 82dc0fd7e7f3c65bff2fa207d6103cf8784ada1f
3
+ metadata.gz: 143043509ebfddd83c874d02592cc32490dcd663
4
+ data.tar.gz: 05f8618fb7ab1f6a88ac7221794967bd58307022
5
5
  SHA512:
6
- metadata.gz: b53f28b9940e7f4cb175adec72115203635cceaab007d13f134fca09d39b426fd06fe95ee2526c8a4f6bac591672b40f4217c1fcedfc409e5506c7aad67ff52b
7
- data.tar.gz: e05e316be1c418cde5c71c4b2d1bfe5b58ac5a119ceeb5bad4b2227c0e83857c9a4586b1fb1b5e6fde1c440f82c081707bfa798b317eef3808e44e5c3e10c9e1
6
+ metadata.gz: 95e3e2d995ff6aa700a07e17dd8f462ad412b8df1d17c6a74f0a773e1ca0ef6dabe4100e526bf9c9e9860d3cc440968717c1667c0ded6fe3939857bcdd1d5860
7
+ data.tar.gz: 45022ead54702e4ce916c0e057cd78d2987c507cd41223a11f2988a254faf200a851739f96b77e4deb81c01b0a5023b30e77afadd6ba7dc259abd9c5c4f98875
@@ -11,11 +11,25 @@ popular here.
11
11
  Vedeu.trigger(:_exit_)
12
12
 
13
13
  ### `:\_command\_`
14
+ This event is used by Vedeu internally, though you can bind to it if
15
+ you wish. It is preferred for you to bind to `:command` though.
16
+
14
17
  Will cause the triggering of the `:command` event; which you should
15
18
  define to 'do things'.
16
19
 
17
20
  Vedeu.trigger(:_command_, command)
18
21
 
22
+ Vedeu.bind(:command) do
23
+ # ... your code here ...
24
+ end
25
+
26
+ Alternatively, you can access commands entered using the following
27
+ API methods: (See {Vedeu::Input::Store} for more details).
28
+
29
+ Vedeu.all_commands
30
+
31
+ Vedeu.last_command
32
+
19
33
  ### `:\_editor\_`
20
34
  This event is called by {Vedeu::Input::Capture#read}. When
21
35
  invoked, the key will be passed to the editor for currently
@@ -41,6 +55,9 @@ action(s), like render the first screen, interface or make a sound.
41
55
  Vedeu.trigger(:_initialize_)
42
56
 
43
57
  ### `:\_keypress\_`
58
+ This event is used by Vedeu internally, though you can bind to it if
59
+ you wish. It is preferred for you to bind to `:key` though.
60
+
44
61
  When the name is given:
45
62
 
46
63
  - The given key is passed to the named keymap. If the keymap is
@@ -62,6 +79,17 @@ It is also to be noted, that a `:key` event will be triggered
62
79
  irrespective of the conditions above, you can bind to this event
63
80
  separately to 'do things'.
64
81
 
82
+ Vedeu.bind(:key) do
83
+ # ... your code here ...
84
+ end
85
+
86
+ Alternatively, you can access keypresses entered using the following
87
+ API methods: (See {Vedeu::Input::Store} for more details).
88
+
89
+ Vedeu.all_keypresses
90
+
91
+ Vedeu.last_keypress
92
+
65
93
  A list of supported keypresses can be found here:
66
94
  {Vedeu::Input::Capture}.
67
95
 
@@ -8,6 +8,7 @@ class EditorApp
8
8
  Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
9
9
 
10
10
  Vedeu.configure do
11
+ debug!
11
12
  log '/tmp/editor.log'
12
13
  renderers Vedeu::Renderers::File.new(filename: '/tmp/editor.out')
13
14
  fake!
@@ -35,15 +36,22 @@ class EditorApp
35
36
  # When pressing Return/Enter in the editor view, the :_command_
36
37
  # event will be triggered with any typed content you have provided.
37
38
  #
38
- # Bind to this event to retrieve the content entered, and then
39
- # process yourself in whatever way appropriate.
39
+ # The :_command_ event in turn triggers the :command event. Bind to
40
+ # :command to retrieve the content entered, and then process
41
+ # yourself in whatever way appropriate.
40
42
  #
41
- # Vedeu.bind(:_command_) do |data|
43
+ # Vedeu.bind(:command) do |data|
42
44
  # # ... do something with 'data'
43
45
  # end
44
46
  #
45
47
  Vedeu.keymap :editor_view do
46
48
  key(:enter) { Vedeu.trigger(:_editor_execute_, :editor_view) }
49
+ key(:insert) do
50
+ Vedeu.log(type: :debug,
51
+ message: "Commands: #{Vedeu.all_commands.inspect}")
52
+ Vedeu.log(type: :debug,
53
+ message: "Keypresses: #{Vedeu.all_keypresses.inspect}")
54
+ end
47
55
  end
48
56
 
49
57
  Vedeu.keymap '_global_' do
@@ -60,7 +68,7 @@ class EditorApp
60
68
  lines do
61
69
  line 'Type into the editor dialog above,'
62
70
  line 'and press Return. This will trigger the'
63
- line ':_command_ event with the contents of '
71
+ line ':command event with the contents of '
64
72
  line 'the view.'
65
73
 
66
74
  # @todo Not implemented yet:
@@ -155,7 +155,11 @@ module Vedeu
155
155
  # :nocov:
156
156
 
157
157
  # See {file:docs/events/system.md#\_keypress_}
158
- Vedeu.bind(:_keypress_) { |key, name| Vedeu.keypress(key, name) }
158
+ Vedeu.bind(:_keypress_) do |key, name|
159
+ Vedeu.add_keypress(key)
160
+
161
+ Vedeu.keypress(key, name)
162
+ end
159
163
 
160
164
  # See {file:docs/events/drb.md#\_drb_input_}
161
165
  Vedeu.bind(:_drb_input_) do |data, type|
@@ -169,7 +173,11 @@ module Vedeu
169
173
  end
170
174
 
171
175
  # See {file:docs/events/system.md#\_command_}
172
- Vedeu.bind(:_command_) { |command| Vedeu.trigger(:command, command) }
176
+ Vedeu.bind(:_command_) do |command|
177
+ Vedeu.add_command(command)
178
+
179
+ Vedeu.trigger(:command, command)
180
+ end
173
181
 
174
182
  # :nocov:
175
183
 
@@ -4,46 +4,89 @@ module Vedeu
4
4
 
5
5
  # Stores each keypress or command to be retrieved later.
6
6
  #
7
- class Store
8
-
9
- def initialize
10
- end
11
-
7
+ module Store
8
+
9
+ extend self
10
+
11
+ # Add a command (a collection of characters/keypresses from an
12
+ # Editor::Document) to the store. Used by Vedeu internally to
13
+ # store commands entered.
14
+ #
15
+ # @example
16
+ # Vedeu.add_command(:some_command)
17
+ #
18
+ # @param command [Symbol|String]
12
19
  # @return [Hash<Symbol => Array<Symbol|String>>]
13
20
  def add_command(command)
14
21
  all_commands << command
15
22
  end
16
23
 
24
+ # Add a keypress to the store. Used by Vedeu internally to
25
+ # store a keypress entered.
26
+ #
27
+ # @example
28
+ # Vedeu.add_keypress(:escape)
29
+ #
30
+ # @param keypress [Symbol|String]
17
31
  # @return [Hash<Symbol => Array<Symbol|String>>]
18
32
  def add_keypress(keypress)
19
33
  all_keypresses << keypress
20
34
  end
21
35
 
36
+ # Access all commands and keypresses stored.
37
+ #
22
38
  # @return [Hash<Symbol => Array<Symbol|String>>]
23
39
  def all
24
40
  storage
25
41
  end
26
42
 
43
+ # Access all commands stored.
44
+ #
45
+ # @example
46
+ # Vedeu.all_commands
47
+ #
27
48
  # @return [Array<Symbol|String>]
28
49
  def all_commands
29
50
  storage[:commands]
30
51
  end
31
52
 
53
+ # Access all keypresses stored.
54
+ #
55
+ # @example
56
+ # Vedeu.all_keypresses
57
+ #
32
58
  # @return [Array<Symbol|String>]
33
59
  def all_keypresses
34
60
  storage[:keypresses]
35
61
  end
36
62
 
63
+ # Access the last command stored. If no commands have been
64
+ # entered since the client application started, then this will
65
+ # return nil.
66
+ #
67
+ # @example
68
+ # Vedeu.last_command
69
+ #
37
70
  # @return [NilClass|Symbol|String]
38
71
  def last_command
39
72
  all_commands[-1]
40
73
  end
41
74
 
75
+ # Access the last keypress stored. If no keys have been pressed
76
+ # since the client application started, then this will return
77
+ # nil.
78
+ #
79
+ # @example
80
+ # Vedeu.last_keypress
81
+ #
42
82
  # @return [NilClass|Symbol|String]
43
83
  def last_keypress
44
84
  all_keypresses[-1]
45
85
  end
46
86
 
87
+ # Remove all stored entries. Any commands or keypresses entered
88
+ # before calling this method will be removed.
89
+ #
47
90
  # @return [Hash<Symbol => Array<Symbol|String>>]
48
91
  def reset
49
92
  @storage = in_memory
@@ -68,4 +111,24 @@ module Vedeu
68
111
 
69
112
  end # Input
70
113
 
114
+ # @!method add_command
115
+ # @see Vedeu::Input::Store.add_command
116
+ # @!method add_keypress
117
+ # @see Vedeu::Input::Store.add_keypress
118
+ # @!method all_commands
119
+ # @see Vedeu::Input::Store.all_commands
120
+ # @!method all_keypresses
121
+ # @see Vedeu::Input::Store.all_keypresses
122
+ # @!method last_command
123
+ # @see Vedeu::Input::Store.last_command
124
+ # @!method last_keypress
125
+ # @see Vedeu::Input::Store.last_keypress
126
+ def_delegators Vedeu::Input::Store,
127
+ :add_command,
128
+ :add_keypress,
129
+ :all_commands,
130
+ :all_keypresses,
131
+ :last_command,
132
+ :last_keypress
133
+
71
134
  end # Vedeu
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.39'.freeze
4
+ VERSION = '0.6.40'.freeze
5
5
 
6
6
  end
@@ -7,14 +7,13 @@ module Vedeu
7
7
  describe Store do
8
8
 
9
9
  let(:described) { Vedeu::Input::Store }
10
- let(:instance) { described.new }
11
10
 
12
- before { instance.reset }
11
+ before { described.reset }
13
12
 
14
13
  describe '#add_command' do
15
14
  let(:command) { 'command_1' }
16
15
 
17
- subject { instance.add_command(command) }
16
+ subject { described.add_command(command) }
18
17
 
19
18
  it { subject.must_equal(['command_1']) }
20
19
  end
@@ -22,13 +21,13 @@ module Vedeu
22
21
  describe '#add_keypress' do
23
22
  let(:keypress) { 'a' }
24
23
 
25
- subject { instance.add_keypress(keypress) }
24
+ subject { described.add_keypress(keypress) }
26
25
 
27
26
  it { subject.must_equal(['a']) }
28
27
  end
29
28
 
30
29
  describe '#all' do
31
- subject { instance.all }
30
+ subject { described.all }
32
31
 
33
32
  context 'when empty' do
34
33
  it { subject.must_equal({ commands: [], keypresses: [] }) }
@@ -43,10 +42,10 @@ module Vedeu
43
42
  }
44
43
 
45
44
  before do
46
- instance.add_command('command_1')
47
- instance.add_command('command_2')
48
- instance.add_keypress('a')
49
- instance.add_keypress('b')
45
+ described.add_command('command_1')
46
+ described.add_command('command_2')
47
+ described.add_keypress('a')
48
+ described.add_keypress('b')
50
49
  end
51
50
 
52
51
  it { subject.must_equal(expected) }
@@ -54,7 +53,7 @@ module Vedeu
54
53
  end
55
54
 
56
55
  describe '#all_commands' do
57
- subject { instance.all_commands }
56
+ subject { described.all_commands }
58
57
 
59
58
  context 'when there are no stored commands' do
60
59
  it { subject.must_equal([]) }
@@ -62,9 +61,9 @@ module Vedeu
62
61
 
63
62
  context 'when there are stored commands' do
64
63
  before do
65
- instance.add_command('command_1')
66
- instance.add_command('command_2')
67
- instance.add_command('command_3')
64
+ described.add_command('command_1')
65
+ described.add_command('command_2')
66
+ described.add_command('command_3')
68
67
  end
69
68
 
70
69
  it { subject.must_equal(['command_1', 'command_2', 'command_3']) }
@@ -72,7 +71,7 @@ module Vedeu
72
71
  end
73
72
 
74
73
  describe '#all_keypresses' do
75
- subject { instance.all_keypresses }
74
+ subject { described.all_keypresses }
76
75
 
77
76
  context 'when there are no stored keypresses' do
78
77
  it { subject.must_equal([]) }
@@ -80,9 +79,9 @@ module Vedeu
80
79
 
81
80
  context 'when there are stored keypresses' do
82
81
  before do
83
- instance.add_keypress('a')
84
- instance.add_keypress('b')
85
- instance.add_keypress('c')
82
+ described.add_keypress('a')
83
+ described.add_keypress('b')
84
+ described.add_keypress('c')
86
85
  end
87
86
 
88
87
  it { subject.must_equal(['a', 'b', 'c']) }
@@ -90,7 +89,7 @@ module Vedeu
90
89
  end
91
90
 
92
91
  describe '#last_command' do
93
- subject { instance.last_command }
92
+ subject { described.last_command }
94
93
 
95
94
  context 'when there are no stored commands' do
96
95
  it { subject.must_equal(nil) }
@@ -98,9 +97,9 @@ module Vedeu
98
97
 
99
98
  context 'when there are stored commands' do
100
99
  before do
101
- instance.add_command('command_1')
102
- instance.add_command('command_2')
103
- instance.add_command('command_3')
100
+ described.add_command('command_1')
101
+ described.add_command('command_2')
102
+ described.add_command('command_3')
104
103
  end
105
104
 
106
105
  it { subject.must_equal('command_3') }
@@ -108,7 +107,7 @@ module Vedeu
108
107
  end
109
108
 
110
109
  describe '#last_keypress' do
111
- subject { instance.last_keypress }
110
+ subject { described.last_keypress }
112
111
 
113
112
  context 'when there are no stored keypresses' do
114
113
  it { subject.must_equal(nil) }
@@ -116,9 +115,9 @@ module Vedeu
116
115
 
117
116
  context 'when there are stored keypresses' do
118
117
  before do
119
- instance.add_keypress('a')
120
- instance.add_keypress('b')
121
- instance.add_keypress('c')
118
+ described.add_keypress('a')
119
+ described.add_keypress('b')
120
+ described.add_keypress('c')
122
121
  end
123
122
 
124
123
  it { subject.must_equal('c') }
@@ -126,7 +125,7 @@ module Vedeu
126
125
  end
127
126
 
128
127
  describe '#reset' do
129
- subject { instance.reset }
128
+ subject { described.reset }
130
129
 
131
130
  it { subject.must_equal({ commands: [], keypresses: [] }) }
132
131
  end
@@ -2,6 +2,10 @@ require 'test_helper'
2
2
 
3
3
  describe Vedeu do
4
4
 
5
+ it { Vedeu.must_respond_to(:add_command) }
6
+ it { Vedeu.must_respond_to(:add_keypress) }
7
+ it { Vedeu.must_respond_to(:all_commands) }
8
+ it { Vedeu.must_respond_to(:all_keypresses) }
5
9
  it { Vedeu.must_respond_to(:background_colours) }
6
10
  it { Vedeu.must_respond_to(:bind) }
7
11
  it { Vedeu.must_respond_to(:bind_alias) }
@@ -51,6 +55,8 @@ describe Vedeu do
51
55
  it { Vedeu.must_respond_to(:keymap) }
52
56
  it { Vedeu.must_respond_to(:keymaps) }
53
57
  it { Vedeu.must_respond_to(:keypress) }
58
+ it { Vedeu.must_respond_to(:last_command) }
59
+ it { Vedeu.must_respond_to(:last_keypress) }
54
60
  it { Vedeu.must_respond_to(:log) }
55
61
  it { Vedeu.must_respond_to(:log_stderr) }
56
62
  it { Vedeu.must_respond_to(:log_stdout) }
@@ -110,6 +110,13 @@ class VedeuMaterialColoursApp
110
110
  key(:home) { Vedeu.trigger(:_cursor_top_) }
111
111
  key(:end) { Vedeu.trigger(:_cursor_bottom_) }
112
112
 
113
+ key(:insert) do
114
+ Vedeu.log(type: :debug,
115
+ message: "Commands: #{Vedeu.all_commands.inspect}")
116
+ Vedeu.log(type: :debug,
117
+ message: "Keypresses: #{Vedeu.all_keypresses.inspect}")
118
+ end
119
+
113
120
  key('q') { Vedeu.trigger(:_exit_) }
114
121
  key(:escape) { Vedeu.trigger(:_mode_switch_) }
115
122
  key(:shift_tab) { Vedeu.trigger(:_focus_prev_) }
data/vedeu.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'guard', '2.13.0'
24
24
  spec.add_development_dependency 'guard-minitest', '2.4.4'
25
25
  spec.add_development_dependency 'guard-rubocop', '1.2.0'
26
- spec.add_development_dependency 'minitest', '5.8.1'
26
+ spec.add_development_dependency 'minitest', '5.8.2'
27
27
  spec.add_development_dependency 'minitest-reporters', '1.1.4'
28
28
  spec.add_development_dependency 'mocha', '1.1.0'
29
29
  spec.add_development_dependency 'pry', '0.10.3'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.39
4
+ version: 0.6.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 5.8.1
61
+ version: 5.8.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 5.8.1
68
+ version: 5.8.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest-reporters
71
71
  requirement: !ruby/object:Gem::Requirement