Skip to content

Instantly share code, notes, and snippets.

@pricees
Created November 25, 2012 19:23
Show Gist options
  • Select an option

  • Save pricees/4144864 to your computer and use it in GitHub Desktop.

Select an option

Save pricees/4144864 to your computer and use it in GitHub Desktop.
Curses, Part 1: The Standard Screen
#!/usr/local/bin/ruby
require "curses"
def print_at_center(str)
lines, cols = Curses.lines, Curses.cols
Curses.clear
Curses.setpos((lines / 2 ) - 1, ((cols - str.length) / 2) - 1)
Curses.addstr(str)
Curses.refresh
end
begin
Curses.noecho
Curses.cbreak
Curses.stdscr.keypad(true)
Curses.init_screen
print_at_center("Hit Any Key")
Curses.getch
print_at_center("Hello World!")
ensure
Curses.close_screen
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment