Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add help on F1 keystroke#1627

Merged
rolandwalker merged 1 commit intomainfrom
RW/add-help-on-f1
Feb 26, 2026
Merged

Add help on F1 keystroke#1627
rolandwalker merged 1 commit intomainfrom
RW/add-help-on-f1

Conversation

@rolandwalker
Copy link
Contributor

Description

  • open documentation index in web browser on F1
  • emit output using prompt_toolkit methods such that the prompt is restored including pending input
  • include the docs URL in the output in case the browser did not open
  • include alternate F1 key sequence that prompt_toolkit doesn't handle
  • update TIPS and key_bindings.rst

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Feb 25, 2026
@github-actions
Copy link

Findings

  1. Potential prompt corruption + uncaught exceptions from browser launch
    webbrowser.open_new_tab() is invoked outside run_in_terminal and without error handling. If the browser command writes to stdout/stderr or raises (common on headless systems), this can corrupt the prompt or bubble exceptions into the key handler. Consider wrapping the browser call inside run_in_terminal and catching webbrowser.Error/OSError so F1 never destabilizes the UI.
    File: mycli/key_bindings.py:51 and mycli/key_bindings.py:58

Missing tests / edge cases

  1. No coverage for the new F1 behavior
    There are no tests asserting that the F1 binding emits help text and attempts a browser open. A lightweight unit test could monkeypatch webbrowser.open_new_tab and prompt_toolkit.application.run_in_terminal to assert both are called, and that failures don’t raise.
    File: mycli/key_bindings.py:51 and mycli/key_bindings.py:58

If you want, I can sketch a minimal pytest for this.

Copy link
Contributor

@scottnemes scottnemes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend adding the web browser call to a try/except to suppress the error, otherwise it adds extra output and requires you to press enter to get a new line

Image

@rolandwalker
Copy link
Contributor Author

Interesting! Does this command not work on your setup?

python -m webbrowser -t "https://www.python.org"

A try/except wouldn't help. The error output is coming from an external program. But I think the issue can be fixed by the same invalidation trick as in #1632 .

 * open documentation index in web browser
 * emit output using prompt_toolkit methods such that the prompt is
   restored including pending input
 * include the docs URL in the output in case the browser did not open
 * include alternate F1 key sequence that prompt_toolkit doesn't handle
 * update TIPS and key_bindings.rst
@rolandwalker
Copy link
Contributor Author

See if the pushed changes fix the spurious output for you by invalidating the display.

@scottnemes
Copy link
Contributor

Interesting! Does this command not work on your setup?

python -m webbrowser -t "https://www.python.org"

A try/except wouldn't help. The error output is coming from an external program. But I think the issue can be fixed by the same invalidation trick as in #1632 .

I use WSL2 on Windows11 for most of my testing, so always a bit different. I am able to install packages to make it work to load the browser though, so verified that bit works.

However the error output is the same after your most recent change. But it looks fine in general, and I couldn't find any good way to suppress the error without getting hacky. So should be good as-is.

@rolandwalker
Copy link
Contributor Author

That's good to know. Maybe we could improve our Windows support, both in and out of WSL2. Maybe we could at least improve the documentation.

@rolandwalker rolandwalker merged commit 03939ba into main Feb 26, 2026
8 checks passed
@rolandwalker rolandwalker deleted the RW/add-help-on-f1 branch February 26, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants