Exemplo n.º 1
0
def test_seq_to_name_no_fallback():
    assert seq_to_name((ord("k"), 20), fallback=False) is None
Exemplo n.º 2
0
    def _update_status_bar(self):
        if self.help.show:
            return

        focused = self.focused
        index = focused.index
        iterator = self.get_iterator(index)
        title = iterator.title
        box_state = focused.state
        wrap = box_state.wrap
        auto_scroll = box_state.auto_scroll
        input_mode = box_state.input_mode

        modes = []
        if not auto_scroll:
            modes.append("SCROLL")
        if self.maximized:
            modes.append("MAXIMIZED")
        if wrap:
            modes.append("WRAP")
        if input_mode:
            modes.append("INPUT")
        mode = "|".join(modes)
        mode_paren = f"({mode})" if mode else ""

        pending_keys = self.input_reader.pending
        pending_name_parts = []
        while pending_keys:
            cur_offset = len(pending_keys)
            name = None
            while not name and cur_offset:
                name = keys.seq_to_name(pending_keys[:cur_offset],
                                        fallback=False)
                if not name:
                    cur_offset -= 1
            pending_name_parts.append(name)
            pending_keys = pending_keys[cur_offset:]

        pending_text = "".join(pending_name_parts)
        if pending_text:
            pending_text = f"{pending_text} "

        prefix = f"[{index + 1}] "
        prefix_len = len(prefix)

        if not isinstance(title, C):
            title = C(title)
        title_len = len(title)
        mode_len = len(mode_paren)
        pending_len = len(pending_text)
        space_between = self.cols - title_len - mode_len - pending_len - prefix_len
        if space_between < 0:
            _ellipsis = "... "
            title = title[:(self.cols - mode_len - pending_len - prefix_len) -
                          len(_ellipsis)]
            title += _ellipsis
            space_between = 0
        if self.output_saved:
            color = ansi.theme.STATUS_SAVE
        elif input_mode:
            color = ansi.theme.STATUS_INPUT
        elif not auto_scroll:
            color = ansi.theme.STATUS_SCROLL
        else:
            color = ansi.theme.STATUS_NORMAL
        text = C(prefix,
                 title,
                 " " * space_between,
                 pending_text,
                 mode_paren,
                 color=color)

        ansi.status_bar(
            row=self.get_status_bar_line(),
            text=text,
        )
Exemplo n.º 3
0
def test_seq_to_name_fallback():
    assert seq_to_name((ord("k"), 20)) == "k[20]"
Exemplo n.º 4
0
def test_seq_to_name_single_char():
    assert seq_to_name((ord("k"), )) == "k"
Exemplo n.º 5
0
def test_seq_to_name_predefined():
    assert seq_to_name(HOME) == "Home"
Exemplo n.º 6
0
def test_seq_to_name_ctrl_name():
    assert seq_to_name((11, )) == "^K"
Exemplo n.º 7
0
def test_seq_to_name_list_input():
    assert seq_to_name([ord("k")]) == "k"