Beispiel #1
0
def stdin_to_command(screen, height, type, HOST):
    screen.move(height, 0)
    screen.clrtoeol()
    if (type == 0):  # provides two interface: before and after the protocol initialisation
        screen.addstr("[RMP Interface]> ")
    elif (type == 1):
        screen.addstr(height, 0, "[RMP node " + str(HOST) + "]# ")

    ERASE = stdin_to_command.ERASE = getattr(stdin_to_command, "erasechar", ord(curses.erasechar()))
    Y, X = screen.getyx()
    s = []
    while True:
        c = screen.getch()
        if c in (curses.ascii.LF, curses.ascii.CR, curses.KEY_ENTER):
            break
        elif c == ERASE or c == curses.KEY_BACKSPACE:
            y, x = screen.getyx()
            if x > X:
                del s[-1]
                screen.move(y, (x - 1))
                screen.clrtoeol()
                screen.refresh()
        elif c in PRINTABLE:
            s.append(chr(c))
            screen.addch(c)
        else:
            pass
    return "".join(s)
Beispiel #2
0
def process_key(code):
    """Process a key press.

    `code` is ncurses key code or a single unicode character."""
    global default_handler
    if not is_key_unhandled((code,meta)):
        for i in (1, 2):
            for t in [t for t in keytables if t.active]:
                try:
                    return t.process_key(code,meta)
                except (KeyBindingNotFoundError, FunctionNotFoundError):
                    continue
            if code == curses.erasechar():
                # workaround for bad terminfo
                code = curses.KEY_BACKSPACE
            else:
                break
        unhandled_keys[code,meta]=True
    if default_handler:
        return default_handler(code,meta)
    else:
        try:
            logging.getLogger("cjc.ui.keytable").debug("Unhandled key: "+keycode_to_name(code,meta))
            curses.beep()
        except curses.error:
            pass
        return 0
def input(screen):
    ERASE = input.ERASE = getattr(input, "erasechar", ord(curses.erasechar()))
    Y, X = screen.getyx()
    s = []

    while True:
        c = screen.getch()

        if c in (curses.ascii.LF, curses.ascii.CR, curses.KEY_ENTER
                 ):  # accept KEY_ENTER, LF or CR for compatibility
            break
        elif c == ERASE or c == curses.KEY_BACKSPACE:  # Both erase and KEY_BACKSPACE used for compatibility
            y, x = screen.getyx()
            if x > X:
                del s[-1]
                screen.move(y, (x - 1))
                screen.clrtoeol()
                screen.refresh()
        elif c in PRINTABLE:
            s.append(chr(c))
            screen.addch(c)
        else:
            pass

    return "".join(s)
Beispiel #4
0
def validator(c):
  if c == curses.ascii.NL or c == curses.ascii.CR:
    return curses.ascii.BEL
  elif c == curses.erasechar():
    return curses.ascii.BS
  else:
    return c
Beispiel #5
0
def process_key(code):
    """Process a key press.

    `code` is ncurses key code or a single unicode character."""
    global default_handler
    if not is_key_unhandled((code, meta)):
        for i in (1, 2):
            for t in [t for t in keytables if t.active]:
                try:
                    return t.process_key(code, meta)
                except (KeyBindingNotFoundError, FunctionNotFoundError):
                    continue
            if code == curses.erasechar():
                # workaround for bad terminfo
                code = curses.KEY_BACKSPACE
            else:
                break
        unhandled_keys[code, meta] = True
    if default_handler:
        return default_handler(code, meta)
    else:
        try:
            logging.getLogger("cjc.ui.keytable").debug(
                "Unhandled key: " + keycode_to_name(code, meta))
            curses.beep()
        except curses.error:
            pass
        return 0
Beispiel #6
0
def validator(c):
    if c == curses.ascii.NL or c == curses.ascii.CR:
        return curses.ascii.BEL
    elif c == curses.erasechar():
        return curses.ascii.BS
    else:
        return c
Beispiel #7
0
 def setup(self):
     """
     Method to run once that initializes a hackchat connection and the
     curses interface
     """
     self.chatter = chat(self.nickname, self.channel)
     #self.stdscr = curses.initscr()
     # define curses color pairs
     set_color_pairs()
     # set getch to blocking
     self.stdscr.nodelay(0)
     # don't echo key strokes on the screen
     curses.noecho()
     # read keystrokes instantly, without waiting for enter to be pressed
     curses.cbreak()
     # enable keypad mode
     self.stdscr.keypad(1)
     # draw the main frame
     self.setup_draw()
     curses.curs_set(0)
     # find what's the erase character
     self.del_char = curses.erasechar()
     self.chatter.run()
     self.backspace()
     self.refresh_body()
Beispiel #8
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 )
Beispiel #9
0
    def stdin_fixed(self, screen, height, type):
        global PRINTABLE

        screen.move(height, 0)
        screen.clrtoeol()
        if (type == 0):
            screen.addstr("Level1> ")
        elif (type == 1):
            screen.addstr("Level2> ")

        ERASE = self.stdin_fixed.ERASE = getattr(self.stdin_fixed, "erasechar", ord(curses.erasechar()))
        Y, X = screen.getyx()
        s = []
        while True:
            c = screen.getch()
            if c in (curses.ascii.LF, curses.ascii.CR, curses.KEY_ENTER):
                break
            elif c == ERASE or c == curses.KEY_BACKSPACE:
                y, x = screen.getyx()
                if x > X:
                    del s[-1]
                    screen.move(y, (x - 1))
                    screen.clrtoeol()
                    screen.refresh()
            elif c in PRINTABLE:
                s.append(chr(c))
                screen.addch(c)
            else:
                pass
        return "".join(s)
Beispiel #10
0
def add_snake(screen, **kwargs):
    curses.erasechar()
    screen.refresh()
    global SNAKE
    cursor_x = kwargs.pop('cursor_x')
    cursor_y = kwargs.pop('cursor_y')
    direction = kwargs.pop('direction')
    if direction in {'left', 'right'} or len(SNAKE) == 1:
        screen.addstr(cursor_y, cursor_x, SNAKE, curses.color_pair(1))
    else:
        pos = -len(SNAKE)
        for i in range(len(SNAKE)):
            screen.addstr(cursor_y + pos, cursor_x, SNAKE[0],
                          curses.color_pair(1))
            pos += 1
    screen.move(cursor_y, cursor_x)
    return cursor_x, cursor_y, direction
Beispiel #11
0
    def inner_loop(self, stdscr):
        self.stdscr = stdscr

        self.controller = Controller(self)
        c = ""
        while c != "`":  # main loops waits for Ctrl+C
            c = self.get_next_key()
            if ord(c) == ord(curses.erasechar()):
                self.controller.sendKey(Key(special="ERASE"))
                y, x = stdscr.getyx()
                stdscr.delch(y, x - 1)
            elif ord(c) not in [ord("\n"), curses.KEY_ENTER]:
                self.controller.sendKey(Key(c))
Beispiel #12
0
 def setup(self, stdscr):
     self.stdscr = stdscr
     # define curses color pairs
     set_color_pairs()
     # set getch to blocking
     self.stdscr.nodelay(0)
     # don't echo key strokes on the screen
     curses.noecho()
     # read keystrokes instantly, without waiting for enter to be pressed
     curses.cbreak()
     # enable keypad mode
     self.stdscr.keypad(1)
     # draw the main frame
     self.setup_draw()
     # find what's the erase character
     self.del_char = curses.erasechar()
     self.run()
def main(screen):
    maxy, maxx = screen.getmaxyx()
    q = 0
    commands = list()
    x = 0
    erasecode = ord(curses.erasechar())
    getch = screen.getch if PY2 else screen.get_wch
    while q != 27:
        q = getch()
        if not PY2:
            keycode = ord(q)
        else:
            keycode = q
        if keycode == erasecode:
            command = commands.pop(-1).delete()
            x -= 1
            continue
        command = AddCharCommand(screen, 0, maxy / 2, x, q)
        commands.append(command)
        command.write()
        x += 1
Beispiel #14
0
def input(stdscr):
    ERASE = input.ERASE = getattr(input, "ERASE", ord(erasechar()))
    Y, X = stdscr.getyx()
    s = []

    while True:
        c = stdscr.getch()

        if c in (13, 10):
            break
        elif c == ERASE or c==KEY_BACKSPACE:
            y, x = stdscr.getyx()
            if x > X:
                del s[-1]
                stdscr.move(y, (x - 1))
                stdscr.clrtoeol()
                stdscr.refresh()
        elif c in PRINTABLE:
            s.append(chr(c))
            stdscr.addch(c)

    return "".join(s)
Beispiel #15
0
def input(stdscr):
    ERASE = input.ERASE = getattr(input, "erasechar", ord(curses.erasechar()))
    Y, X = stdscr.getyx()
    s = []

    while True:
        c = stdscr.getch()

        if c in (13, 10):
            break
        elif c == ERASE or c == curses.KEY_BACKSPACE:
            y, x = stdscr.getyx()
            if x > X:
                del s[-1]
                stdscr.move(y, (x - 1))
                stdscr.clrtoeol()
                stdscr.refresh()
        elif c in PRINTABLE:
            s.append(chr(c))
            stdscr.addch(c)
        else:
            pass

    return "".join(s)
def input(screen):
    ERASE = input.ERASE = getattr(input, "erasechar", ord(curses.erasechar()));
    Y, X = screen.getyx();
    s = [];

    while True:
        c = screen.getch();
        
        if c in (curses.ascii.LF, curses.ascii.CR, curses.KEY_ENTER): #accept KEY_ENTER, LF or CR for compatibility
            break;
        elif c == ERASE or c == curses.KEY_BACKSPACE: #Both erase and KEY_BACKSPACE used for compatibility
            y, x = screen.getyx();
            if x > X:
                del s[-1];
                screen.move(y, (x - 1));
                screen.clrtoeol();
                screen.refresh();
        elif c in PRINTABLE:
            s.append(chr(c));
            screen.addch(c);
        else:
            pass

    return "".join(s)
