pty.cr
pty.cr
Pty control and utility classes to capture command output.
Thread (-Dpreview_mt) safe.
Inspired from crpty.
Installation
-
Add the dependency to your
shard.yml
:dependencies: crpty: github: crystal-posix/pty.cr
-
Run
shards install
Usage
Capture output from a command preserving colors & window width/height
require "pty/process"
ptyp = Pty::Process.new
rvalue, process_status = ptyp.run("cat", ["-"]) do |process, stdin, stdouterr|
spawn do # Must run in another Fiber to avoid blocking if reading from `stdouterr`
File.open("input") { |f| IO.copy(f, stdin) }
ensure
stdin.close # Indicate no more input to child process
end
while line = stdouterr.gets
puts stdouterr
end
:return_value
end
p process_status
raise "cmd failed" unless process_status.success?
Raw pty
require "pty"
pty = Pty.new
pty.master.puts "foo"
pty.slave.gets => "foo"
pty.slave.win_size = {40, 80}
Contributing
- Fork it (https://github.com/crystal-posix/pty/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Didactic Drunk - creator & maintainer
Repository
pty.cr
Owner
Statistic
- 2
- 0
- 0
- 0
- 1
- about 2 years ago
- March 25, 2022
License
MIT License
Links
Synced at
Sat, 04 May 2024 00:40:54 GMT
Languages