Last active
December 30, 2015 13:09
-
-
Save ToQoz/7833974 to your computer and use it in GitHub Desktop.
This file contains 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
require 'curses' | |
def ensure_stdout_isatty | |
isatty = STDOUT.isatty | |
unless isatty | |
stdout_old = STDOUT.dup | |
STDOUT.reopen('/dev/tty') | |
end | |
yield | |
unless isatty | |
STDOUT.flush | |
STDOUT.reopen stdout_old | |
end | |
end | |
ensure_stdout_isatty do | |
begin | |
Curses.init_screen | |
Curses.setpos(Curses.lines / 2, Curses.cols / 2 - ("Hello".length / 2)) | |
Curses.addstr("Hello") | |
Curses.refresh | |
Curses.getch | |
ensure | |
Curses.close_screen | |
end | |
end | |
STDOUT.puts "Hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment