vedeu 0.6.65 → 0.6.66

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: b7de5e8ce3c945a022377f002d55b636db36d4c4
4
- data.tar.gz: 304a938cd7a728def2501a2fbb9c56dc47087c69
3
+ metadata.gz: d3296c4a873190f0059f2603ddce098130fa4ac3
4
+ data.tar.gz: 00cdbf96d644568b7eb6d4cd783b82ab315289d3
5
5
  SHA512:
6
- metadata.gz: 5319814ddc77d021cc4b9d6c0faeaf0dee1dfbad8fda6aed11999ed3e596ee304dd25c24155aff10968d5a48112ecfff371d8a7b58fd370fc2ee9195444570ba
7
- data.tar.gz: 51b151afec06d804cbf24e0a7cf490b434e8d0130d5c993a74e80e93734c22ba00cec0908696fd1bb4d2ce36e6e943a487e7742bdc9b21788ad34476662243fa
6
+ metadata.gz: 9aed24c7e9953e07e443f4183302086010241f6c626934ecd178b8e0416ce82c2ace9c645eb2a670d66051104f3e7af6418ca37d072deac44c6f15540ec6392b
7
+ data.tar.gz: bc86d7cfad0485d4912fb7a4d04c9e485c34f44e064013a5976b32d6352fa8c751d007030776494e6668eb8e4bbe49f2779c05ac37fcd4876baf13bdd19fd44c
data/docs/api.md CHANGED
@@ -146,10 +146,14 @@ See {file:docs/events.md}
146
146
 
147
147
  ### Vedeu.all_commands
148
148
 
149
+ Returns an array of all commands received by Vedeu.
150
+
149
151
  @todo Add more documentation.
150
152
 
151
153
  ### Vedeu.all_keypresses
152
154
 
155
+ Returns an array of all keypresses received by Vedeu.
156
+
153
157
  @todo Add more documentation.
154
158
 
155
159
  ### Vedeu.background_colours
@@ -383,10 +387,14 @@ Repository method. Access registered keymaps.
383
387
 
384
388
  ### Vedeu.last_command
385
389
 
390
+ Returns the last command entered into Vedeu.
391
+
386
392
  @todo Add more documentation.
387
393
 
388
394
  ### Vedeu.last_keypress
389
395
 
396
+ Returns the last keypress entered into Vedeu.
397
+
390
398
  @todo Add more documentation.
391
399
 
392
400
  ### Vedeu.log
@@ -419,7 +427,36 @@ Repository method. Access registered menus.
419
427
 
420
428
  ### Vedeu.read
421
429
 
422
- @todo Add more documentation.
430
+ This allows the direct reading from the terminal, unencumbered by the
431
+ framework.
432
+
433
+ Vedeu.read("some input here") # => programmatic cooked mode
434
+ # (default)
435
+
436
+ Vedeu.read("\e[24;2~", mode: :raw) # => programmatic raw mode
437
+ # (provides :shift_f12 in
438
+ # this example)
439
+
440
+ Vedeu.read(nil, mode: :raw) # => for a single keypress
441
+
442
+ Vedeu.read(nil, mode: :cooked) # => (default mode) for a 'line at
443
+ # a time' (pressing 'return'
444
+ # ends the line)
445
+
446
+ The way that these are used will depend on the mode your terminal is currently set to. Vedeu by default sets this to `:raw` (single character, hidden cursor). `Vedeu.read` by default expects the terminal to be in `:cooked` mode unless you provide the `mode: :raw` option.
447
+
448
+ - In `:cooked` mode (default), it will trigger a `:_command_` event
449
+ with the input provided, meaning you should bind to :command to
450
+ receive the input.
451
+ - In `:raw` mode, it will trigger a `:_keypress_` event with the input
452
+ provided, meaning you should bind to `:key` to receive the input.
453
+
454
+ You can also access the input given using the API methods:
455
+
456
+ Vedeu.all_commands
457
+ Vedeu.all_keypresses
458
+ Vedeu.last_command
459
+ Vedeu.last_keypress
423
460
 
424
461
  ### Vedeu.ready!
425
462
 
@@ -513,4 +550,7 @@ Repository method. Access registered renderers.
513
550
 
514
551
  ### Vedeu.write
515
552
 
