Merge pull request #1757 from santagada/add-toolbar-prompt

implements $BOTTOM_TOOLBAR to create a bottom toolbar
This commit is contained in:
Konstantinos Tsakiltzidis 2016-10-05 19:15:35 +03:00 committed by GitHub
commit df27212376
3 changed files with 42 additions and 0 deletions

13
news/toolbar.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:**
* New ``BOTTOM_TOOLBAR`` environment variable to control a bottom toolbar as specified in prompt-toolkit
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

View file

@ -137,6 +137,7 @@ def DEFAULT_ENSURERS():
'PROMPT': (is_string_or_callable, ensure_string, ensure_string),
'RAISE_SUBPROC_ERROR': (is_bool, to_bool, bool_to_str),
'RIGHT_PROMPT': (is_string_or_callable, ensure_string, ensure_string),
'BOTTOM_TOOLBAR': (is_string_or_callable, ensure_string, ensure_string),
'SUBSEQUENCE_PATH_COMPLETION': (is_bool, to_bool, bool_to_str),
'SUPPRESS_BRANCH_TIMEOUT_MESSAGE': (is_bool, to_bool, bool_to_str),
'TEEPTY_PIPE_DELAY': (is_float, float, str),
@ -267,6 +268,7 @@ def DEFAULT_VALUES():
'PUSHD_SILENT': False,
'RAISE_SUBPROC_ERROR': False,
'RIGHT_PROMPT': '',
'BOTTOM_TOOLBAR': '',
'SHELL_TYPE': 'best',
'SUBSEQUENCE_PATH_COMPLETION': True,
'SUPPRESS_BRANCH_TIMEOUT_MESSAGE': False,
@ -497,6 +499,11 @@ def DEFAULT_DOCS():
'at the prompt. This may be parameterized in the same way as '
'the ``$PROMPT`` variable. Currently, this is only available in the '
'prompt-toolkit shell.'),
'BOTTOM_TOOLBAR': VarDocs(
'Template string for the bottom toolbar. '
'This may be parameterized in the same way as '
'the ``$PROMPT`` variable. Currently, this is only available in the '
'prompt-toolkit shell.'),
'SHELL_TYPE': VarDocs(
'Which shell is used. Currently two base shell types are supported:\n\n'
" - ``readline`` that is backed by Python's readline module\n"

View file

@ -63,15 +63,20 @@ class PromptToolkitShell(BaseShell):
get_prompt_tokens = lambda cli: prompt_tokens_cached
rprompt_tokens_cached = self.rprompt_tokens(None)
get_rprompt_tokens = lambda cli: rprompt_tokens_cached
bottom_toolbar_tokens_cached = self.bottom_toolbar_tokens(None)
get_bottom_toolbar_tokens = lambda cli: bottom_toolbar_tokens_cached
else:
get_prompt_tokens = self.prompt_tokens
get_rprompt_tokens = self.rprompt_tokens
get_bottom_toolbar_tokens = self.bottom_toolbar_tokens
with self.prompter:
prompt_args = {
'mouse_support': mouse_support,
'auto_suggest': auto_suggest,
'get_prompt_tokens': get_prompt_tokens,
'get_rprompt_tokens': get_rprompt_tokens,
'get_bottom_toolbar_tokens': get_bottom_toolbar_tokens,
'style': PygmentsStyle(xonsh_style_proxy(self.styler)),
'completer': completer,
'multiline': multiline,
@ -157,6 +162,23 @@ class PromptToolkitShell(BaseShell):
toks = partial_color_tokenize(p)
return toks
def bottom_toolbar_tokens(self, cli):
"""Returns a list of (token, str) tuples for the current bottom
toolbar.
"""
p = builtins.__xonsh_env__.get('BOTTOM_TOOLBAR')
# partial_format_prompt does handle empty strings properly,
# but this avoids descending into it in the common case of
# $TOOLBAR == ''.
if isinstance(p, str) and len(p) == 0:
return []
try:
p = partial_format_prompt(p)
except Exception: # pylint: disable=broad-except
print_exception()
toks = partial_color_tokenize(p)
return toks
def continuation_tokens(self, cli, width):
"""Displays dots in multiline prompt"""
width = width - 1