Created
November 24, 2013 05:23
-
-
Save hibariya/7623686 to your computer and use it in GitHub Desktop.
ひとつの入力を複数のシェルで実行する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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