pterm / pterm

✨ #PTerm is a modern Go module to easily beautify console output. Featuring charts, progressbars, tables, trees, text input, select menus and much more 🚀 It's completely configurable and 100% cross-platform compatible.

Home Page:https://pterm.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make interactive confirm optionally accept return key for confirmation

elfrucool opened this issue · comments

For some users, it is confusing that the interactive confirm component accepts their y or n answer immediately without requiring a confirmation through typing <enter> key; this is specially true when adopting pterm the first time.

It would be great to have something like pterm.DefaultInteractiveConfirm.WithWaitReturn(true).Show() to enable this behavior.

(note: this feature request came from this question: #643 )

@elfrucool I've added a draft that includes this new functionality. Would you like to take a look and offer some feedback?

I'll take a look once I get a moment

Thanks for the feedback! I understand your point. Although, in situations where pressing Enter is associated with confirmation, it might be confusing if the default action is "No" or "Cancel".

Also, most CLI prompts don't include a "confirmation helper text", so it might not be necessary here.

In my view, removing the helper text seems like the better option. However, let's wait for the maintainers to decide if they prefer your suggestion (adds more complexity to the printer) or if it's best to remove "confirmation helper text" altogether.

@MarvinJWendt, could you please share your thoughts on this?

What I could imagine is this:

  • New option in the InteractiveConfirmPrinter called InstantSelect
    • If InstantSelect is true: Pressing y or n will instantly confirm or abort the printer.
    • If QuickSelect is false: Return is needed after pressing y or n to select
      • While Return is not pressed, the user should be able to switch between y or n
  • InstantSelect should be true in DefaultInteractiveConfirm
    • That way, it can be disabled with .WithInstantSelect(false).

Any objections? :)

I had a similar idea, and I agree with @elfrucool. It seems more logical to have it disabled by default. In my PR, I added a new option WithConfirmation(true) to pterm.DefaultInteractiveConfirm to enable the behavior of waiting for the user to confirm their answer by pressing . Of course, naming is subject to change. 😄

Any updates on this? Waiting on this since its a great feature that helps prevent confusion on how the interactive confirm works in sequence with other inputs, such as the select or text input, which both require "Enter"

@jcohen98 Hi, sorry for the late reply, apologies for the late reply. I've submitted a pull request and am now waiting for approval. I've explained my approach above and hope it will be merged soon.

Cheers!