ruco 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +10 -8
- data/Readme.md +2 -0
- data/VERSION +1 -1
- data/bin/ruco +7 -1
- data/lib/ruco/application.rb +1 -1
- data/lib/ruco/core_ext/string.rb +7 -0
- data/lib/ruco/keyboard.rb +36 -2
- data/ruco.gemspec +1 -1
- data/spec/ruco/application_spec.rb +5 -0
- metadata +5 -3
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
task :default => :spec
|
2
4
|
require "rspec/core/rake_task"
|
3
5
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
@@ -20,18 +22,18 @@ end
|
|
20
22
|
task :key do
|
21
23
|
require 'curses'
|
22
24
|
|
23
|
-
Curses.
|
24
|
-
Curses.noecho # turn off input echoing
|
25
|
+
Curses.noecho # do not show typed chars
|
25
26
|
Curses.nonl # turn off newline translation
|
26
|
-
Curses.stdscr.keypad(true) #
|
27
|
-
|
27
|
+
Curses.stdscr.keypad(true) # enable arrow keys
|
28
|
+
Curses.raw # give us all other keys
|
29
|
+
Curses.stdscr.nodelay = 1 # do not block -> we can use timeouts
|
30
|
+
Curses.init_screen
|
28
31
|
|
29
|
-
|
30
32
|
count = 0
|
31
33
|
loop do
|
32
|
-
key = Curses.getch
|
33
|
-
next if key == 4294967295
|
34
|
-
|
34
|
+
key = Curses.getch || 4294967295
|
35
|
+
next if key == 4294967295
|
36
|
+
exit if key == 3 # Ctrl+c
|
35
37
|
count = (count + 1) % 20
|
36
38
|
Curses.setpos(count,0)
|
37
39
|
Curses.addstr("#{key.inspect} ");
|
data/Readme.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
data/bin/ruco
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
2
3
|
require 'curses'
|
3
4
|
require 'optparse'
|
4
5
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
@@ -38,11 +39,12 @@ def write(line,row,text)
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def init_screen
|
41
|
-
Curses.init_screen
|
42
42
|
Curses.noecho # do not show typed chars
|
43
43
|
Curses.nonl # turn off newline translation
|
44
44
|
Curses.stdscr.keypad(true) # enable arrow keys
|
45
45
|
Curses.raw # give us all other keys
|
46
|
+
Curses.stdscr.nodelay = 1 # do not block -> we can use timeouts
|
47
|
+
Curses.init_screen
|
46
48
|
|
47
49
|
begin
|
48
50
|
yield
|
@@ -86,6 +88,10 @@ def debug_key(key)
|
|
86
88
|
write(@key_line, 0, "#{key}---")
|
87
89
|
end
|
88
90
|
|
91
|
+
def log(stuff)
|
92
|
+
File.open('ruco.log','a'){|f| f.puts stuff }
|
93
|
+
end
|
94
|
+
|
89
95
|
@options = parse_options
|
90
96
|
|
91
97
|
require 'ruco'
|
data/lib/ruco/application.rb
CHANGED
data/lib/ruco/core_ext/string.rb
CHANGED
data/lib/ruco/keyboard.rb
CHANGED
@@ -1,9 +1,25 @@
|
|
1
1
|
class Keyboard
|
2
|
+
SEQUENCE_TIMEOUT = 0.01
|
3
|
+
NOTHING = 4294967295 # getch returns this as 'nothing' on 1.8 but nil on 1.9.2
|
2
4
|
A_TO_Z = ('a'..'z').to_a
|
3
5
|
|
4
6
|
def self.listen
|
5
7
|
loop do
|
6
|
-
key = Curses.getch
|
8
|
+
key = Curses.getch || NOTHING
|
9
|
+
|
10
|
+
if @sequence
|
11
|
+
if sequence_finished?
|
12
|
+
yield @sequence.pack('c*').force_encoding('utf-8')
|
13
|
+
@sequence = nil
|
14
|
+
else
|
15
|
+
@sequence << key unless key == NOTHING
|
16
|
+
end
|
17
|
+
next
|
18
|
+
end
|
19
|
+
|
20
|
+
next if key == NOTHING
|
21
|
+
log(key)
|
22
|
+
|
7
23
|
|
8
24
|
code = case key
|
9
25
|
|
@@ -12,10 +28,18 @@ class Keyboard
|
|
12
28
|
when Curses::Key::DOWN then :down
|
13
29
|
when Curses::Key::RIGHT then :right
|
14
30
|
when Curses::Key::LEFT then :left
|
31
|
+
when 554 then :"Ctrl+right"
|
32
|
+
when 555 then :"Ctrl+Shift+right"
|
33
|
+
when 539 then :"Ctrl+left"
|
34
|
+
when 540 then :"Ctrl+Shift+left"
|
35
|
+
when 560 then :"Ctrl+up"
|
36
|
+
when 519 then :"Ctrl+down"
|
15
37
|
when Curses::KEY_END then :end
|
16
38
|
when Curses::KEY_HOME then :home
|
17
39
|
when Curses::KEY_NPAGE then :page_down
|
18
40
|
when Curses::KEY_PPAGE then :page_up
|
41
|
+
when Curses::KEY_IC then :insert
|
42
|
+
when Curses::KEY_F0..Curses::KEY_F63 then :"F#{key - Curses::KEY_F0}"
|
19
43
|
|
20
44
|
# modify
|
21
45
|
when 9 then :tab
|
@@ -27,11 +51,21 @@ class Keyboard
|
|
27
51
|
when 0 then :"Ctrl+space"
|
28
52
|
when 1..26 then :"Ctrl+#{A_TO_Z[key-1]}"
|
29
53
|
when 27 then :escape
|
54
|
+
when 195..197 # start of unicode sequence
|
55
|
+
@sequence = [key]
|
56
|
+
@sequence_started = Time.now.to_f
|
57
|
+
next
|
30
58
|
else
|
31
|
-
key.chr # printable
|
59
|
+
key > 255 ? key : key.chr # output printable chars
|
32
60
|
end
|
33
61
|
|
34
62
|
yield code
|
35
63
|
end
|
36
64
|
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def self.sequence_finished?
|
69
|
+
(Time.now.to_f - @sequence_started) > SEQUENCE_TIMEOUT
|
70
|
+
end
|
37
71
|
end
|
data/ruco.gemspec
CHANGED
@@ -28,6 +28,11 @@ describe Ruco::Application do
|
|
28
28
|
app.view.should == "#{status.sub('.txt ','.txt*')}22\n2\n\n#{command}"
|
29
29
|
end
|
30
30
|
|
31
|
+
it "does not enter key-codes" do
|
32
|
+
app.key(888)
|
33
|
+
app.view.should == "#{status}\n\n\n#{command}"
|
34
|
+
end
|
35
|
+
|
31
36
|
it "can execute a command" do
|
32
37
|
write("123\n456\n789\n")
|
33
38
|
app.key(:"Ctrl+g") # go to line
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 5
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 13
|
10
|
+
version: 0.0.13
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Grosser
|
@@ -71,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
72
|
requirements:
|
72
73
|
- - ">="
|
73
74
|
- !ruby/object:Gem::Version
|
74
|
-
hash:
|
75
|
+
hash: 3
|
75
76
|
segments:
|
76
77
|
- 0
|
77
78
|
version: "0"
|
@@ -80,6 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
requirements:
|
81
82
|
- - ">="
|
82
83
|
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
83
85
|
segments:
|
84
86
|
- 0
|
85
87
|
version: "0"
|