Advertisement
j-a

console.py

j-a
Feb 26th, 2012
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement