Exemplo n.º 1
0
    def handle_search(self):
        """Let user search through items of the list."""
        self.search_mode = True
        self.resize()

        initial = self.current

        maxx = 50
        tw = curses.newwin(1, maxx, self.window.getbegyx()[0] +
            self.window.getmaxyx()[0], 0)
        t = TextInput(tw, '/')
        try:
            curses.curs_set(1)
        except curses.error:
            pass
        while 1:
            try:
                ch = get_char(tw)
            except KeyboardInterrupt:
                self._goto(initial)
                break
            try:
                kn = curses.keyname(ch)
            except TypeError:
                kn = ''
            if kn == '^J':
                self.term = t.gather()[1:].lower()
                break
            elif kn == 'KEY_RESIZE':
                self.resize()
                tw = curses.newwin(1, maxx, self.window.getbegyx()[0] +
                    self.window.getmaxyx()[0], 0)
                t.move_to_new_window(tw)
                continue
            t.do_command(ch)
            pat = t.gather()
            if not pat:
                self._goto(initial)
                break
            pat = pat[1:].lower()
            if not pat:
                self._goto(initial)
            found = False
            for index, line in self.get_items(initial, initial - 1):
                if pat in line.lower():
                    found = True
                    self._goto(index)
                    break
            if not found:
                self._goto(initial)
        try:
            curses.curs_set(0)
        except curses.error:
            pass
        self.search_mode = False
        self.resize()
        self.draw()
Exemplo n.º 2
0
    def test_moving(self):
        win = curses.newwin(0, 0)
        t = TextInput(win, '>>>')
        screen = get_screen()

        line = '1 2 3 4 5 6 7 all good children go to heaven'
        for l in line:
            t.do_command(ord(l))
        self.assertEquals(screen.get_line(0), t.gather())
        self.assertEquals(t.gather(), '>>>' + line)

        t.move_to_new_window(curses.newwin(5, 0))
        self.assertEquals(screen.get_line(5), t.gather())
        self.assertEquals(t.gather(), '>>>' + line)

        t.move_to_new_window(curses.newwin(10, 10))
        self.assertEquals(screen.get_line(10), t.gather())
        self.assertEquals(t.gather(), '>>>' + line)
Exemplo n.º 3
0
    def test_input(self):
        win = curses.newwin(0, 0)
        t = TextInput(win, '/')
        screen = get_screen()

        line = ''
        def check():
            self.assertEquals(screen.get_line(0), t.gather())
            self.assertEquals(t.gather(), '/' + line)

        check()

        letters = [chr(c) for c in range(97, 123)]
        for i in range(15):
            l = random.choice(letters)
            line += l
            t.do_command(ord(l))
            check()

        t.do_command(curses.KEY_BACKSPACE)
        line = line[:-1]
        check()

        for i in range(len(line) + 5):
            t.do_command(curses.KEY_LEFT)
            check()
        l = random.choice(letters)
        t.do_command(ord(l))
        line = l + line
        check()

        t.do_command(curses.KEY_DC)
        line = line[0] + line[2:]
        check()

        t.do_command(curses.KEY_END)
        l = random.choice(letters)
        t.do_command(ord(l))
        line += l
        check()

        t.do_command(curses.KEY_HOME)
        l = random.choice(letters)
        t.do_command(ord(l))
        line = l + line
        check()

        for i in range(len(line) + 5):
            t.do_command(curses.KEY_RIGHT)
            check()
        l = random.choice(letters)
        t.do_command(ord(l))
        line += l
        check()

        for i in range(len(line)):
            t.do_command(curses.KEY_BACKSPACE)
            line = line[:-1]
            check()
        self.assertEquals(line, '')
        t.do_command(curses.KEY_BACKSPACE)
        self.assertEquals(screen.get_line(0), t.gather())
        self.assertEquals(t.gather(), '')