mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 00:41:00 +01:00
Merge branch 'nicolasavru-support-right-prompt-function2'
This commit is contained in:
commit
1b28213446
4 changed files with 32 additions and 4 deletions
|
@ -14,7 +14,8 @@ from xonsh.tools import (
|
||||||
ensure_string, is_env_path, str_to_env_path, env_path_to_str,
|
ensure_string, is_env_path, str_to_env_path, env_path_to_str,
|
||||||
escape_windows_cmd_string, is_bool, to_bool, bool_to_str,
|
escape_windows_cmd_string, is_bool, to_bool, bool_to_str,
|
||||||
is_bool_or_int, to_bool_or_int, bool_or_int_to_str,
|
is_bool_or_int, to_bool_or_int, bool_or_int_to_str,
|
||||||
ensure_int_or_slice, is_float, is_string, check_for_partial_string,
|
ensure_int_or_slice, is_float, is_string, is_callable,
|
||||||
|
is_string_or_callable, check_for_partial_string,
|
||||||
is_dynamic_cwd_width, to_dynamic_cwd_tuple, dynamic_cwd_tuple_to_str,
|
is_dynamic_cwd_width, to_dynamic_cwd_tuple, dynamic_cwd_tuple_to_str,
|
||||||
argvquote, executables_in, find_next_break, expand_case_matching)
|
argvquote, executables_in, find_next_break, expand_case_matching)
|
||||||
|
|
||||||
|
@ -333,6 +334,17 @@ def test_is_string():
|
||||||
yield assert_false, is_string(42.0)
|
yield assert_false, is_string(42.0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_callable():
|
||||||
|
yield assert_true, is_callable(lambda: 42.0)
|
||||||
|
yield assert_false, is_callable(42.0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_string_or_callable():
|
||||||
|
yield assert_true, is_string_or_callable('42.0')
|
||||||
|
yield assert_true, is_string_or_callable(lambda: 42.0)
|
||||||
|
yield assert_false, is_string(42.0)
|
||||||
|
|
||||||
|
|
||||||
def test_always_true():
|
def test_always_true():
|
||||||
yield assert_true, always_true(42)
|
yield assert_true, always_true(42)
|
||||||
yield assert_true, always_true('42')
|
yield assert_true, always_true('42')
|
||||||
|
|
|
@ -29,7 +29,8 @@ from xonsh.tools import (
|
||||||
IS_SUPERUSER, always_true, always_false, ensure_string, is_env_path,
|
IS_SUPERUSER, always_true, always_false, ensure_string, is_env_path,
|
||||||
str_to_env_path, env_path_to_str, is_bool, to_bool, bool_to_str,
|
str_to_env_path, env_path_to_str, is_bool, to_bool, bool_to_str,
|
||||||
is_history_tuple, to_history_tuple, history_tuple_to_str, is_float,
|
is_history_tuple, to_history_tuple, history_tuple_to_str, is_float,
|
||||||
is_string, is_completions_display_value, to_completions_display_value,
|
is_string, is_callable, is_string_or_callable,
|
||||||
|
is_completions_display_value, to_completions_display_value,
|
||||||
is_string_set, csv_to_set, set_to_csv, get_sep, is_int, is_bool_seq,
|
is_string_set, csv_to_set, set_to_csv, get_sep, is_int, is_bool_seq,
|
||||||
is_bool_or_int, to_bool_or_int, bool_or_int_to_str,
|
is_bool_or_int, to_bool_or_int, bool_or_int_to_str,
|
||||||
csv_to_bool_seq, bool_seq_to_csv, DefaultNotGiven, print_exception,
|
csv_to_bool_seq, bool_seq_to_csv, DefaultNotGiven, print_exception,
|
||||||
|
@ -104,11 +105,13 @@ DEFAULT_ENSURERS = {
|
||||||
'LOADED_CONFIG': (is_bool, to_bool, bool_to_str),
|
'LOADED_CONFIG': (is_bool, to_bool, bool_to_str),
|
||||||
'LOADED_RC_FILES': (is_bool_seq, csv_to_bool_seq, bool_seq_to_csv),
|
'LOADED_RC_FILES': (is_bool_seq, csv_to_bool_seq, bool_seq_to_csv),
|
||||||
'MOUSE_SUPPORT': (is_bool, to_bool, bool_to_str),
|
'MOUSE_SUPPORT': (is_bool, to_bool, bool_to_str),
|
||||||
|
'MULTILINE_PROMPT': (is_string_or_callable, ensure_string, ensure_string),
|
||||||
re.compile('\w*PATH$'): (is_env_path, str_to_env_path, env_path_to_str),
|
re.compile('\w*PATH$'): (is_env_path, str_to_env_path, env_path_to_str),
|
||||||
'PATHEXT': (is_env_path, str_to_env_path, env_path_to_str),
|
'PATHEXT': (is_env_path, str_to_env_path, env_path_to_str),
|
||||||
'PRETTY_PRINT_RESULTS': (is_bool, to_bool, bool_to_str),
|
'PRETTY_PRINT_RESULTS': (is_bool, to_bool, bool_to_str),
|
||||||
|
'PROMPT': (is_string_or_callable, ensure_string, ensure_string),
|
||||||
'RAISE_SUBPROC_ERROR': (is_bool, to_bool, bool_to_str),
|
'RAISE_SUBPROC_ERROR': (is_bool, to_bool, bool_to_str),
|
||||||
'RIGHT_PROMPT': (is_string, ensure_string, ensure_string),
|
'RIGHT_PROMPT': (is_string_or_callable, ensure_string, ensure_string),
|
||||||
'TEEPTY_PIPE_DELAY': (is_float, float, str),
|
'TEEPTY_PIPE_DELAY': (is_float, float, str),
|
||||||
'UPDATE_OS_ENVIRON': (is_bool, to_bool, bool_to_str),
|
'UPDATE_OS_ENVIRON': (is_bool, to_bool, bool_to_str),
|
||||||
'XONSHRC': (is_env_path, str_to_env_path, env_path_to_str),
|
'XONSHRC': (is_env_path, str_to_env_path, env_path_to_str),
|
||||||
|
|
|
@ -143,7 +143,10 @@ class PromptToolkitShell(BaseShell):
|
||||||
prompt.
|
prompt.
|
||||||
"""
|
"""
|
||||||
p = builtins.__xonsh_env__.get('RIGHT_PROMPT')
|
p = builtins.__xonsh_env__.get('RIGHT_PROMPT')
|
||||||
if len(p) == 0:
|
# partial_format_prompt does handle empty strings properly,
|
||||||
|
# but this avoids descending into it in the common case of
|
||||||
|
# $RIGHT_PROMPT == ''.
|
||||||
|
if isinstance(p, str) and len(p) == 0:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
p = partial_format_prompt(p)
|
p = partial_format_prompt(p)
|
||||||
|
|
|
@ -549,6 +549,16 @@ def is_string(x):
|
||||||
return isinstance(x, str)
|
return isinstance(x, str)
|
||||||
|
|
||||||
|
|
||||||
|
def is_callable(x):
|
||||||
|
"""Tests if something is callable"""
|
||||||
|
return callable(x)
|
||||||
|
|
||||||
|
|
||||||
|
def is_string_or_callable(x):
|
||||||
|
"""Tests if something is a string or callable"""
|
||||||
|
return is_string(x) or is_callable(x)
|
||||||
|
|
||||||
|
|
||||||
def always_true(x):
|
def always_true(x):
|
||||||
"""Returns True"""
|
"""Returns True"""
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Reference in a new issue