Skip to content

Conversation

@findkiko
Copy link

Most utilities return after just 1 char when prompting y/n. This PR implements that style so the program doesn't hang waiting for a return key in addition to the user's answer. The additional echos just clean up terminal output.

Copy link
Member

@inkarkat inkarkat left a comment

Choose a reason for hiding this comment

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

It would be nice if someone could verify that this also works on MacOS; that one's causing compatibility problems most often.

@karbassi karbassi added this to the Version 2.12.0 milestone Mar 26, 2018
@karbassi karbassi requested a review from inkarkat August 6, 2021 14:14
inkarkat added a commit to inkarkat/todo.txt-cli that referenced this pull request Aug 6, 2021
By just reading a single character (y for yes, anything else: no).

Closes todotxt#152
@karbassi karbassi closed this in ee94a3f Aug 6, 2021
wwalker pushed a commit to wwalker/todo.txt-cli that referenced this pull request Sep 19, 2021
* Tests: Add coverage for del / move without -f, but with prompting

Supplying the user confirmation via "yes".

* Cosmetics: Align inconsistent spacing for before (y/n) prompt

* Refactoring: Extract confirm() function

The user confirmation query had been duplicated (once) in the code.

* Refactoring: confirm(): Leave early if forced

* Return from user prompt without requiring Enter

By just reading a single character (y for yes, anything else: no).



* Tests: Ensure that only a single "y" concludes the confirmation

By switching from "yes" (that endlessly prints newline-separated "y"s) to "printf y".

* t1800-del: Add coverage for negative confirmation

Negative means "anything but y", so "n", "x", and Enter all apply.

* Cosmetics: Add trailing space after (y/n) prompt

So that the user's typed answer is not recorded directly after it, but with separation: "Foo? (y/n) y" instead of "Foo? (y/n)y".

*Compatibility: "read -N 1" is only available in Bash 4.1+

Mac OS still ships with Bash 3.2 :-( Fall back to the original prompting that requires conclusion via Enter then.
Note: Even though the tests use "printf y", this still gets accepted, as there'll be EOF after that. In real use (when stdin from the terminal stays open), a concluding Enter is mandatory, though.

Closes todotxt#152
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.

3 participants