Exemple #1
0
def scrub(value):
    """
    Clean up the incoming queries to remove unfriendly 
    characters that may come from copy and pasted citations.
    """
    from curses import ascii
    if not value:
        return
    n = ''.join([c for c in value.strip() if not ascii.isctrl(c)])
    return n
Exemple #2
0
    def key_get(self):
        key1 = self._window.getch()
        key2 = self._window.getch() if (key1 == ascii.ESC) else None

        meta = (key1 == ascii.ESC)
        key = (key2 if meta else key1)
        # FIX: Ugly hack to make TAB work:
        if (key == ascii.TAB):
            ctrl = False
        else:
            ctrl = isctrl(key)
            key = ord(unctrl(key)[-1].lower()) if (key < 0x20) else key

        return Key(key, ctrl, meta)
Exemple #3
0
def scrub(value):
    """
    Clean up the incoming queries to remove unfriendly
    characters that may come from copy and pasted citations.

    Also remove all punctuation from text.

    """
    if not value:
        return
    n = ''.join([c for c in value.strip() if not ascii.isctrl(c)])
    #Strip newline or \f characters.
    n2 = n.replace('\n', '').replace('\f', '')
    cleaned = ''.join(ch for ch in n2 if ch not in punctuation)
    return cleaned
Exemple #4
0
def scrub(value):
    """
    Clean up the incoming queries to remove unfriendly
    characters that may come from copy and pasted citations.

    Also remove all punctuation from text.

    """
    if not value:
        return
    n = ''.join([c for c in value.strip() if not ascii.isctrl(c)])
    #Strip newline or \f characters.
    n2 = n.replace('\n', '').replace('\f', '')
    cleaned = ''.join(ch for ch in n2 if ch not in punctuation)
    return cleaned
Exemple #5
0
def prompt(message, default=None, characters=None):
    """Prompt for input.

    :param message: The prompt message.
    :param default: Default `None`. The default input value.
    :param characters: Default `None`. Case-insensitive constraint for single-
        character input.
    """
    if isinstance(default, basestring):
        message = "{0} [{1}]".format(message, default)

    if characters:
        puts("{0} ".format(message), newline=False)
    else:
        message = "{0}: ".format(message)

    while True:
        if characters:
            ret_val = getch()

            if default is not None and ret_val in (chr(CR), chr(LF)):
                puts()
                ret_val = default
                break
            if ret_val in characters.lower() or ret_val in characters.upper():
                puts()

                if ret_val not in characters:
                    ret_val = ret_val.swapcase()

                break
            elif isctrl(ret_val) and ctrl(ret_val) in (chr(ETX), chr(EOT)):
                raise KeyboardInterrupt
        else:
            ret_val = raw_input(message).strip() or default

            if ret_val:
                break

    return ret_val
Exemple #6
0
def scrub_literal(value):
    """
    Scrubs control characters from the incoming values to remove
    things like form feeds (\f) and line breaks (\n) which might 
    cause problems with Jena.

    Data with these characters was found in the Backstage data.
    """
    from curses import ascii
    import unicodedata
    if not value:
        return
    if (type(value) == long) or (type(value) == int):
        return value
    n = ''.join([c for c in value if not ascii.iscntrl(c)\
                if not ascii.isctrl(c)])
    #n = ''.join(new)
    n = n.replace('"', '')
    n = n.replace('\ufffd', '')
    n = clean_text(n)
    if type(n) != unicode:
        n = unicode(n, errors='replace')
    return n.strip()
