vedeu 0.0.35 → 0.0.36

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: 9e5bec0b5de4844a5345d59ec1da5c8ad679f8d5
4
- data.tar.gz: 1d4e0cfa8a8d21a8ad784467a9e0597218160f6f
3
+ metadata.gz: f601ff87eda4c07701dfc42940bbed9c30879fc3
4
+ data.tar.gz: cbf134f3d4aa31bacec4dbc26ac059e4cec15f1b
5
5
  SHA512:
6
- metadata.gz: 4722efaa8c4a0cdd1ce6399d55d9f2103d3b9df478e8fa317c342d519f3537ec1d14d5f5f601b152b878a8429c4ca108ec54a2f9ef489d970e096c6638f3a9ec
7
- data.tar.gz: 7ae465c0dd6f73cfbfcc6b6b2ef956894d19490c71631237111086c817ee3f2619d9d7684c5fca6821dd929d9f789d5311c5f47cf7b4e4f0f477326b4c102f57
6
+ metadata.gz: 3c4d5ef111d1f43f66c3fa1a4acc31a7066405fa5aed113b7b9fabed117290757d42d7972f847eeb2c009262b2c50a7504ca0f28e8741ec7f27c72ed1754b336
7
+ data.tar.gz: 1d663a4f0a1d69cca7abf7aa1f91346bc47be0578fdba37e7627e0df5a8e9109980fc5bc01bd31493f29f9e2ba20ecdbc8adfab4a7cf8581b1ad80060c4c6275
@@ -1,26 +1,61 @@
1
1
  require_relative '../support/queue'
2
2
  require_relative '../support/terminal'
3
+ require_relative '../repository/event_repository'
3
4
 
4
5
  module Vedeu
5
- module Input
6
- extend self
6
+ class Input
7
+ def self.capture
8
+ new.capture
9
+ end
7
10
 
8
11
  def capture
9
- key = input
10
-
11
- Trigger.event(:_mode_switch_) if is_escape?(key)
12
+ EventRepository.trigger(:_keypress_, keypress)
12
13
 
13
- Queue.enqueue(key)
14
+ Queue.enqueue(keypress)
14
15
  end
15
16
 
16
17
  private
17
18
 
18
- def is_escape?(key)
19
- key.ord == 27
19
+ def keypress
20
+ key = input
21
+ translated = case key
22
+ when "\r" then :enter
23
+ when "\t" then :tab
24
+ when "\e" then :escape
25
+ when "\e[A" then :up
26
+ when "\e[B" then :down
27
+ when "\e[C" then :right
28
+ when "\e[D" then :left
29
+ when "\e[5~" then :page_up
30
+ when "\e[6~" then :page_down
31
+ when "\e[H" then :home
32
+ when "\e[3~" then :delete
33
+ when "\e[F" then :end
34
+ when "\eOP" then :f1
35
+ when "\eOQ" then :f2
36
+ when "\eOR" then :f3
37
+ when "\eOS" then :f4
38
+ when "\e[15~" then :f5
39
+ when "\e[17~" then :f6
40
+ when "\e[18~" then :f7
41
+ when "\e[19~" then :f8
42
+ when "\e[20~" then :f9
43
+ when "\e[21~" then :f10
44
+ when "\e[23~" then :f11
45
+ when "\e[24~" then :f12
46
+ when "\e[1;2P" then :print_screen
47
+ when "\e[1;2Q" then :scroll_lock
48
+ when "\e[1;2R" then :pause_break
49
+ when "\u007F" then :backspace
50
+ else
51
+ key
52
+ end
53
+
54
+ translated
20
55
  end
21
56
 
22
57
  def input
23
- Terminal.input
58
+ @_input ||= Terminal.input
24
59
  end
25
60
  end
26
61
  end
@@ -1,18 +1,6 @@
1
1
  require_relative '../support/terminal'
2
2
 
3
3
  module Vedeu
4
- class Trigger
5
- def self.event(event, *args)
6
- EventRepository.trigger(event, *args)
7
- end
8
- end
9
-
10
- class Register
11
- def self.event(event, *args)
12
- EventRepository.register(event, &block)
13
- end
14
- end
15
-
16
4
  module EventRepository
17
5
  extend self
18
6
 
@@ -35,8 +23,15 @@ module Vedeu
35
23
  def defaults
36
24
  {
37
25
  :_exit_ => [ proc { fail StopIteration } ],
38
- :_mode_switch_ => [ proc { fail ModeSwitch } ]
26
+ :_keypress_ => [ proc { |key| keypress(key) } ],
27
+ :_mode_switch_ => [ proc { fail ModeSwitch } ],
39
28
  }
40
29
  end
30
+
31
+ def keypress(key)
32
+ trigger(:_mode_switch_) if key == :escape
33
+
34
+ trigger(:key, key)
35
+ end
41
36
  end
42
37
  end
@@ -3,7 +3,7 @@ require_relative '../repository/event_repository'
3
3
  module Vedeu
4
4
  class Exit
5
5
  def self.dispatch
6
- Trigger.event(:_exit_)
6
+ EventRepository.trigger(:_exit_)
7
7
  end
8
8
  end
9
9
  end
@@ -16,6 +16,10 @@ module Vedeu
16
16
  store.size > 0
17
17
  end
18
18
 
19
+ def entries
20
+ store
21
+ end
22
+
19
23
  def size
20
24
  store.size
21
25
  end
@@ -21,17 +21,22 @@ module Vedeu
21
21
  ensure
