j-a

console.py

j-a
Feb 26th, 2012
479
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×