Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid showing the 130 error code after hitting ^C #827

Merged
merged 1 commit into from May 22, 2024

Conversation

steelman
Copy link
Contributor

@steelman steelman commented Mar 21, 2024

When a user hits ^C on command line to cancel entering a lengthy command, $! in __lp_set_prompt is set to 130 (128 + SIGINT). Displaying this error on the input line (especially in warning colours) makes little sense. Therefore, liquidprompt should check if the command submitted is a real command or is it part of PROMPT_COMMAND in which case the error does not come from a user's command and should not be presented.

Technical checklist:

  • code follows our shell standards:
    • correct use of IFS
    • careful quoting
    • cautious array access
    • portable array indexing with _LP_FIRST_INDEX
    • printing a "%" character is done with _LP_PERCENT
    • functions/variable naming conventions
    • functions have local variables
    • data functions have optimization guards (early exits)
    • subshells are avoided as much as possible
    • string substitutions may be done differently in Bash and Zsh (use _LP_SHELL_*)
  • tests and checks have been added, ran, and their warnings fixed:
    • unit tests have been updated (see tests/test_*.sh files)
    • ran tests.sh
    • ran shellcheck.sh (requires shellcheck).
  • documentation have been updated accordingly:
    • functions and attributes are documented in alphabetical order
    • new sections are documented in the default theme
    • tag .. versionadded:: X.Y or .. versionchanged:: Y.Z
    • functions signatures have arguments, returned code, and set value(s)
    • attributes have types and defaults
    • ran docs/docs-lint.sh (requires Python 3 and requirements.txt
      installed (cd docs/; python3 -m venv venv; . venv/bin/activate; pip install -r requirements.txt))

Copy link
Collaborator

@Rycieos Rycieos left a comment

Choose a reason for hiding this comment

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

Interesting idea. I can see why one would want this. And I likely will use this once we merge it. However, it needs to be configurable.

  • Add a config option to control this, like LP_HIDE_EMPTY_ERROR. Don't forget to add docs for it as well.
  • The tracking variable _LP_NOT_A_REAL_COMMAND is very confusing. Rename it to _LP_REAL_COMMAND, and invert the Boolean logic.

liquidprompt Outdated
if (( _LP_NOT_A_REAL_COMMAND )); then
lp_error=0
fi
# zsh doesn't run __lp_before_command, so we set it here
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bash also doesn't run __lp_before_command() if all the features that depend on it are disabled.

liquidprompt Outdated Show resolved Hide resolved
Copy link
Collaborator

@Rycieos Rycieos left a comment

Choose a reason for hiding this comment

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

I was going to post a detailed review of how you missed a couple important things, but the more I dug and reread, I realized that you are fighting against a terrible codebase, which is my fault of course.

So I decided to fix things up as I saw them. Take a look at my new branch rework/preexec, specifically the first two commits eb334b2 and 436b1b5. This largely reworks and improves how preexecs are handled, no longer runs them on empty prompts ([Enter]), and also fixes a related issue where runtime display was not cleared after an empty prompt.

After those fixes, your change is super simple, so I did that too in commit 1be449e. Please take a look at these 3 commits, and let me know if everything makes sense. If so, I'll merge my first 2 into master, and you can continue from there.

If you accept my (our) commit 1be449e, then you pretty much are only missing docs. You will want to add a section for your new config option here. Remember to detail both scenarios this will trigger.

@steelman
Copy link
Contributor Author

steelman commented Apr 14, 2024

LGTM +1 Let me prepare the docs now.

Copy link
Collaborator

@Rycieos Rycieos left a comment

Choose a reason for hiding this comment

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

Looks great, except for one "spelling error":

config.rst:1182: : Spell check: Ctrl: after the user hits Ctrl-C or submits an empty command (i.e. empty string.

You will need to add Ctrl to the docs/spelling_wordlist.txt file.

@Rycieos Rycieos added this to the v2.2 milestone Apr 15, 2024
@Rycieos Rycieos mentioned this pull request Apr 15, 2024
When a user hits ^C on command line to cancel entering a lengthy
command, $! in __lp_set_prompt is set to 130 (128 + SIGINT). Displaying
this error on the input line (especially in warning colours) makes
little sense.
@Rycieos Rycieos merged commit 1b87fbd into liquidprompt:master May 22, 2024
5 checks passed
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.

None yet

2 participants