runcmd-cli 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/runcmd/cli.rb +1 -1
- data/lib/runcmd/cli/play_command.rb +56 -5
- data/lib/runcmd/cli/{run_command.rb → record_command.rb} +13 -7
- data/lib/runcmd/cli/root_command.rb +1 -1
- data/lib/runcmd/cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4009812a50103f2672c2ffe3f5f652645bae990952bac1ea51c29c11c02a098d
|
4
|
+
data.tar.gz: 8e62aa9134f735f331088211d7785c572698b1e8ef55f5780ae7251da09df80d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41f017464bfdf3f96bfe8f8a229211fdc998ec478a457eec736ca9ae65e6b2aac64a2914509bd2878c1b0fce20782b9ad951148a72f76cce77e2fd483e7aa729
|
7
|
+
data.tar.gz: a829859d3e1bf169598a393e0979495c47e211cace2a4403c2db8570e825895ce4ad1aac09d06770e204ffaafa78232c58194edfb9e0a429d5875fd704ba56ea
|
data/Gemfile.lock
CHANGED
data/lib/runcmd/cli.rb
CHANGED
@@ -1,19 +1,70 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require "pty"
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
# Signal.trap("INT") {
|
6
|
+
# puts "CTRL+C detected, press second time to exit"
|
7
|
+
# exit if $ctrl_c
|
8
|
+
# $ctrl_c = true
|
9
|
+
# }
|
2
10
|
|
3
11
|
module Runcmd
|
4
12
|
module Cli
|
5
13
|
class PlayCommand < Clamp::Command
|
6
14
|
parameter "RECORDING", "recording"
|
7
|
-
option ["--speed", "-
|
15
|
+
option ["--speed", "-"], "SPEED", "speed", default: 0.1 do |s|
|
8
16
|
Float(s)
|
9
17
|
end
|
10
18
|
|
11
19
|
def execute
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
recording_input = File.new recording, "r"
|
21
|
+
cmd = recording_input.readline
|
22
|
+
args = recording_input.readline.split(" ")
|
23
|
+
|
24
|
+
stderr_reader, stderr_writer = IO.pipe
|
25
|
+
|
26
|
+
env = {
|
27
|
+
"LINES" => IO.console.winsize.first.to_s,
|
28
|
+
"COLUMNS" => IO.console.winsize.last.to_s
|
29
|
+
}
|
30
|
+
|
31
|
+
stdout,stdin,pid = PTY.spawn(env, cmd, *args, err: stderr_writer.fileno)
|
32
|
+
stderr_writer.close
|
33
|
+
|
34
|
+
stdin_thr = Thread.new do
|
35
|
+
while c = recording_input.getc
|
36
|
+
case c
|
37
|
+
when "\u0003"
|
38
|
+
# control+c
|
39
|
+
stdin.print c
|
40
|
+
else
|
41
|
+
stdin.print c
|
42
|
+
end
|
43
|
+
sleep speed
|
44
|
+
end
|
45
|
+
|
46
|
+
stdin.close
|
16
47
|
end
|
48
|
+
|
49
|
+
stdout_thr = Thread.new do
|
50
|
+
while c = stdout.getc
|
51
|
+
print c
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
stderr_thr = Thread.new do
|
56
|
+
while c = stderr_reader.getc
|
57
|
+
print c
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
stdout_thr.join
|
62
|
+
stdin_thr.kill
|
63
|
+
|
64
|
+
stdin_thr.join
|
65
|
+
stderr_thr.join
|
66
|
+
|
67
|
+
recording_input.close
|
17
68
|
end
|
18
69
|
end
|
19
70
|
end
|
@@ -10,10 +10,11 @@ Signal.trap("INT") {
|
|
10
10
|
|
11
11
|
module Runcmd
|
12
12
|
module Cli
|
13
|
-
class
|
13
|
+
class RecordCommand < Clamp::Command
|
14
|
+
parameter "RECORDING", "recording"
|
14
15
|
parameter "COMMAND ...", "command"
|
15
|
-
option ["--record","-r"], "RECORD", "record"
|
16
16
|
|
17
|
+
option ["--video", "-v"], "VIDEO", "video"
|
17
18
|
def execute
|
18
19
|
cmd = command_list.shift
|
19
20
|
args = command_list
|
@@ -25,20 +26,23 @@ module Runcmd
|
|
25
26
|
"COLUMNS" => IO.console.winsize.last.to_s
|
26
27
|
}
|
27
28
|
|
28
|
-
|
29
|
+
recording_video = File.new "#{recording}.video", "w" if video
|
30
|
+
recording_input = File.new "#{recording}.runcmd", "w"
|
31
|
+
recording_input.puts cmd
|
32
|
+
recording_input.puts args.join(" ")
|
29
33
|
|
30
34
|
stdout,stdin,pid = PTY.spawn(env, cmd, *args, err: stderr_writer.fileno)
|
31
35
|
stderr_writer.close
|
32
36
|
|
33
37
|
stdin_thr = Thread.new do
|
34
38
|
while c = $stdin.getch
|
39
|
+
recording_input.print c
|
35
40
|
case c
|
36
41
|
when "\u0003"
|
37
42
|
# control+c
|
38
43
|
stdin.print c
|
39
44
|
else
|
40
45
|
stdin.print c
|
41
|
-
log.print c if record
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
@@ -48,14 +52,14 @@ module Runcmd
|
|
48
52
|
stdout_thr = Thread.new do
|
49
53
|
while c = stdout.getc
|
50
54
|
print c
|
51
|
-
|
55
|
+
recording_video.print c if video
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
59
|
stderr_thr = Thread.new do
|
56
60
|
while c = stderr_reader.getc
|
57
61
|
print c
|
58
|
-
|
62
|
+
recording_video.print c if video
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
@@ -65,7 +69,9 @@ module Runcmd
|
|
65
69
|
stdin_thr.join
|
66
70
|
stderr_thr.join
|
67
71
|
|
68
|
-
|
72
|
+
recording_video.close if video
|
73
|
+
recording_input.close
|
74
|
+
|
69
75
|
end
|
70
76
|
end
|
71
77
|
end
|
data/lib/runcmd/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runcmd-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
@@ -103,8 +103,8 @@ files:
|
|
103
103
|
- exe/runcmd
|
104
104
|
- lib/runcmd/cli.rb
|
105
105
|
- lib/runcmd/cli/play_command.rb
|
106
|
+
- lib/runcmd/cli/record_command.rb
|
106
107
|
- lib/runcmd/cli/root_command.rb
|
107
|
-
- lib/runcmd/cli/run_command.rb
|
108
108
|
- lib/runcmd/cli/version.rb
|
109
109
|
- lib/runcmd/cli/version_command.rb
|
110
110
|
- runcmd-cli.gemspec
|