예제 #1
0
    def _get_input(self, wait_tenths):
        # this works around a strange curses bug with window resizing
        # not being reported correctly with repeated calls to this
        # function without a doupdate call in between
        curses.doupdate()

        key = self._getch(wait_tenths)
        resize = False
        raw = []
        keys = []

        while key >= 0:
            raw.append(key)
            if key == KEY_RESIZE:
                resize = True
            elif key == KEY_MOUSE:
                keys += self._encode_mouse_event()
            else:
                keys.append(key)
            key = self._getch_nodelay()

        processed = []

        try:
            while keys:
                run, keys = escape.process_keyqueue(keys, True)
                processed += run
        except escape.MoreInputRequired:
            key = self._getch(self.complete_tenths)
            while key >= 0:
                raw.append(key)
                if key == KEY_RESIZE:
                    resize = True
                elif key == KEY_MOUSE:
                    keys += self._encode_mouse_event()
                else:
                    keys.append(key)
                key = self._getch_nodelay()
            while keys:
                run, keys = escape.process_keyqueue(keys, False)
                processed += run

        if resize:
            processed.append('window resize')

        return processed, raw
예제 #2
0
    def _get_input(self, wait_tenths):
        # this works around a strange curses bug with window resizing 
        # not being reported correctly with repeated calls to this
        # function without a doupdate call in between
        curses.doupdate() 
        
        key = self._getch(wait_tenths)
        resize = False
        raw = []
        keys = []
        
        while key >= 0:
            raw.append(key)
            if key==KEY_RESIZE: 
                resize = True
            elif key==KEY_MOUSE:
                keys += self._encode_mouse_event()
            else:
                keys.append(key)
            key = self._getch_nodelay()

        processed = []
        
        try:
            while keys:
                run, keys = escape.process_keyqueue(keys, True)
                processed += run
        except escape.MoreInputRequired:
            key = self._getch(self.complete_tenths)
            while key >= 0:
                raw.append(key)
                if key==KEY_RESIZE: 
                    resize = True
                elif key==KEY_MOUSE:
                    keys += self._encode_mouse_event()
                else:
                    keys.append(key)
                key = self._getch_nodelay()
            while keys:
                run, keys = escape.process_keyqueue(keys, False)
                processed += run

        if resize:
            processed.append('window resize')

        return processed, raw
예제 #3
0
 def process_keyqueue(self,codes, more_available):
     code = codes[0]
     if code >127 and code <256 and len(codes)==1:
         key = chr(code)
         key = key.decode('850')
         return key, []
     return escape.process_keyqueue(
                 codes, more_available)
예제 #4
0
파일: cli.py 프로젝트: gbtami/papageorge
 def key_from_gui(self, key):
     self.set_focus('footer')
     # ugly hack! why?!
     key = (10 if key == 65293 else 
             8 if key == 65288 else
             key)
     key = process_keyqueue([key], False)[0][0]
     self.cmd_line.keypress(self.body_size, key)
예제 #5
0
    def parse_input(self, event_loop, callback, codes, wait_for_more=True):
        """
        Read any available input from get_available_raw_input, parses it into
        keys, and calls the given callback.

        The current implementation tries to avoid any assumptions about what
        the screen or event loop look like; it only deals with parsing keycodes
        and setting a timeout when an incomplete one is detected.

        `codes` should be a sequence of keycodes, i.e. bytes.  A bytearray is
        appropriate, but beware of using bytes, which only iterates as integers
        on Python 3.
        """
        # Note: event_loop may be None for 100% synchronous support, only used
        # by get_input.  Not documented because you shouldn't be doing it.
        if self._input_timeout and event_loop:
            event_loop.remove_alarm(self._input_timeout)
            self._input_timeout = None

        original_codes = codes
        processed = []
        try:
            while codes:
                run, codes = escape.process_keyqueue(codes, wait_for_more)
                processed.extend(run)
        except escape.MoreInputRequired:
            # Set a timer to wait for the rest of the input; if it goes off
            # without any new input having come in, use the partial input
            k = len(original_codes) - len(codes)
            processed_codes = original_codes[:k]
            self._partial_codes = codes

            def _parse_incomplete_input():
                self._input_timeout = None
                self._partial_codes = None
                self.parse_input(event_loop,
                                 callback,
                                 codes,
                                 wait_for_more=False)

            if event_loop:
                self._input_timeout = event_loop.alarm(
                    self.complete_wait, _parse_incomplete_input)

        else:
            processed_codes = original_codes
            self._partial_codes = None

        if self._resized:
            processed.append('window resize')
            self._resized = False

        if callback:
            callback(processed, processed_codes)
        else:
            # For get_input
            return processed, processed_codes