def progmain(mainscr):
    global win
    global inputstr
    global portname
    global prompt
    global name_to_phys
    global state
    global phys_to_mount
    global name_to_status
    global disk
    global name_to_thread

    start_time = time.time()
    elapsed_time = time.time() - start_time

    phys_to_name = {v: k for k, v in name_to_phys.items()}  # this inverts the dictionary

    for keys in name_to_phys:
        name_to_status[keys] = 'Insert drive...'

    for keys in phys_to_name:
        phys_to_mount[keys] = 'none'

    mainscr.clear()

    win = curses.newwin(height, width, begin_y, begin_x)
    win.nodelay(1) # non-blocking input

    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by('usb')
    monitor.filter_by('block')

    observer = pyudev.MonitorObserver(monitor, log_event)
    observer.start()

    while True:
        with winLock:
            win.move(nc_action[1], nc_action[0])
            win.clrtoeol()
            win.addnstr(nc_action[1], nc_action[0], 'Action: ' + action_status, width)
            win.move(nc_devpath[1],nc_devpath[0])
            win.clrtoeol()
            win.addnstr(nc_devpath[1], nc_devpath[0], 'Device: ' + device_status, width) # "mount" mapping
            win.move(nc_sysname[1],nc_sysname[0])
            win.clrtoeol()
            win.addnstr(nc_sysname[1], nc_sysname[0], 'Sysname: ' + sysname_status, width) # "phys" mapping

            offset = 0
            for port in sorted(name_to_phys):
                win.move(nc_portarray[1] + offset, nc_portarray[0])
                win.clrtoeol()
                win.addnstr(nc_portarray[1] + offset, nc_portarray[0], port + ":" + name_to_status[port], width)
                offset = offset + 1

            win.border()
            win.move(nc_prompt[1], nc_prompt[0])
            win.clrtobot()
            win.addnstr(nc_prompt[1], nc_prompt[0], prompt, width)
            win.addnstr(nc_input[1], nc_input[0], replprompt, width)
            win.addnstr(nc_input[1], nc_input[0] + len(replprompt), inputstr, width-2)
            win.move(nc_input[1], nc_input[0] + len(inputstr) + len(replprompt))

            win.refresh()

        try:
            c = win.getch()
        except:
            c = ''

        time.sleep(0.05)

        if c == ord('Q') or c == ord('"'):
            observer.stop()
            return
        elif c in(curses.KEY_BACKSPACE, curses.KEY_DL, 127, curses.erasechar()):
            win.delch(nc_input[1], nc_input[0] + len(inputstr) + len(replprompt))
            inputstr = inputstr[:-1]
        elif c == ord('\n'):
            inputstr = ''
        elif c == ord('B') or c == ord('X'):
            if state == 'WAIT_INSERT':
                state = 'BURNING'
                prompt = 'Burning, please wait...'
                name_to_thread.clear()
                for keys in name_to_status:
                    if name_to_status[keys] == 'Insert drive...':
                        name_to_status[keys] = '[]'
                    else:
                        name_to_status[keys] = 'Starting burn...'
                        mount = phys_to_mount[name_to_phys[keys]]
                        name_to_thread[keys] = BurnThread(name="BurnThread{}".format(mount), mountpoint=mount, namedport=keys)

                for keys in name_to_thread:
                    name_to_thread[keys].start()
            else:
                prompt = 'Please be patient...'
            inputstr = ''
        elif c != curses.ERR:
            inputstr = inputstr + chr(c)

        if state == 'BURNING':
            active_burn = False
            for keys in name_to_thread:
                if name_to_thread[keys].isAlive():
                    active_burn = True

            if not active_burn:
                prompt = "Syncing filesystems..."
                win.move(nc_prompt[1], nc_prompt[0])

                win.clrtobot()
                win.addnstr(nc_prompt[1], nc_prompt[0], prompt, width)
                win.addnstr(nc_input[1], nc_input[0], replprompt, width)
                win.addnstr(nc_input[1], nc_input[0] + len(replprompt), inputstr, width - 2)
                win.move(nc_input[1], nc_input[0] + len(inputstr) + len(replprompt))
                win.refresh()

                p = subprocess.Popen(["sync"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
                p.wait()

                prompt = "Burn finished, remove disks..."
                state = 'REMOVE'
        elif state == 'REMOVE':
            if elapsed_time > 10:
                start_time = time.time()
                p = subprocess.Popen(["aplay", "alert.wav"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
                p.wait()

            elapsed_time = time.time() - start_time

            all_removed = True
            for keys in name_to_status:
                if not(name_to_status[keys] == 'Insert drive...' or name_to_status[keys] == '[]'):
                    all_removed = False

            if all_removed:
                for keys in name_to_status:
                    name_to_status[keys] = 'Insert drive...'
                    prompt = "Insert drives, then press B to start mass burn, or Q to quit..."
                    state = 'WAIT_INSERT'
Beispiel #18
0
 def get_erasechar(self):
     return curses.erasechar()
Beispiel #19
0
 def validate(self, ch):
   if ch == ord(curses.erasechar()):
     (y,x) = self.textwin.getyx()
     self.textwin.move(y,x-1)
     self.textwin.delch()
   return ch
Beispiel #20
0
import curses
screen = curses.initscr()
screen.addstr(2, 2, str(curses.erasechar()))
screen.getch()
curses.endwin()
Beispiel #21
0
 def get_erasechar(self):
     return curses.erasechar()