runcmd-cli 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4970b51ed518ae09d8e238c63e589c69372adccbae82580667a07bb9dffef4b7
4
- data.tar.gz: 460527b1850f8752c800222e6b8de420c65e25925f48868d97bc63ee1141c6c4
3
+ metadata.gz: 550a2a15646bdf31858f55c53c78c9bef12da804c9c2f6e83cbdaca07b1a309b
4
+ data.tar.gz: b622b68ac6877de69979a3c63fa5d695a3f8a1794e838a10e7d746506cfc1a7f
5
5
  SHA512:
6
- metadata.gz: 39ef6dba77993f640bd0386ca62bf25e9f51f5486e0b2cc417226a71642c590120d7c31644220ba2a926b62dbbe6b199c7620786705f6689043a9d97e59e47a2
7
- data.tar.gz: 6d0e33de55dd88d298e165d441c775d179c3f71b96be41831a7dd07145795e755aaed2fcc3054b557e67b49781856ca13ddf969488fea717ed1dbc5a33d9e02e
6
+ metadata.gz: 509aa6e5f43859a031d7c71cba89724c99b001ffdeaefbe236a5657619136935b2ed88b57ccb149161cfd58171f3678973927dde9003fececdae10c6573d411e
7
+ data.tar.gz: 5c6c0dd196d170813fce98203945ecf2920eec19994f9757a5b6d52e6023dcbd746151445c56d8e4e4eb49f44153878fe4f714b3f5c96541b413d1f4f3b5a0e2
data/Gemfile.lock CHANGED
@@ -6,7 +6,7 @@ PATH
6
6
  PATH
7
7
  remote: .
8
8
  specs:
9
- runcmd-cli (0.1.0)
9
+ runcmd-cli (0.1.1)
10
10
  clamp
11
11
  runcmd
12
12
 
data/lib/runcmd/cli.rb CHANGED
@@ -8,4 +8,7 @@ end
8
8
  require_relative "cli/version"
9
9
 
10
10
  require_relative "cli/version_command"
11
+ require_relative "cli/run_command"
12
+ require_relative "cli/play_command"
13
+
11
14
  require_relative "cli/root_command"
@@ -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
@@ -11,6 +11,8 @@ module Runcmd
11
11
  end
12
12
 
13
13
  subcommand ["version"], "Show version information", VersionCommand
14
+ subcommand ["run"], "run", RunCommand
15
+ subcommand ["play"], "play", PlayCommand
14
16
 
15
17
  def self.run
16
18
  super
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Runcmd
2
2
  module Cli
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
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.0
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