Skip to content

Commit

Permalink
Show the prompt while running fzf
Browse files Browse the repository at this point in the history
  • Loading branch information
lebr0nli committed Jun 4, 2024
1 parent 65e0fbb commit 720c4ea
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion gdbinit-gep.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ def fzf_reverse_search(event: KeyPressEvent) -> None:
"""Reverse search history with fzf."""

def _fzf_reverse_search() -> None:
global HISTORY_FILENAME
# run_in_terminal will hide the prompt, we show the prompt while running fzf
# so user can see the original prompt while selecting completions, which is more user-friendly
event.app.renderer.render(event.app, event.app.layout, is_done=True)

if not os.path.exists(HISTORY_FILENAME):
# just create an empty file
with open(HISTORY_FILENAME, "w"):
Expand All @@ -239,6 +242,10 @@ def _fzf_reverse_search() -> None:
event.app.current_buffer.document = Document() # clear buffer
event.app.current_buffer.insert_text(stdout.strip())

# remove the prompt we showed after running fzf
event.app.output.cursor_up(1)
event.app.renderer.erase()

run_in_terminal(_fzf_reverse_search)


Expand All @@ -254,6 +261,11 @@ def _fzf_tab_autocomplete() -> None:
all_completions, should_get_all_help_docs = get_gdb_completion_and_status(target_text)
if not all_completions:
return

# run_in_terminal will hide the prompt, we show the prompt while running fzf
# so user can see the original prompt while selecting completions, which is more user-friendly
event.app.renderer.render(event.app, event.app.layout, is_done=True)

prefix = common_prefix([common_prefix(all_completions), target_text])
# TODO/FIXME: qeury might not be the expected one, e.g.
# (gdb) complete b fun
Expand Down Expand Up @@ -302,6 +314,10 @@ def _fzf_tab_autocomplete() -> None:
stdout = "'" + stdout
event.app.current_buffer.insert_text(stdout[len(query) :].rstrip())

# remove the prompt we showed after running fzf
event.app.output.cursor_up(1)
event.app.renderer.erase()

run_in_terminal(_fzf_tab_autocomplete)


Expand Down

0 comments on commit 720c4ea

Please sign in to comment.