kommando 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da77c3f809cd0a9d9fdf6ae89c929d6e1ab457f9
4
- data.tar.gz: 2e4815740c38be873a97f4f64d278489e18232f3
3
+ metadata.gz: 087165e6259c0a09ac7fb5eaf432338dd92fe9b6
4
+ data.tar.gz: 06ff447d8ee0ebadce51fae705628cef8877d08d
5
5
  SHA512:
6
- metadata.gz: d5ab9ed6a24dd357a3fd86e104723034da942147d7e203f44634fdab52736c2dd59d319cb3432a9742721b975ca79abbc6d1c4c840f86547d95e7021835ce433
7
- data.tar.gz: 8e83c297b5706403481eebab8c02a30afff4e7bced1b506ce0733c68c6d4f167584da75ca1e34cb16882ea93940526d3203d2005c8f738645a62729b64057cbf
6
+ metadata.gz: 378bdaa26cda65cd3cd154501578cddc3a6e34c19e573ac3a3bf92bb270d2cecdec64a91eb1ded589cd641b2520cac7d9f8e6d4521d52bd20f13b2eef2ad08c6
7
+ data.tar.gz: 961ed2f546c6edf6b81091a0988128331dbc485cdb25d71d7f7fefd83ba22ecdc4352d9ce73f4dcb810343a45d2683e984b1831fde3a70499d02efff9138ca18
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.11
4
+ STDIN support.
5
+
6
+ - FEAT: Support for writing to STDIN with `k.in << "hello"`
7
+ - EXAMPLES: `in` and `nano` added.
8
+
3
9
  ## 0.0.10
4
10
  ENV variable interpolation.
5
11
 
@@ -0,0 +1,9 @@
1
+ require "./lib/kommando"
2
+
3
+ k = Kommando.new "$ read YOURNAME; echo hello $YOURNAME"
4
+ k.in << "Matti\n"
5
+ k.run
6
+
7
+ raise "err" unless k.out == "Matti\r\nhello Matti"
8
+
9
+ puts k.out
@@ -0,0 +1,24 @@
1
+ require "./lib/kommando"
2
+ require "tempfile"
3
+
4
+ scratch = Tempfile.new
5
+
6
+ k = Kommando.new "nano #{scratch.path}", {
7
+ output: true
8
+ }
9
+
10
+ Thread.new do
11
+ words = [
12
+ "hello\r",
13
+ "world\r",
14
+ "\x1B\x1Bx",
15
+ "y",
16
+ "\r"
17
+ ]
18
+ words.each do |word|
19
+ k.in << word
20
+ sleep 0.25
21
+ end
22
+ end
23
+
24
+ k.run
@@ -10,6 +10,7 @@ class Kommando
10
10
  def initialize(cmd, opts={})
11
11
  @cmd = cmd
12
12
  @stdout = Buffer.new
13
+ @stdin = Buffer.new
13
14
 
14
15
  @output_stdout = opts[:output] == true
15
16
  @output_file = if opts[:output].class == String
@@ -46,6 +47,8 @@ class Kommando
46
47
  def kill
47
48
  Process.kill('KILL', @pid)
48
49
  @kill_happened = true
50
+
51
+ sleep 0.001 until @code # let finalize
49
52
  end
50
53
 
51
54
  def run
@@ -130,6 +133,17 @@ class Kommando
130
133
  end
131
134
  end
132
135
 
136
+ thread_stdin = Thread.new do
137
+ while true do
138
+ c = @stdin.getc
139
+ unless c
140
+ sleep 0.01
141
+ next
142
+ end
143
+ stdin.write c
144
+ end
145
+ end
146
+
133
147
  if @timeout
134
148
  begin
135
149
  Timeout.timeout(@timeout) do
@@ -184,4 +198,8 @@ class Kommando
184
198
  def code
185
199
  @code
186
200
  end
201
+
202
+ def in
203
+ @stdin
204
+ end
187
205
  end
@@ -12,4 +12,11 @@ class Kommando::Buffer
12
12
  @buffer.join ""
13
13
  end
14
14
 
15
+ def <<(string)
16
+ @buffer << string
17
+ end
18
+
19
+ def getc
20
+ @buffer.shift
21
+ end
15
22
  end
@@ -1,3 +1,3 @@
1
1
  class Kommando
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kommando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2016-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,8 +107,10 @@ files:
107
107
  - examples/async.rb
108
108
  - examples/env.rb
109
109
  - examples/exit.rb
110
+ - examples/in.rb
110
111
  - examples/kill.rb
111
112
  - examples/live_output.rb
113
+ - examples/nano.rb
112
114
  - examples/ping.rb
113
115
  - examples/shell.rb
114
116
  - examples/stdout_to_file.rb