Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

console.py

j-a Feb 26th, 2012 347 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. import curses
  2.  
  3. def run(callback, machine):
  4.     def internal(stdscr, machine):
  5.         console = ConsoleDisplay(stdscr, machine.rows(), machine.cols())
  6.         callback(console, machine)
  7.  
  8.     curses.wrapper(internal, machine)
  9.  
  10.  
  11. class ConsoleDisplay():
  12.  
  13.     def __init__(self, win, rows, cols):
  14.  
  15.         def set_escape_keys_interpreted_by_curses(win):
  16.             win.keypad(1)
  17.  
  18.         def set_getch_nonblocking(win):
  19.             win.nodelay(1)
  20.  
  21.         def set_cursor_as_a_block():
  22.             curses.curs_set(2)
  23.  
  24.         win.resize(rows, cols)
  25.         set_escape_keys_interpreted_by_curses(win)
  26.         set_getch_nonblocking(win)
  27.         set_cursor_as_a_block()
  28.         self._win = win
  29.         self.rows = rows
  30.         self.cols = cols
  31.  
  32.     def set_char(self, x, y, c):
  33.         if c == 0:
  34.             c = 32 # TODO: set this in RAM mem instead...
  35.         self._win.insstr(y, x, str(chr(c)))
  36.  
  37.     def refresh(self):
  38.         self._win.refresh()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top