22
22
  restore_screen
23
23
  end
24
- # :nocov:
25
24
 
26
25
  def input
27
26
  if raw_mode?
28
- console.getc
27
+ keys = console.getch
28
+ if keys.ord == 27
29
+ keys << console.read_nonblock(3) rescue nil
30
+ keys << console.read_nonblock(2) rescue nil
31
+ end
32
+ keys
29
33
 
30
34
  else
31
35
  console.gets.chomp
32
36
 
33
37
  end
34
38
  end
39
+ # :nocov:
35
40
 
36
41
  def output(stream = '')
37
42
  console.print(stream)
@@ -39,6 +44,7 @@ module Vedeu
39
44
  stream
40
45
  end
41
46
 
47
+ # :nocov:
42
48
  def initialize_screen(&block)
43
49
  output Esc.string 'reset'
44
50
  output Esc.string 'clear'
@@ -70,6 +76,7 @@ module Vedeu
70
76
  def raw_mode?
71
77
  @mode == :raw
72
78
  end
79
+ # :nocov:
73
80
 
74
81
  def centre
75
82
  [(height / 2), (width / 2)]
@@ -64,15 +64,24 @@ module Example
64
64
  }.merge(command_position)
65
65
  command 'time', {
66
66
  entity: ExampleCommand,
67
- keyword: 'time',
67
+ keyword: 'time',
68
68
  keypress: 't'
69
69
  }
70
70
  command 'exit', {
71
71
  entity: Vedeu::Exit,
72
- keyword: 'exit',
72
+ keyword: 'exit',
73
73
  keypress: 'q'
74
74
  }
75
75
 
76
+ event :key do |key|
77
+ case key
78
+ when 'v' then puts "v was pressed."
79
+ when :f1 then puts "F1 was pressed."
80
+ when :f2 then run(:some_event, [:args, :go, :here])
81
+ else
82
+ end
83
+ end
84
+
76
85
  def self.start
77
86
  Vedeu::Launcher.new([]).execute!
78
87
  end
@@ -4,9 +4,52 @@ require_relative '../../../../lib/vedeu/input/input'
4
4
  module Vedeu
5
5
  describe Input do
6
6
  describe '.capture' do
7
- it 'enqueues the captured input from the terminal' do
8
- Terminal.stub :input, 'input' do
9
- Input.capture.must_equal(Vedeu::Queue)
7
+ keypresses = {
8
+ "\r" => :enter,
9
+ "\t" => :tab,
10
+ # "\e" => :escape, # handled below in separate test
11
+ "\e[A" => :up,
12
+ "\e[B" => :down,
13
+ "\e[C" => :right,
14
+ "\e[D" => :left,
15
+ "\e[5~" => :page_up,
16
+ "\e[6~" => :page_down,
17
+ "\e[H" => :home,
18
+ "\e[3~" => :delete,
19
+ "\e[F" => :end,
20
+ "\eOP" => :f1,
21
+ "\eOQ" => :f2,
22
+ "\eOR" => :f3,
23
+ "\eOS" => :f4,
24
+ "\e[15~" => :f5,
25
+ "\e[17~" => :f6,
26
+ "\e[18~" => :f7,
27
+ "\e[19~" => :f8,
28
+ "\e[20~" => :f9,
29
+ "\e[21~" => :f10,
30
+ "\e[23~" => :f11,
31
+ "\e[24~" => :f12,
32
+ "\e[1;2P" => :print_screen,
33
+ "\e[1;2Q" => :scroll_lock,
34
+ "\e[1;2R" => :pause_break,
35
+ "\u007F" => :backspace,
36
+ "k" => "k"
37
+ }
38
+
39
+ keypresses.each do |keypress, value|
40
+ it 'enqueues the captured input from the terminal' do
41
+ Queue.reset
42
+ Terminal.stub :input, keypress do
43
+ Input.capture
44
+ Queue.entries.must_equal([value])
45
+ end
46
+ end
47
+ end
48
+
49
+ it 'switches the terminal mode when escape is pressed' do
50
+ Queue.reset
51
+ Terminal.stub :input, "\e" do
52
+ proc { Input.capture }.must_raise(ModeSwitch)
10
53
  end
11
54
  end
12
55
  end
@@ -36,6 +36,19 @@ module Vedeu
36
36
  end
37
37
  end
38
38
 
39
+ describe '.entries' do
40
+ it 'returns an empty collection when the queue is empty' do
41
+ Queue.reset
42
+ Queue.entries.must_equal([])
43
+ end
44
+
45
+ it 'returns all the enqueue items when the queue is not empty' do
46
+ Queue.reset
47
+ Queue.enqueue(:queued_entry)
48
+ Queue.entries.must_equal([:queued_entry])
49
+ end
50
+ end
51
+
39
52
  describe '.size' do
40
53
  it 'returns the size of the queue when the queue is empty' do
41
54
  Queue.reset
data/test/test_helper.rb CHANGED
@@ -9,10 +9,6 @@ SimpleCov.start do
9
9
  add_filter '/test/'
10
10
  end unless ENV['no_simplecov']
11
11
 
12
- Minitest.after_run do
13
- print [27.chr, '[', '?25h'].join # show cursor
14
- end
15
-
16
12
  GC.disable
17
13
 
18
14
  # commented out by default (makes tests slower)
data/vedeu.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.0.35'
7
+ spec.version = '0.0.36'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = %q{A terminal case of wonderland.}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-20 00:00:00.000000000 Z
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler