Beispiel #1
0
def general_keycodes():
    keycodes = {}
    for key, tiname in _keynames.items():
        keycode = curses.tigetstr(tiname)
        trace("key {key} tiname {tiname} keycode {keycode!r}", **locals())
        if keycode:
            keycodes[keycode] = key
    return keycodes
Beispiel #2
0
def general_keycodes():
    keycodes = {}
    for key, tiname in _keynames.items():
        keycode = curses.tigetstr(tiname)
        trace('key {key} tiname {tiname} keycode {keycode!r}', **locals())
        if keycode:
            keycodes[keycode] = key
    return keycodes
Beispiel #3
0
def general_keycodes():
    keycodes = {}
    for key, tiname in _keynames.items():
        keycode = curses.tigetstr(tiname)
        trace('key {key} tiname {tiname} keycode {keycode!r}', **locals())
        if keycode:
            keycodes[keycode] = key
    keycodes.update(CTRL_ARROW_KEYCODE)
    return keycodes
Beispiel #4
0
def general_keycodes():
    keycodes = {}
    for key, tiname in _keynames.items():
        keycode = curses.tigetstr(tiname)
        trace('key {key} tiname {tiname} keycode {keycode!r}', **locals())
        if keycode:
            keycodes[keycode] = key
    keycodes.update(CTRL_ARROW_KEYCODE)
    return keycodes
Beispiel #5
0
 def __init__(self, fd):
     our_keycodes = {}
     for key, tiname in _keynames.items():
         keycode = curses.tigetstr(tiname)
         if keycode:
             our_keycodes[keycode] = unicode(key)
     our_keycodes[tcgetattr(fd)[6][VERASE]] = u'backspace'
     self.k = self.ck = keymap.compile_keymap(our_keycodes)
     self.events = []
     self.buf = []
Beispiel #6
0
 def __init__(self, fd):
     our_keycodes = {}
     for key, tiname in _keynames.items():
         keycode = curses.tigetstr(tiname)
         if keycode:
             our_keycodes[keycode] = unicode(key)
     our_keycodes[tcgetattr(fd)[6][VERASE]] = u'backspace'
     self.k = self.ck = keymap.compile_keymap(our_keycodes)
     self.events = []
     self.buf = []
Beispiel #7
0
def _my_getstr(cap, optional=0):
    r = curses.tigetstr(cap)
    if not optional and r is None:
        raise InvalidTerminal, \
              "terminal doesn't have the required '%s' capability"%cap
    return r
Beispiel #8
0
    def refresh(self, screen, cxy):
        # this function is still too long (over 90 lines)

        if not self.__gone_tall:
            while len(self.screen) < min(len(screen), self.height):
                self.__hide_cursor()
                self.__move(0, len(self.screen) - 1)
                self.__write("\n")
                self.__posxy = 0, len(self.screen)
                self.screen.append("")
        else:
            while len(self.screen) < len(screen):
                self.screen.append("")            

        if len(screen) > self.height:
            self.__gone_tall = 1
            self.__move = self.__move_tall

        px, py = self.__posxy
        old_offset = offset = self.__offset
        height = self.height

        if 0:
            global counter
            try:
                counter
            except NameError:
                counter = 0
            self.__write_code(curses.tigetstr("setaf"), counter)
            counter += 1
            if counter > 8:
                counter = 0

        # we make sure the cursor is on the screen, and that we're
        # using all of the screen if we can
        cx, cy = cxy
        if cy < offset:
            offset = cy
        elif cy >= offset + height:
            offset = cy - height + 1
        elif offset > 0 and len(screen) < offset + height:
            offset = max(len(screen) - height, 0)
            screen.append("")

        oldscr = self.screen[old_offset:old_offset + height]
        newscr = screen[offset:offset + height]

        # use hardware scrolling if we have it.
        if old_offset > offset and self._ri:
            self.__hide_cursor()
            self.__write_code(self._cup, 0, 0)
            self.__posxy = 0, old_offset
            for i in range(old_offset - offset):
                self.__write_code(self._ri)
                oldscr.pop(-1)
                oldscr.insert(0, "")
        elif old_offset < offset and self._ind:
            self.__hide_cursor()
            self.__write_code(self._cup, self.height - 1, 0)
            self.__posxy = 0, old_offset + self.height - 1
            for i in range(offset - old_offset):
                self.__write_code(self._ind)
                oldscr.pop(0)
                oldscr.append("")

        self.__offset = offset

        for y, oldline, newline, in zip(range(offset, offset + height),
                                        oldscr,
                                        newscr):
            if oldline != newline:
                self.__write_changed_line(y, oldline, newline, px)
                
        y = len(newscr)
        while y < len(oldscr):
            self.__hide_cursor()
            self.__move(0, y)
            self.__posxy = 0, y
            self.__write_code(self._el)
            y += 1

        self.__show_cursor()
        
        self.screen = screen
        self.move_cursor(cx, cy)
        self.flushoutput()