예제 #6
0
    def parse_input(self, event_loop, callback, codes, wait_for_more=True):
        """
        Read any available input from get_available_raw_input, parses it into
        keys, and calls the given callback.

        The current implementation tries to avoid any assumptions about what
        the screen or event loop look like; it only deals with parsing keycodes
        and setting a timeout when an incomplete one is detected.

        `codes` should be a sequence of keycodes, i.e. bytes.  A bytearray is
        appropriate, but beware of using bytes, which only iterates as integers
        on Python 3.
        """
        # Note: event_loop may be None for 100% synchronous support, only used
        # by get_input.  Not documented because you shouldn't be doing it.
        if self._input_timeout and event_loop:
            event_loop.remove_alarm(self._input_timeout)
            self._input_timeout = None

        original_codes = codes
        processed = []
        try:
            while codes:
                run, codes = escape.process_keyqueue(
                    codes, wait_for_more)
                processed.extend(run)
        except escape.MoreInputRequired:
            # Set a timer to wait for the rest of the input; if it goes off
            # without any new input having come in, use the partial input
            k = len(original_codes) - len(codes)
            processed_codes = original_codes[:k]
            self._partial_codes = codes

            def _parse_incomplete_input():
                self._input_timeout = None
                self._partial_codes = None
                self.parse_input(
                    event_loop, callback, codes, wait_for_more=False)
            if event_loop:
                self._input_timeout = event_loop.alarm(
                    self.complete_wait, _parse_incomplete_input)

        else:
            processed_codes = original_codes
            self._partial_codes = None

        if self._resized:
            processed.append('window resize')
            self._resized = False

        if callback:
            callback(processed, processed_codes)
        else:
            # For get_input
            return processed, processed_codes
예제 #7
0
    def _run_input_iter(self):
        def empty_resize_pipe():
            # clean out the pipe used to signal external event loops
            # that a resize has occurred
            try:
                while True: os.read(self._resize_pipe_rd, 1)
            except OSError:
                pass

        while True:
            processed = []
            codes = self._get_gpm_codes() + \
                self._get_keyboard_codes()

            original_codes = codes
            try:
                while codes:
                    run, codes = escape.process_keyqueue(
                        codes, True)
                    processed.extend(run)
            except escape.MoreInputRequired:
                k = len(original_codes) - len(codes)
                yield (self.complete_wait, processed,
                    original_codes[:k])
                empty_resize_pipe()
                original_codes = codes
                processed = []

                codes += self._get_keyboard_codes() + \
                    self._get_gpm_codes()
                while codes:
                    run, codes = escape.process_keyqueue(
                        codes, False)
                    processed.extend(run)
            
            if self._resized:
                processed.append('window resize')
                self._resized = False

            yield (self.max_wait, processed, original_codes)
            empty_resize_pipe()
예제 #8
0
    def _run_input_iter(self):
        def empty_resize_pipe():
            # clean out the pipe used to signal external event loops
            # that a resize has occured
            try:
                while True: os.read(self._resize_pipe_rd, 1)
            except OSError:
                pass

        while True:
            processed = []
            codes = self._get_gpm_codes() + \
                self._get_keyboard_codes()

            original_codes = codes
            try:
                while codes:
                    run, codes = escape.process_keyqueue(
                        codes, True)
                    processed.extend(run)
            except escape.MoreInputRequired:
                k = len(original_codes) - len(codes)
                yield (self.complete_wait, processed,
                    original_codes[:k])
                empty_resize_pipe()
                original_codes = codes
                processed = []

                codes += self._get_keyboard_codes() + \
                    self._get_gpm_codes()
                while codes:
                    run, codes = escape.process_keyqueue(
                        codes, False)
                    processed.extend(run)
            
            if self._resized:
                processed.append('window resize')
                self._resized = False

            yield (self.max_wait, processed, original_codes)
            empty_resize_pipe()
예제 #9
0
    async def run(self):
        self.clear_input(True)
        self.set_input()

        self.local("text.title")

        while self.connected:
            t = ""
            key = ""

            try:
                t = await self.process.stdin.read(5)
            except asyncssh.BreakReceived:
                continue
            except asyncssh.misc.TerminalSizeChanged:
                continue
            except KeyboardInterrupt:
                break

            if not t:
                continue

            key = process_keyqueue(t.encode("utf-8"), True)[0][0]

            if len(key) == 1:  # wtf? u a crazy
                if len(self.text) < 100:
                    self.text += t
                    self.cursor += 1
                    self.write(t)

            elif key in ("ctrl d", "ctrl c"):
                self.exit()

            elif key == "backspace":
                if self.text:
                    self.text = self.text[:-1]
                    self.write("\b \b")

            elif key == "ctrl w":
                self.clear_input(True)
                self.set_input()

            elif key == "enter":
                if self.text.strip():
                    super().event_key_enter(self.text.strip())
                    self.clear_input()
                    self.set_input()
            elif key == "tab":
                if self.text.strip():
                    self.event_key_tab(self.text.strip())
            else:
                super().event_key(key)
예제 #10
0
파일: cli.py 프로젝트: drestebon/papageorge
 def key_from_gui(self, key):
     self.set_focus('footer')
     # ugly hack! why?!
     if key == 65506:
         return
     elif key == 65056:
         key = 'shift tab'
     else:
         key = (10 if key == 65293 else
                 9 if key == 65289 else
                 8 if key == 65288 else
                 key)
         key = process_keyqueue([key], False)[0][0]
     self.cmd_line.keypress(self.body_size, key)