553
+ This allows the direct writing to the terminal, unencumbered by the
554
+ framework.
555
+
516
556
  @todo Add more documentation.
data/docs/dsl.md CHANGED
@@ -78,6 +78,10 @@ end
78
78
 
79
79
  {include:Vedeu::Borders::DSL}
80
80
 
81
+ ### Creating a new named border
82
+
83
+ {include:Vedeu::Borders::DSL#border}
84
+
81
85
  ### Setting a title for the border
82
86
 
83
87
  {include:Vedeu::Borders::DSL#title}
@@ -107,6 +111,10 @@ end
107
111
 
108
112
  {include:Vedeu::Geometries::DSL}
109
113
 
114
+ ### Creating a new named geometry
115
+
116
+ {include:Vedeu::Geometries::DSL#geometry}
117
+
110
118
  ### Setting the interface dimensions
111
119
 
112
120
  {include:Vedeu::Geometries::DSL#align}
@@ -131,16 +139,23 @@ end
131
139
 
132
140
  {include:Vedeu::Groups::DSL}
133
141
 
134
- ### Add interfaces to groups
142
+ ### Creating a new named group
135
143
 
136
144
  {include:Vedeu::Groups::DSL.group}
137
145
 
146
+ ### Add interfaces to groups
147
+
148
+ {include:Vedeu::Groups::DSL#add}
149
+
138
150
  ## Keymaps
139
151
 
140
152
  {include:Vedeu::Input::DSL}
141
- {include:Vedeu::Input::DSL.keymap}
142
153
  {include:Vedeu::Input::DSL#name}
143
154
 
155
+ ### Creating a new named group
156
+
157
+ {include:Vedeu::Input::DSL.keymap}
158
+
144
159
  ## Menus
145
160
 
146
161
  {include:Vedeu::Menus::DSL}
@@ -148,6 +163,10 @@ end
148
163
  {include:Vedeu::Menus::DSL#items}
149
164
  {include:Vedeu::Menus::DSL#name}
150
165
 
166
+ ### Creating a new named menu
167
+
168
+ {include:Vedeu::Menus::DSL.menu}
169
+
151
170
  ## Views
152
171
 
153
172
  {include:Vedeu::DSL::View}
data/docs/input.md CHANGED
@@ -124,3 +124,26 @@ Accessing the input can be achieved in the following ways:
124
124
  Vedeu.bind(:command) do
125
125
  # ... do something with the command
126
126
  end
127
+
128
+ ## Providing Input
129
+
130
+ Input can be provided in a couple of ways, automatic and manually.
131
+
132
+ ### Automatically
133
+
134
+ Dependent on the terminal mode as mentioned previously.
135
+
136
+ - In `:raw` mode, a keypress (a single character e.g. `b`, or
137
+ modifier+character e.g. Shift+F12), can be bound via the keymaps
138
+ functionality.
139
+ - In `:cooked` mode, a group of keypresses, terminated with the
140
+ `return` key will trigger the `:command` event which you can bind to
141
+ and perform actions dependent on the input provided.
142
+ - In `:fake` mode, Vedeu emulates the terminal allowing you all the
143
+ benefits of `:cooked` mode but with Vedeu's in-built editor. The
144
+ input can be accessed using the API calls as mentioned in
145
+ {file:docs/input.md#accessing_input}.
146
+
147
+ ### Manually (semi-automatic)
148
+
149
+ See {file:docs/api.md#vedeuread}
@@ -9,6 +9,7 @@ module Vedeu
9
9
 
10
10
  end # Vedeu
11
11
 
12
+ require 'vedeu/input/raw'
12
13
  require 'vedeu/input/capture'
13
14
  require 'vedeu/input/dsl'
14
15
  require 'vedeu/input/key'
@@ -91,13 +91,7 @@ module Vedeu
91
91
  #
92
92
  # @return [String]
93
93
  def input
94
- keys = console.getch
95
-
96
- if keys.ord == Vedeu::ESCAPE_KEY_CODE
97
- keys << console.read_nonblock(4) rescue nil
98
- keys << console.read_nonblock(3) rescue nil
99
- keys << console.read_nonblock(2) rescue nil
100
- end
94
+ keys = Vedeu::Input::Raw.read
101
95
 
102
96
  return Vedeu::Input::Mouse.click(keys) if click?(keys)
103
97
 
@@ -0,0 +1,41 @@
1
+ module Vedeu
2
+
3
+ module Input
4
+
5
+ class Raw
6
+
7
+ # @see Vedeu::Input::Raw#initialize
8
+ def self.read
9
+ new.read
10
+ end
11
+
12
+ # Returns a new instance of Vedeu::Input::Raw.
13
+ #
14
+ # @return [Vedeu::Input::Raw]
15
+ def initialize; end
16
+
17
+ # @return [String]
18
+ def read
19
+ keys = console.getch
20
+
21
+ if keys.ord == Vedeu::ESCAPE_KEY_CODE
22
+ keys << console.read_nonblock(4) rescue nil
23
+ keys << console.read_nonblock(3) rescue nil
24
+ keys << console.read_nonblock(2) rescue nil
25
+ end
26
+
27
+ keys
28
+ end
29
+
30
+ private
31
+
32
+ # @return [IO]
33
+ def console
34
+ @console ||= Vedeu::Terminal.console
35
+ end
36
+
37
+ end # Raw
38
+
39
+ end # Input
40
+
41
+ end # Vedeu
@@ -77,13 +77,7 @@ module Vedeu
77
77
  console.gets.chomp
78
78
 
79
79
  else
80
- keys = console.getch
81
-
82
- if keys.ord == Vedeu::ESCAPE_KEY_CODE
83
- keys << console.read_nonblock(4) rescue nil
84
- keys << console.read_nonblock(3) rescue nil
85
- keys << console.read_nonblock(2) rescue nil
86
- end
80
+ keys = Vedeu::Input::Raw.read
87
81
 
88
82
  Vedeu::Input::Translator.translate(keys)
89
83
 
@@ -137,11 +137,11 @@ module Vedeu
137
137
  Vedeu.timer("Optimised clearing #{clearing}: '#{name}'".freeze) do
138
138
  height.times.map do |iy|
139
139
  [
140
- Vedeu::Geometries::Position.new(y + iy, x).to_s,
140
+ position(y + iy, x),
141
141
  colour.to_s,
142
142
  chars,
143
143
  ].join
144
- end.join + Vedeu::Geometries::Position.new(y, x).to_s
144
+ end.join + position(y, x)
145
145
  end
146
146
  end
147
147
 
@@ -175,6 +175,11 @@ module Vedeu
175
175
  end
176
176
  end
177
177
 
178
+ # @return [Vedeu::Geometries::Position]
179
+ def position(pos_y, pos_x)
180
+ Vedeu::Geometries::Position.new(pos_y, pos_x).to_s
181
+ end
182
+
178
183
  # @return [Fixnum]
179
184
  def width
180
185
  @width ||= if content_only?
@@ -18,14 +18,9 @@ module Vedeu
18
18
  # @return [Array<void>]
19
19
  def clear
20
20
  storage.map do |renderer|
21
- Vedeu.log(type: :render,
22
- message: "Clearing via #{renderer.class.name}".freeze)
21
+ log('Clearing', renderer)
23
22
 
24
- Thread.new(renderer) do
25
- mutex.synchronize do
26
- toggle_cursor { renderer.clear }
27
- end
28
- end
23
+ threaded(renderer) { renderer.clear }
29
24
  end.each(&:join) if Vedeu.ready?
30
25
 
31
26
  ''
@@ -51,14 +46,9 @@ module Vedeu
51
46
  # @return [Array<void>]
52
47
  def render(output)
53
48
  storage.map do |renderer|
54
- Vedeu.log(type: :render,
55
- message: "Rendering via #{renderer.class.name}".freeze)
49
+ log('Rendering', renderer)
56
50
 
57
- Thread.new(renderer) do
58
- mutex.synchronize do
59
- toggle_cursor { renderer.render(output) }
60
- end
61
- end
51
+ threaded(renderer) { renderer.render(output) }
62
52
  end.each(&:join) if Vedeu.ready?
63
53
 
64
54
  output
@@ -96,6 +86,14 @@ module Vedeu
96
86
  Set.new
97
87
  end
98
88
 
89
+ # @param message [String]
90
+ # @param renderer [Class]
91
+ # @return [void]
92
+ def log(message, renderer)
93
+ Vedeu.log(type: :render,
94
+ message: "#{message} via #{renderer.class.name}".freeze)
95
+ end
96
+
99
97
  # @return [Mutex]
100
98
  def mutex
101
99
  @mutex ||= Mutex.new
@@ -106,6 +104,17 @@ module Vedeu
106
104
  @storage ||= in_memory
107
105
  end
108
106
 
107
+ # @return [void]
108
+ def threaded(renderer)
109
+ Thread.new(renderer) do
110
+ mutex.synchronize do
111
+ toggle_cursor do
112
+ yield
113
+ end
114
+ end
115
+ end
116
+ end
117
+
109
118
  # @return [void]
110
119
  def toggle_cursor
111
120
  Vedeu.trigger(:_hide_cursor_)
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.65'.freeze
4
+ VERSION = '0.6.66'.freeze
5
5
 
6
6
  end
@@ -48,8 +48,9 @@ module Vedeu
48
48
  let(:registered) { false }
49
49
 
50
50
  before do
51
- Vedeu::Terminal.console.stubs(:getch).returns(keypress)
52
- Vedeu::Input::Mapper.stubs(:registered?).with(translated, _name).returns(registered)
51
+ Vedeu::Input::Raw.stubs(:read).returns(keypress)
52
+ Vedeu::Input::Mapper.stubs(:registered?).with(translated, _name)
53
+ .returns(registered)
53
54
  Vedeu.interfaces.stubs(:by_name).returns(interface)
54
55
  end
55
56
 
@@ -157,9 +158,7 @@ module Vedeu
157
158
  context 'when the terminal mode is :raw' do
158
159
  let(:is_raw_mode) { true }
159
160
 
160
- before do
161
- Vedeu::Terminal.console.stubs(:getch).returns(keypress)
162
- end
161
+ before { Vedeu::Input::Raw.stubs(:read).returns(keypress) }
163
162
 
164
163
  context 'when the keypress is an escape sequence' do
165
164
  context 'when the key is :shift_f5 (read_nonblock(7))' do
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Input
6
+
7
+ describe Raw do
8
+
9
+ let(:described) { Vedeu::Input::Raw }
10
+ let(:instance) { described.new }
11
+
12
+ describe '#initialize' do
13
+ it { instance.must_be_instance_of(described) }
14
+ end
15
+
16
+ describe '.read' do
17
+ let(:keypress) { 'a' }
18
+
19
+ before do
20
+ Vedeu::Terminal.console.stubs(:getch).returns(keypress)
21
+ end
22
+
23
+ subject { described.read }
24
+
25
+ it { subject.must_equal(keypress) }
26
+ end
27
+
28
+ describe '#read' do
29
+ it { instance.must_respond_to(:read) }
30
+ end
31
+
32
+ end # Raw
33
+
34
+ end # Input
35
+
36
+ end # Vedeu
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.65
4
+ version: 0.6.66
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -440,6 +440,7 @@ files:
440
440
  - lib/vedeu/input/keymap.rb
441
441
  - lib/vedeu/input/mapper.rb
442
442
  - lib/vedeu/input/mouse.rb
443
+ - lib/vedeu/input/raw.rb
443
444
  - lib/vedeu/input/read.rb
444
445
  - lib/vedeu/input/repository.rb
445
446
  - lib/vedeu/input/store.rb
@@ -625,6 +626,7 @@ files:
625
626
  - test/lib/vedeu/input/keymap_test.rb
626
627
  - test/lib/vedeu/input/mapper_test.rb
627
628
  - test/lib/vedeu/input/mouse_test.rb
629
+ - test/lib/vedeu/input/raw_test.rb
628
630
  - test/lib/vedeu/input/read_test.rb
629
631
  - test/lib/vedeu/input/repository_test.rb
630
632
  - test/lib/vedeu/input/store_test.rb
@@ -839,6 +841,7 @@ test_files:
839
841
  - test/lib/vedeu/input/keymap_test.rb
840
842
  - test/lib/vedeu/input/mapper_test.rb
841
843
  - test/lib/vedeu/input/mouse_test.rb
844
+ - test/lib/vedeu/input/raw_test.rb
842
845
  - test/lib/vedeu/input/read_test.rb
843
846
  - test/lib/vedeu/input/repository_test.rb
844
847
  - test/lib/vedeu/input/store_test.rb