runcmd-cli 0.1.2 → 0.2.0

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: 14952b53e3c7e1af1acdac479415b9366e4bc639974a505a00dc89d0ca81ef91
4
- data.tar.gz: cceecc3dab11f8fe696e0ab62e30cdf62d70c0e1e9f369b33d2244df804c52cc
3
+ metadata.gz: 4009812a50103f2672c2ffe3f5f652645bae990952bac1ea51c29c11c02a098d
4
+ data.tar.gz: 8e62aa9134f735f331088211d7785c572698b1e8ef55f5780ae7251da09df80d
5
5
  SHA512:
6
- metadata.gz: 8a0fce19e9c38708465147c977f7cf008c0db1a6d828099c87388dee0a8eecede4043fa29da0ef6aab06282351a80453ca16c4f11060d4ed2a3f2c9229e85775
7
- data.tar.gz: 359a6dab0af6bcdf69e693dc6bc2bbe1045811322db9a87f52b5859f05623a725aa374bca5c3ab073ccd0f33e78617f47d550fcf032f3b6ec694663a883f5797
6
+ metadata.gz: 41f017464bfdf3f96bfe8f8a229211fdc998ec478a457eec736ca9ae65e6b2aac64a2914509bd2878c1b0fce20782b9ad951148a72f76cce77e2fd483e7aa729
7
+ data.tar.gz: a829859d3e1bf169598a393e0979495c47e211cace2a4403c2db8570e825895ce4ad1aac09d06770e204ffaafa78232c58194edfb9e0a429d5875fd704ba56ea
@@ -6,7 +6,7 @@ PATH
6
6
  PATH
7
7
  remote: .
8
8
  specs:
9
- runcmd-cli (0.1.2)
9
+ runcmd-cli (0.2.0)
10
10
  clamp
11
11
  runcmd
12
12
 
@@ -9,7 +9,7 @@ end
9
9
  require_relative "cli/version"
10
10
 
11
11
  require_relative "cli/version_command"
12
- require_relative "cli/run_command"
12
+ require_relative "cli/record_command"
13
13
  require_relative "cli/play_command"
14
14
 
15
15
  require_relative "cli/root_command"
@@ -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", "-s"], "speed", "speed", default: 0 do |s|
15
+ option ["--speed", "-"], "SPEED", "speed", default: 0.1 do |s|
8
16
  Float(s)
9
17
  end
10
18
 
11
19
  def execute
12
- log = File.open(recording, "r")
13
- log.each_char do |c|
14
- print c
15
- sleep speed
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 RunCommand < Clamp::Command
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
- log = File.new record, "w" if record
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
- log.print c if record
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
- log.print c if record
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
- log.close if record
72
+ recording_video.close if video
73
+ recording_input.close
74
+
69
75
  end
70
76
  end
71
77
  end
@@ -11,7 +11,7 @@ module Runcmd
11
11
  end
12
12
 
13
13
  subcommand ["version"], "Show version information", VersionCommand
14
- subcommand ["run"], "run", RunCommand
14
+ subcommand ["record"], "record", RecordCommand
15
15
  subcommand ["play"], "play", PlayCommand
16
16
 
17
17
  def self.run
@@ -1,5 +1,5 @@
1
1
  module Runcmd
2
2
  module Cli
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
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.2
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