예제 #1
0
def curses_status( ca, args ):
    ca.stdscr.addstr(
        "Baudrate      : %s\n" % curses.baudrate() )
    ca.stdscr.addstr(
        "Has color     : %s\n" % curses.has_colors() )
    ca.stdscr.addstr(
        "Change color  : %s\n" % curses.can_change_color() )
    ca.stdscr.addstr(
        "Insert char   : %s\n" % curses.has_ic() )
    ca.stdscr.addstr(
        "Insert line   : %s\n" % curses.has_il() )
    ca.stdscr.addstr(
        "Color numbers : 0-%s\n" % curses.COLORS )
    ca.stdscr.addstr(
        "COLOR_WHITE   : %s\n" % (curses.color_content(curses.COLOR_WHITE),) )
    ca.stdscr.addstr(
        "COLOR_BLACK   : %s\n" % (curses.color_content(curses.COLOR_BLACK),) )
    ca.stdscr.addstr(
        "COLOR_RED     : %s\n" % (curses.color_content(curses.COLOR_RED),) )
    ca.stdscr.addstr(
        "COLOR_GREEN   : %s\n" % (curses.color_content(curses.COLOR_GREEN),) )
    ca.stdscr.addstr(
        "COLOR_BLUE    : %s\n" % (curses.color_content(curses.COLOR_BLUE),) )
    ca.stdscr.addstr(
        "COLOR_YELLOW  : %s\n" % (curses.color_content(curses.COLOR_YELLOW),) )
    ca.stdscr.addstr(
        "COLOR_MAGENTA : %s\n" % (curses.color_content(curses.COLOR_MAGENTA),))
    ca.stdscr.addstr(
        "COLOR_CYAN    : %s\n" % (curses.color_content(curses.COLOR_CYAN),) )
    ca.stdscr.addstr(
        "Erase char    : %s\n" % (curses.erasechar(),) )

    ls = list( filter( lambda x: curses.has_key(x), range(255) ))
    ca.stdscr.addstr(
        "Unknown keys  : %s\n" % ls )
예제 #2
0
 def setterm(self, term):
     """Set the curses structures for this terminal"""
     log.debug("Setting term type to %s" % (term, ))
     curses.initscr()
     curses.setupterm(
         term)  # This will raise if the termtype is not supported
     self.TERM = term
     self.ESCSEQ = {}
     for k in list(self.KEYS.keys()):
         str = has_key(k)
         if str:
             self.ESCSEQ[str] = k
     # Create a copy to prevent altering the class
     self.CODES = self.CODES.copy()
     self.CODES['DEOL'] = curses.tigetstr('el')
     self.CODES['DEL'] = curses.tigetstr('dch1')
     self.CODES['INS'] = curses.tigetstr('ich1')
     self.CODES['CSRLEFT'] = curses.tigetstr('cub1')
     self.CODES['CSRRIGHT'] = curses.tigetstr('cuf1')
예제 #3
0
def module_funcs(stdscr):
    "Test module-level functions"

    for func in [curses.baudrate, curses.beep, curses.can_change_color,
                 curses.cbreak, curses.def_prog_mode, curses.doupdate,
                 curses.filter, curses.flash, curses.flushinp,
                 curses.has_colors, curses.has_ic, curses.has_il,
                 curses.isendwin, curses.killchar, curses.longname,
                 curses.nocbreak, curses.noecho, curses.nonl,
                 curses.noqiflush, curses.noraw,
                 curses.reset_prog_mode, curses.termattrs,
                 curses.termname, curses.erasechar, curses.getsyx]:
        func()

    # Functions that actually need arguments
    if curses.tigetstr("cnorm"):
        curses.curs_set(1)
    curses.delay_output(1)
    curses.echo() ; curses.echo(1)

    f = tempfile.TemporaryFile()
    stdscr.putwin(f)
    f.seek(0)
    curses.getwin(f)
    f.close()

    curses.halfdelay(1)
    curses.intrflush(1)
    curses.meta(1)
    curses.napms(100)
    curses.newpad(50,50)
    win = curses.newwin(5,5)
    win = curses.newwin(5,5, 1,1)
    curses.nl() ; curses.nl(1)
    curses.putp('abc')
    curses.qiflush()
    curses.raw() ; curses.raw(1)
    curses.setsyx(5,5)
    curses.tigetflag('hc')
    curses.tigetnum('co')
    curses.tigetstr('cr')
    curses.tparm('cr')
    curses.typeahead(sys.__stdin__.fileno())
    curses.unctrl('a')
    curses.ungetch('a')
    curses.use_env(1)

    # Functions only available on a few platforms
    if curses.has_colors():
        curses.start_color()
        curses.init_pair(2, 1,1)
        curses.color_content(1)
        curses.color_pair(2)
        curses.pair_content(curses.COLOR_PAIRS - 1)
        curses.pair_number(0)

        if hasattr(curses, 'use_default_colors'):
            curses.use_default_colors()

    if hasattr(curses, 'keyname'):
        curses.keyname(13)

    if hasattr(curses, 'has_key'):
        curses.has_key(13)

    if hasattr(curses, 'getmouse'):
        (availmask, oldmask) = curses.mousemask(curses.BUTTON1_PRESSED)
        # availmask indicates that mouse stuff not available.
        if availmask != 0:
            curses.mouseinterval(10)
            # just verify these don't cause errors
            m = curses.getmouse()
            curses.ungetmouse(*m)
예제 #4
0
import curses
curses.initscr()
inpu = curses.has_key('q')
if inpu == 'q':
    exit
'''import msvcrt

while True:
	x = msvcrt.kbhit()
	if x:
		ret = msvcrt.getch()
		print ret.decode()
	else:
		print "No key entered"
else:
	print "Exiting"
'''
예제 #5
0
    def userStringLine(self,
                       label=None,
                       complete=None,
                       default=None,
                       prompt="> ",
                       history=[]):
        user = default if not default == None else ""
        hints = list()
        historyIdx = 0

        cursorIndex = len(user)
        userDisplayIndex = 0

        curses.curs_set(1)
        try:
            while True:

                # Validate userDisplayIndex and cursorIndex
                #   Make sure we have at least one char at the end to place the cursor
                #   after the last char of the user input.
                #   The userDisplayIndex should be move such that the cursorIndex is visible
                if cursorIndex < 0:
                    cursorIndex = 0

                if cursorIndex < userDisplayIndex:
                    userDisplayIndex = cursorIndex

                visibleLength = self.rect.width - len(prompt)
                if visibleLength < 0:
                    visibleLength = 0

                if cursorIndex > len(user):
                    cursorIndex = len(user)

                if cursorIndex - userDisplayIndex > visibleLength:
                    userDisplayIndex = cursorIndex - visibleLength

                cursorPosY = len(prompt) + cursorIndex - userDisplayIndex
                if cursorPosY >= self.rect.width:
                    cursorPosY = None

                height = 1
                if not label == None:
                    height += 1

                maxHints = min(self.rect.height - height, 20) - 1

                if len(hints) > maxHints:
                    hints = hints[:maxHints] + ["(list truncated)"]
                height += len(hints)

                maxlen = self.rect.width
                y = self.rect.y + self.rect.height - height
                x = self.rect.x

                self.update()

                # display the label in one line
                # then display possible hints
                # then display > and the user strings last bytes

                if not label == None:
                    self.stdscr.addnstr(y, x, label.ljust(maxlen), maxlen,
                                        curses.A_STANDOUT | curses.A_BOLD)
                    y += 1

                for h in hints:
                    self.stdscr.addnstr(y, x, h.ljust(maxlen), maxlen,
                                        curses.A_STANDOUT)
                    y += 1

                msg = (prompt + user[userDisplayIndex:])
                self.stdscr.addnstr(y, x, msg, maxlen)
                self.stdscr.clrtoeol()

                if not cursorPosY == None:
                    self.stdscr.move(y, self.rect.y + cursorPosY)

                c = self.stdscr.getch()
                if c == curses.KEY_RESIZE:
                    self.resize()
                    self.update()
                elif c == curses.KEY_DC:
                    if not cursorIndex == len(user):
                        user = user[:cursorIndex] + user[cursorIndex + 1:]
                elif c == curses.KEY_BACKSPACE or c == curses.ascii.DEL:
                    if not cursorIndex == 0:
                        user = user[:cursorIndex - 1] + user[cursorIndex:]
                        cursorIndex -= 1
                elif c == ord('\n') or c == ord('\r'):
                    self.update()
                    return user
                elif c == curses.KEY_LEFT:
                    cursorIndex -= 1
                elif c == curses.KEY_RIGHT:
                    cursorIndex += 1
                elif c == curses.KEY_HOME:
                    cursorIndex = 0
                elif c == curses.KEY_END:
                    cursorIndex = len(user)
                elif c == curses.KEY_UP:
                    historyIdx = max(historyIdx - 1, -len(history))
                    if not historyIdx == 0:
                        user = history[historyIdx]
                        cursorIndex = len(user)
                    else:
                        user = ""
                elif c == curses.KEY_DOWN:
                    historyIdx = min(historyIdx + 1, 0)
                    if not historyIdx == 0:
                        user = history[historyIdx]
                        cursorIndex = len(user)
                    else:
                        user = ""
                elif c == ord('\t'):
                    # tabulator, time for auto complete
                    if not complete == None:
                        hints = list()
                        hint = complete(user)
                        if isinstance(hint, list):
                            hints = hint
                        elif isinstance(hint, str):
                            user = hint
                            cursorIndex = len(user)
                        elif isinstance(hint, tuple):
                            user = hint[0]
                            hints = list(hint[1])
                            cursorIndex = len(user)
                elif not curses.has_key(c):
                    user = user[:cursorIndex] + chr(c) + user[cursorIndex:]
                    cursorIndex += 1
        finally:
            curses.curs_set(0)
예제 #6
0
#
예제 #7
0
#