def __init__(self, f_in=0, f_out=1, term=None, encoding=None): if encoding is None: encoding = sys.getdefaultencoding() self.encoding = encoding if isinstance(f_in, int): self.input_fd = f_in else: self.input_fd = f_in.fileno() if isinstance(f_out, int): self.output_fd = f_out else: self.output_fd = f_out.fileno() self.pollob = poll() self.pollob.register(self.input_fd, POLLIN) curses.setupterm(term, self.output_fd) self.term = term self._bel = _my_getstr("bel") self._civis = _my_getstr("civis", optional=1) self._clear = _my_getstr("clear") self._cnorm = _my_getstr("cnorm", optional=1) self._cub = _my_getstr("cub", optional=1) self._cub1 = _my_getstr("cub1", 1) self._cud = _my_getstr("cud", 1) self._cud1 = _my_getstr("cud1", 1) self._cuf = _my_getstr("cuf", 1) self._cuf1 = _my_getstr("cuf1", 1) self._cup = _my_getstr("cup") self._cuu = _my_getstr("cuu", 1) self._cuu1 = _my_getstr("cuu1", 1) self._dch1 = _my_getstr("dch1", 1) self._dch = _my_getstr("dch", 1) self._el = _my_getstr("el") self._hpa = _my_getstr("hpa", 1) self._ich = _my_getstr("ich", 1) self._ich1 = _my_getstr("ich1", 1) self._ind = _my_getstr("ind", 1) self._pad = _my_getstr("pad", 1) self._ri = _my_getstr("ri", 1) self._rmkx = _my_getstr("rmkx", 1) self._smkx = _my_getstr("smkx", 1) ## work out how we're going to sling the cursor around if 0 and self._hpa: # hpa don't work in windows telnet :-( self.__move_x = self.__move_x_hpa elif self._cub and self._cuf: self.__move_x = self.__move_x_cub_cuf elif self._cub1 and self._cuf1: self.__move_x = self.__move_x_cub1_cuf1 else: raise RuntimeError, "insufficient terminal (horizontal)" if self._cuu and self._cud: self.__move_y = self.__move_y_cuu_cud elif self._cuu1 and self._cud1: self.__move_y = self.__move_y_cuu1_cud1 else: raise RuntimeError, "insufficient terminal (vertical)" if self._dch1: self.dch1 = self._dch1 elif self._dch: self.dch1 = curses.tparm(self._dch, 1) else: self.dch1 = None if self._ich1: self.ich1 = self._ich1 elif self._ich: self.ich1 = curses.tparm(self._ich, 1) else: self.ich1 = None self.__move = self.__move_short self.event_queue = unix_eventqueue.EventQueue(self.input_fd) self.partial_char = '' self.cursor_visible = 1
def __write_code(self, fmt, *args): self.__buffer.append((curses.tparm(fmt, *args), 1))