ripl-readline-em 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +1 -1
- data/README.rdoc +34 -2
- data/examples/custom_binding.rb +19 -0
- data/examples/readline_callback_em.rb +44 -0
- data/lib/readline/callback.rb +8 -0
- data/lib/ripl/readline/em.rb +1 -2
- data/lib/ripl/readline/em/version.rb +7 -0
- metadata +11 -8
data/.gemspec
CHANGED
data/README.rdoc
CHANGED
@@ -11,5 +11,37 @@ Install the gem with:
|
|
11
11
|
|
12
12
|
== Usage
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
require 'eventmachine'
|
15
|
+
require 'ripl/readline/em'
|
16
|
+
|
17
|
+
EventMachine.run do
|
18
|
+
EventMachine.add_periodic_timer(2) do
|
19
|
+
# Example of writing output while line is being edited.
|
20
|
+
#
|
21
|
+
# See also http://stackoverflow.com/questions/1512028/gnu-readline-how-do-clear-the-input-line
|
22
|
+
print "\b \b" * Readline.line_buffer.size
|
23
|
+
print "\r"
|
24
|
+
begin
|
25
|
+
puts "#{Time.now}"
|
26
|
+
ensure
|
27
|
+
Readline.forced_update_display
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Start up Ripl, but it will not receive any user input
|
32
|
+
Ripl.start
|
33
|
+
|
34
|
+
# Watch stdin for input, sending it to Ripl as entered (including editing,
|
35
|
+
# history and completion).
|
36
|
+
#
|
37
|
+
# Default behavior is to call EventMachine.stop_event_loop when the shell is
|
38
|
+
# exited. Modify this behavior by passing a hash with an `:on_exit` entry,
|
39
|
+
# either nil or a Proc that will be run on exit instead of the default.
|
40
|
+
EventMachine.watch_stdin Ripl::Readline::EmInput
|
41
|
+
|
42
|
+
# -or-
|
43
|
+
# EventMachine.watch_stdin Ripl::Readline::EmInput, :on_exit => nil
|
44
|
+
|
45
|
+
# Yet another option is to create your own handler module, include
|
46
|
+
# Ripl::Readline::EmInput, and override the `on_exit` method.
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
require 'ripl/readline/em'
|
3
|
+
|
4
|
+
class Shell
|
5
|
+
|
6
|
+
def set_name(name)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def greet
|
11
|
+
puts "Hello, #{@name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
EventMachine.run do
|
17
|
+
Ripl.start :binding => Shell.new.instance_eval { binding }
|
18
|
+
EventMachine.watch_stdin Ripl::Readline::EmInput
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# This example uses readline directly without going through ripl. This is not
|
2
|
+
# the primary goal of this library, but a useful side effect of extending the
|
3
|
+
# Readline api.
|
4
|
+
|
5
|
+
require 'readline/callback.rb'
|
6
|
+
require 'eventmachine'
|
7
|
+
|
8
|
+
module Handler
|
9
|
+
def initialize
|
10
|
+
Readline::callback_handler_install('> ') do |line|
|
11
|
+
if line =~ /(quit|exit)/
|
12
|
+
EventMachine::stop_event_loop
|
13
|
+
else
|
14
|
+
puts "have a line: #{line}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def notify_readable
|
20
|
+
Readline.callback_read_char
|
21
|
+
end
|
22
|
+
|
23
|
+
def unbind
|
24
|
+
Readline.callback_handler_remove
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
EventMachine.run do
|
29
|
+
EventMachine.add_periodic_timer(2) do
|
30
|
+
# Example of writing output while line is being edited.
|
31
|
+
#
|
32
|
+
# See also http://stackoverflow.com/questions/1512028/gnu-readline-how-do-clear-the-input-line
|
33
|
+
print "\b \b" * Readline.line_buffer.size
|
34
|
+
print "\r"
|
35
|
+
begin
|
36
|
+
puts "#{Time.now}"
|
37
|
+
ensure
|
38
|
+
Readline.forced_update_display
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
conn = EventMachine.watch $stdin, Handler
|
43
|
+
conn.notify_readable = true
|
44
|
+
end
|
data/lib/readline/callback.rb
CHANGED
@@ -30,6 +30,14 @@ module Readline
|
|
30
30
|
# as-is functions
|
31
31
|
attach_function :forced_update_display, :rl_forced_update_display, [], :void
|
32
32
|
|
33
|
+
# ruby 1.8 doesn't expose readline's line buffer
|
34
|
+
unless Readline.respond_to?(:line_buffer)
|
35
|
+
attach_variable :rl_line_buffer, :string
|
36
|
+
def line_buffer
|
37
|
+
::Readline::Callback.rl_line_buffer
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
33
41
|
if editline?
|
34
42
|
def set_prompt(*args)
|
35
43
|
# noop; rl_set_prompt isn't exported by EditLine
|
data/lib/ripl/readline/em.rb
CHANGED
@@ -3,12 +3,11 @@ require 'readline/callback'
|
|
3
3
|
require 'ripl'
|
4
4
|
require 'ripl/readline'
|
5
5
|
require 'ripl/readline/eminput'
|
6
|
+
require 'ripl/readline/em/version'
|
6
7
|
|
7
8
|
module Ripl
|
8
9
|
module Readline
|
9
10
|
module Em
|
10
|
-
VERSION = '0.2.0'
|
11
|
-
|
12
11
|
def get_input
|
13
12
|
history << @input
|
14
13
|
@input
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl-readline-em
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ripl
|
16
|
-
requirement: &
|
16
|
+
requirement: &21057440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *21057440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: eventmachine
|
27
|
-
requirement: &
|
27
|
+
requirement: &21106660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *21106660
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ffi
|
38
|
-
requirement: &
|
38
|
+
requirement: &21106200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *21106200
|
47
47
|
description: Run EventMachine code in a ripl shell asynchronously with readline editing
|
48
48
|
and completion
|
49
49
|
email: pat@polycrystal.org
|
@@ -53,6 +53,7 @@ extra_rdoc_files:
|
|
53
53
|
- README.rdoc
|
54
54
|
- LICENSE.txt
|
55
55
|
files:
|
56
|
+
- lib/ripl/readline/em/version.rb
|
56
57
|
- lib/ripl/readline/em.rb
|
57
58
|
- lib/ripl/readline/eminput.rb
|
58
59
|
- lib/readline/callback.rb
|
@@ -60,6 +61,8 @@ files:
|
|
60
61
|
- README.rdoc
|
61
62
|
- examples/readline_callback.rb
|
62
63
|
- examples/ripl_readline_em.rb
|
64
|
+
- examples/readline_callback_em.rb
|
65
|
+
- examples/custom_binding.rb
|
63
66
|
- Rakefile
|
64
67
|
- .gemspec
|
65
68
|
homepage: http://github.com/pmahoney/ripl-readline-em
|