summaryrefslogtreecommitdiffstats
path: root/litecli/clitoolbar.py
blob: 1e28784667546d0989a26eee11f54035868d90da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from __future__ import unicode_literals

from prompt_toolkit.key_binding.vi_state import InputMode
from prompt_toolkit.enums import EditingMode
from prompt_toolkit.application import get_app


def create_toolbar_tokens_func(cli, show_fish_help):
    """
    Return a function that generates the toolbar tokens.
    """

    def get_toolbar_tokens():
        result = []
        result.append(("class:bottom-toolbar", " "))

        if cli.multi_line:
            result.append(
                ("class:bottom-toolbar", " (Semi-colon [;] will end the line) ")
            )

        if cli.multi_line:
            result.append(("class:bottom-toolbar.on", "[F3] Multiline: ON  "))
        else:
            result.append(("class:bottom-toolbar.off", "[F3] Multiline: OFF  "))
        if cli.prompt_app.editing_mode == EditingMode.VI:
            result.append(
                ("class:botton-toolbar.on", "Vi-mode ({})".format(_get_vi_mode()))
            )

        if show_fish_help():
            result.append(
                ("class:bottom-toolbar", "  Right-arrow to complete suggestion")
            )

        if cli.completion_refresher.is_refreshing():
            result.append(("class:bottom-toolbar", "     Refreshing completions..."))

        return result

    return get_toolbar_tokens


def _get_vi_mode():
    """Get the current vi mode for display."""
    return {
        InputMode.INSERT: "I",
        InputMode.NAVIGATION: "N",
        InputMode.REPLACE: "R",
        InputMode.INSERT_MULTIPLE: "M",
        InputMode.REPLACE_SINGLE: "R",
    }[get_app().vi_state.input_mode]