Beispiel #9
0
class UnixConsole(Console):
    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 change_encoding(self, encoding):
        self.encoding = encoding

    def refresh(self, screen, (cx, cy)):
        # this function is still too long (over 90 lines)

        if not self.__gone_tall:
            while len(self.screen) < min(len(screen), self.height):
                self.__hide_cursor()
                self.__move(0, len(self.screen) - 1)
                self.__write("\n")
                self.__posxy = 0, len(self.screen)
                self.screen.append("")
        else:
            while len(self.screen) < len(screen):
                self.screen.append("")

        if len(screen) > self.height:
            self.__gone_tall = 1
            self.__move = self.__move_tall

        px, py = self.__posxy
        old_offset = offset = self.__offset
        height = self.height

        if 0:
            global counter
            try:
                counter
            except NameError:
                counter = 0
            self.__write_code(curses.tigetstr("setaf"), counter)
            counter += 1
            if counter > 8:
                counter = 0

        # we make sure the cursor is on the screen, and that we're
        # using all of the screen if we can
        if cy < offset:
            offset = cy
        elif cy >= offset + height:
            offset = cy - height + 1
        elif offset > 0 and len(screen) < offset + height:
            offset = max(len(screen) - height, 0)
            screen.append("")

        oldscr = self.screen[old_offset:old_offset + height]
        newscr = screen[offset:offset + height]

        # use hardware scrolling if we have it.
        if old_offset > offset and self._ri:
            self.__hide_cursor()
            self.__write_code(self._cup, 0, 0)
            self.__posxy = 0, old_offset
            for i in range(old_offset - offset):
                self.__write_code(self._ri)
                oldscr.pop(-1)
                oldscr.insert(0, "")
        elif old_offset < offset and self._ind:
            self.__hide_cursor()
            self.__write_code(self._cup, self.height - 1, 0)
            self.__posxy = 0, old_offset + self.height - 1
            for i in range(offset - old_offset):
                self.__write_code(self._ind)
                oldscr.pop(0)
                oldscr.append("")

        self.__offset = offset

        for y, oldline, newline, in zip(range(offset, offset + height), oldscr,
                                        newscr):
            if oldline != newline:
                self.__write_changed_line(y, oldline, newline, px)

        y = len(newscr)
        while y < len(oldscr):
            self.__hide_cursor()
            self.__move(0, y)
            self.__posxy = 0, y
            self.__write_code(self._el)
            y += 1

        self.__show_cursor()

        self.screen = screen
        self.move_cursor(cx, cy)
        self.flushoutput()
Beispiel #10
0
def _my_getstr(cap, optional=0):
    r = curses.tigetstr(cap)
    if not optional and r is None:
        raise RuntimeError, \
              "terminal doesn't have the required '%s' capability"%cap
    return r
Beispiel #11
0
    def refresh(self, screen, cxy):
        # this function is still too long (over 90 lines)

        if not self.__gone_tall:
            while len(self.screen) < min(len(screen), self.height):
                self.__hide_cursor()
                self.__move(0, len(self.screen) - 1)
                self.__write("\n")
                self.__posxy = 0, len(self.screen)
                self.screen.append("")
        else:
            while len(self.screen) < len(screen):
                self.screen.append("")

        if len(screen) > self.height:
            self.__gone_tall = 1
            self.__move = self.__move_tall

        px, py = self.__posxy
        old_offset = offset = self.__offset
        height = self.height

        if 0:
            global counter
            try:
                counter
            except NameError:
                counter = 0
            self.__write_code(curses.tigetstr("setaf"), counter)
            counter += 1
            if counter > 8:
                counter = 0

        # we make sure the cursor is on the screen, and that we're
        # using all of the screen if we can
        cx, cy = cxy
        if cy < offset:
            offset = cy
        elif cy >= offset + height:
            offset = cy - height + 1
        elif offset > 0 and len(screen) < offset + height:
            offset = max(len(screen) - height, 0)
            screen.append("")

        oldscr = self.screen[old_offset:old_offset + height]
        newscr = screen[offset:offset + height]

        # use hardware scrolling if we have it.
        if old_offset > offset and self._ri:
            self.__hide_cursor()
            self.__write_code(self._cup, 0, 0)
            self.__posxy = 0, old_offset
            for i in range(old_offset - offset):
                self.__write_code(self._ri)
                oldscr.pop(-1)
                oldscr.insert(0, "")
        elif old_offset < offset and self._ind:
            self.__hide_cursor()
            self.__write_code(self._cup, self.height - 1, 0)
            self.__posxy = 0, old_offset + self.height - 1
            for i in range(offset - old_offset):
                self.__write_code(self._ind)
                oldscr.pop(0)
                oldscr.append("")

        self.__offset = offset

        for y, oldline, newline, in zip(range(offset, offset + height), oldscr,
                                        newscr):
            if oldline != newline:
                self.__write_changed_line(y, oldline, newline, px)

        y = len(newscr)
        while y < len(oldscr):
            self.__hide_cursor()
            self.__move(0, y)
            self.__posxy = 0, y
            self.__write_code(self._el)
            y += 1

        self.__show_cursor()

        self.screen = screen
        self.move_cursor(cx, cy)
        self.flushoutput()