Exemple #7
0
	def _input_iteration(self):
		ch = self.mainscr.getch()
		if QUITTING_TIME.isSet(): return False
		logging.debug("input: %r (%s / %s, ctrl=%s)" % (ch, ascii.unctrl(ch), ascii.ctrl(ch), ascii.isctrl(ch)))
		if ascii.isprint(ch):
			self.add_char(chr(ch))
		elif ch in (ascii.BS, ascii.DEL, curses.KEY_BACKSPACE):
			self.remove_char()
		elif ch == ascii.NL:
			self.open_selected()
		elif ch == curses.KEY_UP or (ascii.ismeta(ch) and ascii.unctrl(ch) == 'a'): # shift+tab???
			self.select(PREVIOUS)
		elif ch == curses.KEY_DOWN or ch == curses.ascii.TAB:
			self.select(NEXT)
		elif ch == curses.KEY_LEFT:
			self.move_cursor(backwards=True)
		elif ch == curses.KEY_RIGHT:
			self.move_cursor()
		elif ch == curses.KEY_HOME:
			self.move_cursor_to(0)
		elif ch == curses.KEY_END:
			self.move_cursor_to(len(self.query))
		elif ascii.isctrl(ch) and ascii.ctrl(ch) in (ascii.STX, ascii.ETX, ascii.CAN, ascii.ETX): # ctrl-c, variously o_O
			logging.debug("copy to clipboard")
			self.copy_selected_path_to_clipboard()
		elif ch == ascii.ESC:
			self.set_query("")
		elif ch == ascii.EOT: # ctrl-D
			logging.debug("EOF")
			return False
		else:
			logging.debug("not handled...")
		self.ui_lock.acquire()
		self.update()
		self.ui_lock.release()
		return True
Exemple #8
0
    def _needescape(c):
        """
        Return True if character needs escaping, else False.
        """

        return not ascii.isprint(c) or c == '"' or c == '\\' or ascii.isctrl(c)
Exemple #9
0
def key_input():
    # if the next two aren't here, input does not work
    curses.cbreak()
    curses.noecho()
    editWin = gc.ui.editWin
    gc.ui_thread.wait_until_ui_task_completes((ui.draw_edit_win, True))
    while not gc.doExit:
        ch = editWin.getch()
        if ch == -1 or not gc.ui.displayPanel.hidden():
            time.sleep(0.01)
            continue

        if chr(ch) != '\n' and len(gc.ui.messageEdit.inputBuffer) > 0 and \
                gc.ui.messageEdit.inputBuffer[0] != ord('/'):
            gc.typingBeingHandled = True
        # prevents crashes when enter is hit and input buf is empty
        if chr(ch) == '\n' and not gc.ui.messageEdit.inputBuffer:
            continue
        if ch == curses.KEY_PPAGE:
            gc.ui.channel_log_offset -= gc.settings["scroll_lines"]
            ui.draw_screen()
            continue
        elif ch == curses.KEY_NPAGE:
            gc.ui.channel_log_offset += gc.settings["scroll_lines"]
            ui.draw_screen()
            continue
        elif ch == curses.KEY_RESIZE:
            gc.ui.resize()
            ui.draw_screen()
            continue
        elif ch == curses.KEY_DC:
            # TODO: Add functionality here
            ui.draw_screen()
            continue
        # For later ctrl+key combos
        elif ascii.isctrl(ch):
            pass
        elif ch == KEY_CTRL_LEFT:
            gc.client.channel_backward()
            ui.draw_screen()
            continue
        elif ch == KEY_CTRL_RIGHT:
            gc.client.channel_forward()
            ui.draw_screen()
            continue
        # if ESC is pressed, clear messageEdit buffer
        elif ch == 27:
            ch = editWin.getch()
            if ch in (0x7f, ord('\b'), curses.KEY_BACKSPACE):
                gc.ui.messageEdit.reset()
                gc.ui_thread.wait_until_ui_task_completes(
                    (ui.draw_edit_win, True))
            continue
        ret = gc.ui.messageEdit.addKey(ch)
        if ret is not None:
            input_handler(ret)
            gc.ui.messageEdit.reset()
        call = (ui.draw_edit_win, True)
        gc.ui_thread.funcs.append(call)
        while not gc.doExit and (call in gc.ui_thread.funcs or \
                call[0].__name__ in gc.ui_thread.locks):
            time.sleep(0.01)
    log("key_input finished")
    gc.tasksExited += 1