Skip to content

Instantly share code, notes, and snippets.

@hibariya
Created November 24, 2013 05:23
Show Gist options
  • Select an option

  • Save hibariya/7623686 to your computer and use it in GitHub Desktop.

Select an option

Save hibariya/7623686 to your computer and use it in GitHub Desktop.
ひとつの入力を複数のシェルで実行する
#!/usr/bin/env ruby
require 'curses'
require 'pty'
require 'landescape'
class Terminal < Struct.new(:window, :stdout, :stdin, :pid)
def wait
Process.detach(pid).join
end
end
Curses.noecho
window = Curses.stdscr
window.addstr 'Landescape example for curses'
window.refresh
terminal_width = 100
terminal_height = 25
terminal_padding = 2
terminals = 2.times.with_object([]) {|t, memo|
height = terminal_height + terminal_padding
width = terminal_width + terminal_padding
terminal = window.subwin(height, width, height * t + 10, 10)
terminal.scrollok true
memo << Terminal.new(terminal, *PTY.getpty('TERM=vt100 bash --noprofile'))
}
terminals.each do |terminal|
terminal.stdin.puts <<-SHELL
tput cols 100
tput lines 25
clear
SHELL
Landescape.run terminal.stdout, terminal.window
end
Thread.fork do
while char = window.getch
terminals.each do |t|
t.stdin.putc char
end
end
end
terminals.each &:wait
Curses.close_screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment