runcmd-cli 0.1.0 → 0.1.1
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 +3 -0
- data/lib/runcmd/cli/play_command.rb +20 -0
- data/lib/runcmd/cli/root_command.rb +2 -0
- data/lib/runcmd/cli/run_command.rb +75 -0
- data/lib/runcmd/cli/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 550a2a15646bdf31858f55c53c78c9bef12da804c9c2f6e83cbdaca07b1a309b
|
4
|
+
data.tar.gz: b622b68ac6877de69979a3c63fa5d695a3f8a1794e838a10e7d746506cfc1a7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 509aa6e5f43859a031d7c71cba89724c99b001ffdeaefbe236a5657619136935b2ed88b57ccb149161cfd58171f3678973927dde9003fececdae10c6573d411e
|
7
|
+
data.tar.gz: 5c6c0dd196d170813fce98203945ecf2920eec19994f9757a5b6d52e6023dcbd746151445c56d8e4e4eb49f44153878fe4f714b3f5c96541b413d1f4f3b5a0e2
|
data/Gemfile.lock
CHANGED
data/lib/runcmd/cli.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Runcmd
|
4
|
+
module Cli
|
5
|
+
class PlayCommand < Clamp::Command
|
6
|
+
parameter "RECORDING", "recording"
|
7
|
+
option ["--speed", "-s"], "speed", "speed", default: 0 do |s|
|
8
|
+
Float(s)
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
log = File.open(recording, "r")
|
13
|
+
log.each_char do |c|
|
14
|
+
print c
|
15
|
+
sleep speed
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "pty"
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
Signal.trap("INT") {
|
6
|
+
puts "CTRLC"
|
7
|
+
exit if $ctrl_c
|
8
|
+
$ctrl_c = true
|
9
|
+
}
|
10
|
+
|
11
|
+
module Runcmd
|
12
|
+
module Cli
|
13
|
+
class RunCommand < Clamp::Command
|
14
|
+
parameter "COMMAND ...", "command"
|
15
|
+
option ["--record","-r"], "RECORD", "record"
|
16
|
+
|
17
|
+
def execute
|
18
|
+
cmd = command_list.shift
|
19
|
+
args = command_list
|
20
|
+
|
21
|
+
stderr_reader, stderr_writer = IO.pipe
|
22
|
+
|
23
|
+
env = {
|
24
|
+
"LINES" => IO.console.winsize.first.to_s,
|
25
|
+
"COLUMNS" => IO.console.winsize.last.to_s
|
26
|
+
}
|
27
|
+
|
28
|
+
log = File.new record, "w" if record
|
29
|
+
|
30
|
+
stdout,stdin,pid = PTY.spawn(env, cmd, *args, err: stderr_writer.fileno)
|
31
|
+
stderr_writer.close
|
32
|
+
|
33
|
+
stdin_thr = Thread.new do
|
34
|
+
while c = $stdin.getch
|
35
|
+
case c
|
36
|
+
when "\u0003"
|
37
|
+
# control+c
|
38
|
+
stdin.print c
|
39
|
+
else
|
40
|
+
stdin.print c
|
41
|
+
log.print c if record
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
stdin.close
|
46
|
+
end
|
47
|
+
|
48
|
+
stdout_thr = Thread.new do
|
49
|
+
while c = stdout.getc
|
50
|
+
print c
|
51
|
+
log.print c if record
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
stderr_thr = Thread.new do
|
56
|
+
while c = stderr_reader.getc
|
57
|
+
print c
|
58
|
+
log.print c if record
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
stdout_thr.join
|
63
|
+
puts "stdout closed"
|
64
|
+
stdin_thr.kill
|
65
|
+
|
66
|
+
stdin_thr.join
|
67
|
+
puts "stdin closed"
|
68
|
+
stderr_thr.join
|
69
|
+
puts "stderr closed"
|
70
|
+
|
71
|
+
log.close if record
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
@@ -102,7 +102,9 @@ files:
|
|
102
102
|
- bin/setup
|
103
103
|
- exe/runcmd
|
104
104
|
- lib/runcmd/cli.rb
|
105
|
+
- lib/runcmd/cli/play_command.rb
|
105
106
|
- lib/runcmd/cli/root_command.rb
|
107
|
+
- lib/runcmd/cli/run_command.rb
|
106
108
|
- lib/runcmd/cli/version.rb
|
107
109
|
- lib/runcmd/cli/version_command.rb
|
108
110
|
- runcmd-cli.gemspec
|