Skip to content

Instantly share code, notes, and snippets.

@ToQoz
Last active December 30, 2015 13:09
Show Gist options
  • Save ToQoz/7833974 to your computer and use it in GitHub Desktop.
Save ToQoz/7833974 to your computer and use it in GitHub Desktop.
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