rios 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -14
- data/VERSION +1 -1
- data/ext/rios/util.c +8 -1
- data/ext/rios/util.h +1 -1
- data/lib/rios/easy.rb +25 -0
- data/lib/rios/proxy.rb +14 -5
- data/rios.gemspec +4 -2
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -1,19 +1,33 @@
|
|
1
|
-
=
|
1
|
+
= Rios - A proxy framework for command line interfaces
|
2
2
|
|
3
|
-
Description
|
3
|
+
== Description
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
5
|
+
Rios is a proxy framework which works as a proxy for command line
|
6
|
+
applications and allows developer to hook input/output of the
|
7
|
+
applications in a blazingly simple way.
|
14
8
|
|
15
|
-
==
|
9
|
+
== Installation
|
16
10
|
|
17
|
-
|
18
|
-
further details.
|
11
|
+
# gem install rios
|
19
12
|
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
=== Shadow certain word
|
16
|
+
|
17
|
+
#!/usr/bin/env ruby
|
18
|
+
|
19
|
+
require "rios/easy"
|
20
|
+
|
21
|
+
on_output { |s|
|
22
|
+
s.gsub(/vim/i) { |match| "***" }
|
23
|
+
}
|
24
|
+
|
25
|
+
listen
|
26
|
+
|
27
|
+
== Author
|
28
|
+
|
29
|
+
mooz <mailto:stillpedant@gmail.com>
|
30
|
+
|
31
|
+
== License
|
32
|
+
|
33
|
+
The MIT License.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/ext/rios/util.c
CHANGED
@@ -7,8 +7,11 @@ VALUE Util = Qnil;
|
|
7
7
|
void Init_util() {
|
8
8
|
Rios = rb_define_module("Rios");
|
9
9
|
Util = rb_define_module_under(Rios, "Util");
|
10
|
-
|
10
|
+
|
11
11
|
rb_define_singleton_method(Util, "openpty", method_openpty, 1);
|
12
|
+
rb_define_singleton_method(Util, "set_controlling_tty", method_set_controlling_tty, 2);
|
13
|
+
|
14
|
+
rb_define_const(Util, "BUFSIZ", INT2NUM(BUFSIZ));
|
12
15
|
}
|
13
16
|
|
14
17
|
/* Rios::Util::openpty */
|
@@ -26,3 +29,7 @@ VALUE method_openpty(VALUE self, VALUE fd) {
|
|
26
29
|
|
27
30
|
return rb_ary_new3(2, INT2NUM(master), INT2NUM(slave));
|
28
31
|
}
|
32
|
+
|
33
|
+
VALUE method_set_controlling_tty(VALUE self, VALUE tty, VALUE source) {
|
34
|
+
return INT2NUM(ioctl(NUM2INT(tty), TIOCSCTTY, NUM2INT(source)));
|
35
|
+
}
|
data/ext/rios/util.h
CHANGED
data/lib/rios/easy.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "rios/proxy"
|
2
|
+
|
3
|
+
module Rios
|
4
|
+
module Easy
|
5
|
+
@@proxy = Rios::Proxy.new
|
6
|
+
|
7
|
+
# Inspired from Sinatra
|
8
|
+
def self.delegate(*methods)
|
9
|
+
methods.each do |method_name|
|
10
|
+
eval <<-RUBY, binding, '(__DELEGATE__)', 1
|
11
|
+
def #{method_name}(*args, &block)
|
12
|
+
@@proxy.send(#{method_name.inspect}, *args, &block)
|
13
|
+
end
|
14
|
+
private #{method_name.inspect}
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
delegate :on_input, :on_output, :on_finish, :input, :output, :listen
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Object
|
24
|
+
include Rios::Easy
|
25
|
+
end
|
data/lib/rios/proxy.rb
CHANGED
@@ -3,7 +3,6 @@ require "rios/terminal"
|
|
3
3
|
|
4
4
|
module Rios
|
5
5
|
class Proxy
|
6
|
-
BUFSIZE = 128
|
7
6
|
DEFAULT_COMMAND = ENV["SHELL"]
|
8
7
|
|
9
8
|
def initialize
|
@@ -11,6 +10,7 @@ module Rios
|
|
11
10
|
@input_filters = []
|
12
11
|
@output_filters = []
|
13
12
|
@on_finishes = []
|
13
|
+
@pty_lock = Mutex.new
|
14
14
|
end
|
15
15
|
|
16
16
|
##
|
@@ -34,13 +34,17 @@ module Rios
|
|
34
34
|
##
|
35
35
|
# emulate user input
|
36
36
|
def input(string)
|
37
|
-
|
37
|
+
@pty_lock.synchronize {
|
38
|
+
terminal.master.syswrite(string)
|
39
|
+
}
|
38
40
|
end
|
39
41
|
|
40
42
|
##
|
41
43
|
# output string to the stdout (usually terminal)
|
42
44
|
def output(string)
|
43
|
-
|
45
|
+
@pty_lock.synchronize {
|
46
|
+
$stdout.syswrite(string)
|
47
|
+
}
|
44
48
|
end
|
45
49
|
|
46
50
|
##
|
@@ -96,7 +100,7 @@ module Rios
|
|
96
100
|
terminal.slave.close
|
97
101
|
|
98
102
|
begin
|
99
|
-
while s = $stdin.sysread(
|
103
|
+
while s = $stdin.sysread(Util::BUFSIZ) do
|
100
104
|
input(apply_filters(s, @input_filters))
|
101
105
|
end
|
102
106
|
rescue
|
@@ -111,7 +115,7 @@ module Rios
|
|
111
115
|
terminal.slave.close
|
112
116
|
|
113
117
|
begin
|
114
|
-
while s = terminal.master.sysread(
|
118
|
+
while s = terminal.master.sysread(Util::BUFSIZ) do
|
115
119
|
output(apply_filters(s, @output_filters))
|
116
120
|
end
|
117
121
|
rescue
|
@@ -121,6 +125,9 @@ module Rios
|
|
121
125
|
end
|
122
126
|
|
123
127
|
def do_command(block)
|
128
|
+
Process.setsid()
|
129
|
+
Util::set_controlling_tty(terminal.slave.fileno, $stdin.fileno)
|
130
|
+
|
124
131
|
terminal.master.close
|
125
132
|
$stdin.reopen(terminal.slave)
|
126
133
|
$stdout.reopen(terminal.slave)
|
@@ -129,6 +136,8 @@ module Rios
|
|
129
136
|
|
130
137
|
if block
|
131
138
|
block.call
|
139
|
+
elsif @command.class == Array
|
140
|
+
exec(*@command)
|
132
141
|
else
|
133
142
|
exec(@command)
|
134
143
|
end
|
data/rios.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rios}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mooz"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-16}
|
13
13
|
s.default_executable = %q{script.rb}
|
14
14
|
s.description = %q{Rios is a proxy framework which works as a proxy
|
15
15
|
for command line applications and allows developer to hook input/output
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
]
|
24
24
|
s.files = [
|
25
25
|
"Gemfile",
|
26
|
+
"README.rdoc",
|
26
27
|
"Rakefile",
|
27
28
|
"VERSION",
|
28
29
|
"bin/script.rb",
|
@@ -30,6 +31,7 @@ Gem::Specification.new do |s|
|
|
30
31
|
"ext/rios/util.c",
|
31
32
|
"ext/rios/util.h",
|
32
33
|
"lib/rios.rb",
|
34
|
+
"lib/rios/easy.rb",
|
33
35
|
"lib/rios/proxy.rb",
|
34
36
|
"lib/rios/terminal.rb",
|
35
37
|
"rios.gemspec"
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- mooz
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-16 00:00:00 +09:00
|
14
14
|
default_executable: script.rb
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,7 @@ extra_rdoc_files:
|
|
82
82
|
- README.rdoc
|
83
83
|
files:
|
84
84
|
- Gemfile
|
85
|
+
- README.rdoc
|
85
86
|
- Rakefile
|
86
87
|
- VERSION
|
87
88
|
- bin/script.rb
|
@@ -89,11 +90,11 @@ files:
|
|
89
90
|
- ext/rios/util.c
|
90
91
|
- ext/rios/util.h
|
91
92
|
- lib/rios.rb
|
93
|
+
- lib/rios/easy.rb
|
92
94
|
- lib/rios/proxy.rb
|
93
95
|
- lib/rios/terminal.rb
|
94
96
|
- rios.gemspec
|
95
97
|
- LICENSE.txt
|
96
|
-
- README.rdoc
|
97
98
|
has_rdoc: true
|
98
99
|
homepage: https://github.com/mooz/rios
|
99
100
|
licenses:
|
@@ -108,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
109
|
requirements:
|
109
110
|
- - ">="
|
110
111
|
- !ruby/object:Gem::Version
|
111
|
-
hash:
|
112
|
+
hash: -339107533
|
112
113
|
segments:
|
113
114
|
- 0
|
114
115
|
version: "0"
|