Created
December 5, 2012 10:24
-
-
Save saitoha/4214542 to your computer and use it in GitHub Desktop.
screen dump on xterm#286
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import sys, os, termios, select | |
| def readcell(y, x): | |
| import sys | |
| sys.stdout.write("\x1b[;1;%d;%d;%d;%d*y" % (y, x, y, x)) | |
| sys.stdout.flush() | |
| rfd, wfd, xfd = select.select([0], [], [], 2) | |
| if rfd: | |
| data = os.read(0, 32) | |
| return unichr(int(data[5:-2], 16)) | |
| def dumpscreen(): | |
| import termios, fcntl, struct | |
| winsize = fcntl.ioctl(0, termios.TIOCGWINSZ, 'hhhh') | |
| height, width = struct.unpack('hh', winsize) | |
| for y in xrange(1, height + 1): | |
| for x in xrange(1, width + 1): | |
| yield readcell(y, x) | |
| yield u"\n" | |
| vdisable = os.fpathconf(0, 'PC_VDISABLE') | |
| backup = termios.tcgetattr(0) | |
| new = termios.tcgetattr(0) | |
| new[3] &= ~(termios.ECHO | termios.ICANON) | |
| new[6][termios.VMIN] = 1 | |
| new[6][termios.VTIME] = 0 | |
| termios.tcsetattr(0, termios.TCSANOW, new) | |
| try: | |
| print u"".join([c for c in dumpscreen()]) | |
| finally: | |
| termios.tcsetattr(0, termios.TCSANOW, backup) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment