From 6bac17f3058f6c639ee410e502fb3e593945f182 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Wed, 25 Feb 2026 05:41:31 -0500 Subject: [PATCH] invalidate display after fzf history search Depending upon settings, the prompt message might be invisible after returning from an fzf search. One cause could be export FZF_DEFAULT_OPTS='--height=15%' Leaving aside the question of the interaction between the environment variable and the search interface expected by the mycli documentation, we can solve the issue of the lost prompt message by manually invalidating the display. As the docstring notes, app.invalidate() did not have the desired effect, and caused warnings at exit time: Task was destroyed but it is pending! --- changelog.md | 5 +++++ mycli/packages/toolkit/fzf.py | 2 ++ mycli/packages/toolkit/utils.py | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 mycli/packages/toolkit/utils.py diff --git a/changelog.md b/changelog.md index b01cd235..8a550808 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,11 @@ Features * Add `\bug` command. +Bug Fixes +--------- +* Force a prompt_toolkit refresh after fzf history search to avoid display glitches. + + 1.57.0 (2026/02/25) ============== diff --git a/mycli/packages/toolkit/fzf.py b/mycli/packages/toolkit/fzf.py index a5d6ffce..966fb436 100644 --- a/mycli/packages/toolkit/fzf.py +++ b/mycli/packages/toolkit/fzf.py @@ -6,6 +6,7 @@ from pyfzf import FzfPrompt from mycli.packages.toolkit.history import FileHistoryWithTimestamp +from mycli.packages.toolkit.utils import safe_invalidate_display class Fzf(FzfPrompt): @@ -56,6 +57,7 @@ def search_history(event: KeyPressEvent, incremental: bool = False) -> None: formatted_history_items, fzf_options=' '.join(options), ) + safe_invalidate_display(event.app) if result: selected_index = formatted_history_items.index(result[0]) diff --git a/mycli/packages/toolkit/utils.py b/mycli/packages/toolkit/utils.py new file mode 100644 index 00000000..1e5fca93 --- /dev/null +++ b/mycli/packages/toolkit/utils.py @@ -0,0 +1,20 @@ +from prompt_toolkit.application import Application, run_in_terminal + + +def safe_invalidate_display(app: Application) -> None: + """ + fzf can confuse the terminal/app when certain values are set in + environment variable FZF_DEFAULT_OPTS. + + The same could happen after running other external programs. + + This function invalidates the prompt_toolkit display, causing a + refresh of the prompt message and pending user input, without + leading to exceptions at exit time, as the built-in + app.invalidate() does. + """ + + def print_empty_string(): + app.print_text('') + + run_in_terminal(print_empty_string)