Skip to content

Instantly share code, notes, and snippets.

@hibariya
Last active December 25, 2015 21:09
Show Gist options
  • Save hibariya/7040873 to your computer and use it in GitHub Desktop.
Save hibariya/7040873 to your computer and use it in GitHub Desktop.
子プロセスの入力を制御しつつ出力をいただきたい。 ruby から起動した bash の中で vim をつかいたいときはこんなかんじでいいの?
#!/usr/bin/env ruby
require 'pty'
require 'curses'
PTY.getpty 'bash' do |stdout, stdin, pid|
# 画面のサイズを変えてみる
stdin.puts 'stty rows 10'
stdin.puts 'stty cols 50'
Thread.fork stdout do |stdout|
stdout.each_char.each do |char|
$stdout.print char
end
end
Curses.noecho
while char = Curses.getch
stdin.putc char
end
Process.waitpid pid # これは呼ばれませんねえ
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment