diff --git a/mycli/client.py b/mycli/client.py index d2caa70a..66c41f26 100644 --- a/mycli/client.py +++ b/mycli/client.py @@ -41,7 +41,7 @@ from mycli.packages.integrations.boundary.boundary_tunnel import BoundaryTunnel from mycli.packages.integrations.kubernetes.kubectl_tunnel import KubectlTunnel from mycli.packages.integrations.openssh.ssh_tunnel import SshTunnel -from mycli.packages.prompt_toolkit.style import style_factory_helpers, style_factory_ptoolkit +from mycli.packages.prompt_toolkit.style import style_factory_helpers, style_factory_prompt_toolkit from mycli.packages.special_commands.dsn_aliases import DsnAliases from mycli.packages.special_commands.favorite_queries import FavoriteQueries from mycli.packages.tabular_output import sql_format @@ -150,7 +150,7 @@ def __init__( if cli_verbosity: self.verbosity = cli_verbosity self.cli_style = c["colors"] - self.ptoolkit_style = style_factory_ptoolkit(self.syntax_style, self.cli_style) + self.prompt_toolkit_style = style_factory_prompt_toolkit(self.syntax_style, self.cli_style) self.helpers_style = style_factory_helpers(self.syntax_style, self.cli_style) self.helpers_warnings_style = style_factory_helpers(self.syntax_style, self.cli_style, warnings=True) self.wider_completion_menu = c["main"].as_bool("wider_completion_menu") diff --git a/mycli/main_modes/repl.py b/mycli/main_modes/repl.py index d0c11733..d43868d4 100644 --- a/mycli/main_modes/repl.py +++ b/mycli/main_modes/repl.py @@ -70,7 +70,7 @@ from mycli.packages.prompt_toolkit.history import FRECENCY_HISTORY_ENTRIES, FRECENCY_REFRESH_INTERVAL, FileHistoryWithTimestamp from mycli.packages.prompt_toolkit.key_bindings import mycli_bindings from mycli.packages.prompt_toolkit.multiline import repl_is_multiline -from mycli.packages.prompt_toolkit.style import style_factory_ptoolkit +from mycli.packages.prompt_toolkit.style import style_factory_prompt_toolkit from mycli.packages.prompt_toolkit.toolbar import create_toolbar_tokens_func, get_vi_mode from mycli.packages.pygments.mycli_lexer import MyCliLexer from mycli.packages.redirection.hybrid_redirection import get_redirect_components, is_redirect_command @@ -782,7 +782,7 @@ def _build_prompt_session( auto_suggest=ThreadedAutoSuggest(AutoSuggestFromHistory()), complete_while_typing=complete_while_typing_filter, multiline=repl_is_multiline(mycli), - style=style_factory_ptoolkit(mycli.syntax_style, mycli.cli_style), + style=style_factory_prompt_toolkit(mycli.syntax_style, mycli.cli_style), include_default_pygments_style=False, key_bindings=key_bindings, enable_open_in_editor=True, diff --git a/mycli/output.py b/mycli/output.py index bcd29dbf..e9c995b7 100644 --- a/mycli/output.py +++ b/mycli/output.py @@ -63,7 +63,7 @@ class OutputMixin(MyCliState): prompt_session: PromptSession | None prompt_format: str explicit_pager: bool - ptoolkit_style: _MergedStyle + prompt_toolkit_style: _MergedStyle helpers_style: PygmentsStyle helpers_warnings_style: PygmentsStyle main_formatter: TabularOutputFormatter @@ -73,7 +73,7 @@ def output_timing(self, timing: str, is_warnings_style: bool = False) -> None: add_style = 'class:warnings.timing' if is_warnings_style else 'class:output.timing' formatted_timing = FormattedText([('', timing)]) styled_timing = to_formatted_text(formatted_timing, style=add_style) - prompt_toolkit.print_formatted_text(styled_timing, style=self.ptoolkit_style) + prompt_toolkit.print_formatted_text(styled_timing, style=self.prompt_toolkit_style) def log_query(self, query: str) -> None: if isinstance(self.logfile, TextIOWrapper): @@ -206,7 +206,7 @@ def newlinewrapper(text: list[str]) -> Generator[str, None, None]: else: status = FormattedText([('', result.status_plain)]) styled_status = to_formatted_text(status, style=add_style) - prompt_toolkit.print_formatted_text(styled_status, style=self.ptoolkit_style) + prompt_toolkit.print_formatted_text(styled_status, style=self.prompt_toolkit_style) def output_iterm2_image(self, image: bytes) -> None: """Emit a PNG using the iTerm2 inline image protocol.""" diff --git a/mycli/packages/prompt_toolkit/key_bindings.py b/mycli/packages/prompt_toolkit/key_bindings.py index e531a9a8..36dabd0b 100644 --- a/mycli/packages/prompt_toolkit/key_bindings.py +++ b/mycli/packages/prompt_toolkit/key_bindings.py @@ -13,7 +13,7 @@ vi_mode, ) from prompt_toolkit.key_binding import KeyBindings -from prompt_toolkit.key_binding.bindings.named_commands import register as ptoolkit_register +from prompt_toolkit.key_binding.bindings.named_commands import register as prompt_toolkit_register from prompt_toolkit.key_binding.key_processor import KeyPressEvent from prompt_toolkit.selection import SelectionType @@ -56,7 +56,7 @@ def print_f1_help(): app.print_text('\n') -@ptoolkit_register("edit-and-execute-command") +@prompt_toolkit_register("edit-and-execute-command") def edit_and_execute(event: KeyPressEvent) -> None: """Different from the prompt-toolkit default, we want to have a choice not to execute a query after editing, hence validate_and_handle=False.""" diff --git a/mycli/packages/prompt_toolkit/style.py b/mycli/packages/prompt_toolkit/style.py index ef02b6aa..879c0a63 100644 --- a/mycli/packages/prompt_toolkit/style.py +++ b/mycli/packages/prompt_toolkit/style.py @@ -125,20 +125,20 @@ class TestStyle(PygmentsStyle): return True except AssertionError: - # can't emit error because some styles are valid pygments and not valid ptoolkit + # can't emit error because some styles are valid pygments and not valid prompt_toolkit return False -def is_valid_ptoolkit(name: str) -> bool: +def is_valid_prompt_toolkit(name: str) -> bool: try: _s = Style([("default", name)]) return True except ValueError: - # can't emit error because some styles are valid pygments and not valid ptoolkit + # can't emit error because some styles are valid pygments and not valid prompt_toolkit return False -def style_factory_ptoolkit(name: str, cli_style: dict[str, str]) -> _MergedStyle: +def style_factory_prompt_toolkit(name: str, cli_style: dict[str, str]) -> _MergedStyle: try: style: PygmentsStyle = pygments.styles.get_style_by_name(name) except ClassNotFound: @@ -153,7 +153,7 @@ def style_factory_ptoolkit(name: str, cli_style: dict[str, str]) -> _MergedStyle token_type, style_value = parse_pygments_style(token, style, cli_style) if token_type in TOKEN_TO_PROMPT_STYLE: prompt_style = TOKEN_TO_PROMPT_STYLE[token_type] - if is_valid_ptoolkit(style_value): + if is_valid_prompt_toolkit(style_value): prompt_styles.append((prompt_style, style_value)) else: # we don't want to support tokens anymore @@ -161,7 +161,7 @@ def style_factory_ptoolkit(name: str, cli_style: dict[str, str]) -> _MergedStyle else: # treat as prompt style name (2.0). See default style names here: # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py - if is_valid_ptoolkit(cli_style[token]): + if is_valid_prompt_toolkit(cli_style[token]): prompt_styles.append((token, cli_style[token])) override_style: Style = Style([("bottom-toolbar", "noreverse")]) diff --git a/mycli_test/pytests/test_main.py b/mycli_test/pytests/test_main.py index 3974a9f4..754d3ca1 100644 --- a/mycli_test/pytests/test_main.py +++ b/mycli_test/pytests/test_main.py @@ -2222,7 +2222,7 @@ def test_output_timing_logs_and_prints_with_warning_style(monkeypatch: pytest.Mo monkeypatch.setattr(prompt_toolkit, 'print_formatted_text', lambda text, style=None: printed.append((text, style))) main.MyCli.output_timing(cli, 'Time: 1.000s', is_warnings_style=True) assert timings_logged == ['Time: 1.000s'] - assert printed[-1][1] == cli.ptoolkit_style + assert printed[-1][1] == cli.prompt_toolkit_style def test_get_output_margin_uses_prompt_session_render_counter(monkeypatch: pytest.MonkeyPatch) -> None: diff --git a/mycli_test/pytests/test_main_modes_repl.py b/mycli_test/pytests/test_main_modes_repl.py index 29e5cc91..477b06b0 100644 --- a/mycli_test/pytests/test_main_modes_repl.py +++ b/mycli_test/pytests/test_main_modes_repl.py @@ -1513,7 +1513,7 @@ def fake_prompt_session(**kwargs: Any) -> FakePromptSession: return FakePromptSession() monkeypatch.setattr(repl_mode, 'PromptSession', fake_prompt_session) - monkeypatch.setattr(repl_mode, 'style_factory_ptoolkit', lambda *args, **kwargs: 'style') + monkeypatch.setattr(repl_mode, 'style_factory_prompt_toolkit', lambda *args, **kwargs: 'style') monkeypatch.setattr(repl_mode, 'repl_is_multiline', lambda mycli: False) def fake_toolbar_tokens(mycli: Any, show_help: Any, fmt: str, custom_toolbar: Any) -> str: @@ -2006,7 +2006,7 @@ def test_transform_shell_redirect_writes_formatted_transformed_rows( cli.redirect_formatter = TabularOutputFormatter(format_name='csv') cli.helpers_style = None cli.helpers_warnings_style = None - cli.ptoolkit_style = None + cli.prompt_toolkit_style = None cli.explicit_pager = False cli.get_output_margin = lambda status: 0 cli.format_sqlresult = lambda *args, **kwargs: OutputMixin.format_sqlresult(cli, *args, **kwargs) diff --git a/mycli_test/pytests/test_output.py b/mycli_test/pytests/test_output.py index 56d0e64f..8e42b76d 100644 --- a/mycli_test/pytests/test_output.py +++ b/mycli_test/pytests/test_output.py @@ -37,7 +37,7 @@ def test_output_timing_logs_and_prints_with_default_style(monkeypatch: pytest.Mo assert logged == ['0.12 sec'] assert to_plain_text(printed[0][0]) == '0.12 sec' assert list(printed[0][0])[0][0].strip() == 'class:output.timing' - assert printed[0][1] == cli.ptoolkit_style + assert printed[0][1] == cli.prompt_toolkit_style def test_output_timing_uses_warning_style(monkeypatch: pytest.MonkeyPatch) -> None: @@ -533,7 +533,7 @@ def streaming_output_cli(monkeypatch: pytest.MonkeyPatch) -> Any: cli = make_bare_mycli() cli.main_formatter = TabularOutputFormatter(format_name='csv') cli.redirect_formatter = TabularOutputFormatter(format_name='csv') - cli.helpers_style = cli.helpers_warnings_style = cli.ptoolkit_style = None + cli.helpers_style = cli.helpers_warnings_style = cli.prompt_toolkit_style = None monkeypatch.setattr(output_module.special_commands, 'is_explorer_output', lambda: False) return cli diff --git a/mycli_test/pytests/test_prompt_toolkit_style.py b/mycli_test/pytests/test_prompt_toolkit_style.py index 19f563b9..e50f0ade 100644 --- a/mycli_test/pytests/test_prompt_toolkit_style.py +++ b/mycli_test/pytests/test_prompt_toolkit_style.py @@ -57,8 +57,8 @@ def __init_subclass__(cls, **kwargs) -> None: assert style_module.is_valid_pygments('invalid') is False -def test_is_valid_ptoolkit_returns_true_and_false(monkeypatch) -> None: - assert style_module.is_valid_ptoolkit('bold') is True +def test_is_valid_prompt_toolkit_returns_true_and_false(monkeypatch) -> None: + assert style_module.is_valid_prompt_toolkit('bold') is True class FailingPromptStyle: def __init__(self, _rules) -> None: @@ -66,10 +66,10 @@ def __init__(self, _rules) -> None: monkeypatch.setattr(style_module, 'Style', FailingPromptStyle) - assert style_module.is_valid_ptoolkit('invalid') is False + assert style_module.is_valid_prompt_toolkit('invalid') is False -def test_style_factory_ptoolkit_builds_styles_and_falls_back(monkeypatch, caplog) -> None: +def test_style_factory_prompt_toolkit_builds_styles_and_falls_back(monkeypatch, caplog) -> None: calls: list[str] = [] native_style = object() @@ -95,7 +95,7 @@ def __init__(self, rules) -> None: 'Token.Name': (Token.Name, 'token-invalid'), }[token], ) - monkeypatch.setattr(style_module, 'is_valid_ptoolkit', lambda value: value in {'token-valid', 'prompt-valid'}) + monkeypatch.setattr(style_module, 'is_valid_prompt_toolkit', lambda value: value in {'token-valid', 'prompt-valid'}) monkeypatch.setattr(style_module, 'Style', FakeStyle) monkeypatch.setattr(style_module, 'style_from_pygments_cls', lambda style: ('pygments-style', style)) monkeypatch.setattr(style_module, 'merge_styles', lambda styles: styles) @@ -109,7 +109,7 @@ def __init__(self, rules) -> None: } with caplog.at_level('ERROR', logger='mycli.packages.prompt_toolkit.style'): - styles = style_module.style_factory_ptoolkit('missing', cli_style) + styles = style_module.style_factory_prompt_toolkit('missing', cli_style) assert calls == ['missing', 'native'] assert styles[0] == ('pygments-style', native_style) @@ -187,8 +187,8 @@ def fake_get_style_by_name(name: str): assert output_style.styles[Token.Output.Status] == 'ansicyan' -def test_style_factory_ptoolkit_returns_merged_style_object() -> None: - style = style_module.style_factory_ptoolkit( +def test_style_factory_prompt_toolkit_returns_merged_style_object() -> None: + style = style_module.style_factory_prompt_toolkit( 'native', { 'prompt': 'bold', diff --git a/mycli_test/utils.py b/mycli_test/utils.py index ea5e1d06..58ea21df 100644 --- a/mycli_test/utils.py +++ b/mycli_test/utils.py @@ -146,7 +146,7 @@ def make_bare_mycli() -> Any: cli.explorer_formatter = DummyFormatter() cli.helpers_style = 'helpers-style' cli.helpers_warnings_style = 'helpers-warnings-style' - cli.ptoolkit_style = cast(Any, 'pt-style') + cli.prompt_toolkit_style = cast(Any, 'pt-style') cli.syntax_style = 'native' cli.cli_style = {} cli.null_string = ''