Mercurial > ~astiob > upreckon > hgweb
comparison upreckon/unix.py @ 218:65b5c9390010
With _unix, Escape presses now cancel test data unarchiving
| author | Oleg Oshmyan <chortos@inbox.lv> | 
|---|---|
| date | Mon, 22 Aug 2011 22:34:09 +0300 | 
| parents | d5b6708c1955 | 
| children | d9eb7d958b6d | 
   comparison
  equal
  deleted
  inserted
  replaced
| 217:ce1285728952 | 218:65b5c9390010 | 
|---|---|
| 306 termios.tcsetattr(sys.stdin.fileno(), termios.TCSAFLUSH, old) | 306 termios.tcsetattr(sys.stdin.fileno(), termios.TCSAFLUSH, old) | 
| 307 atexit.register(cleanup) | 307 atexit.register(cleanup) | 
| 308 tty.setcbreak(sys.stdin.fileno()) | 308 tty.setcbreak(sys.stdin.fileno()) | 
| 309 def pause(): | 309 def pause(): | 
| 310 sys.stdin.read(1) | 310 sys.stdin.read(1) | 
| 311 else: | |
| 312 try: | |
| 313 from signal import signal, SIGIO, SIG_DFL | |
| 314 from select import select | |
| 315 except ImportError: | |
| 316 pass | |
| 317 else: | |
| 318 def sigio_handler(signum, frame): | |
| 319 if select((sys.stdin,), (), (), 0)[0]: | |
| 320 if os.read(sys.stdin.fileno(), 1) == '\33'.encode('ascii'): | |
| 321 remove_escape_handler() | |
| 322 raise CanceledByUser | |
| 323 def install_escape_handler(): | |
| 324 signal(SIGIO, sigio_handler) | |
| 325 sigio_handler(SIGIO, None) | |
| 326 def remove_escape_handler(): | |
| 327 signal(SIGIO, SIG_DFL) | |
| 328 __all__ += 'install_escape_handler', 'remove_escape_handler' | 
