1from prompt_toolkit.key_binding.vi_state import InputMode
2from prompt_toolkit.application import get_app
3from prompt_toolkit.enums import EditingMode
4from .packages import special
5
6
7def create_toolbar_tokens_func(mycli, show_fish_help):
8    """Return a function that generates the toolbar tokens."""
9    def get_toolbar_tokens():
10        result = []
11        result.append(('class:bottom-toolbar', ' '))
12
13        if mycli.multi_line:
14            delimiter = special.get_current_delimiter()
15            result.append(
16                (
17                    'class:bottom-toolbar',
18                    ' ({} [{}] will end the line) '.format(
19                        'Semi-colon' if delimiter == ';' else 'Delimiter', delimiter)
20                ))
21
22        if mycli.multi_line:
23            result.append(('class:bottom-toolbar.on', '[F3] Multiline: ON  '))
24        else:
25            result.append(('class:bottom-toolbar.off',
26                           '[F3] Multiline: OFF  '))
27        if mycli.prompt_app.editing_mode == EditingMode.VI:
28            result.append((
29                'class:botton-toolbar.on',
30                'Vi-mode ({})'.format(_get_vi_mode())
31            ))
32
33        if show_fish_help():
34            result.append(
35                ('class:bottom-toolbar', '  Right-arrow to complete suggestion'))
36
37        if mycli.completion_refresher.is_refreshing():
38            result.append(
39                ('class:bottom-toolbar', '     Refreshing completions...'))
40
41        return result
42    return get_toolbar_tokens
43
44
45def _get_vi_mode():
46    """Get the current vi mode for display."""
47    return {
48        InputMode.INSERT: 'I',
49        InputMode.NAVIGATION: 'N',
50        InputMode.REPLACE: 'R',
51        InputMode.REPLACE_SINGLE: 'R',
52        InputMode.INSERT_MULTIPLE: 'M',
53    }[get_app().vi_state.input_mode]
54