jroimartin / gocui

Minimalist Go package aimed at creating Console User Interfaces.
BSD 3-Clause "New" or "Revised" License
9.9k stars 609 forks source link

wish: example of dialog box #158

Open maciekk opened 6 years ago

maciekk commented 6 years ago

I would like to be able to bring up a dialog box when a particular key is pressed within a gocui.View. This dialog box could be a yes/no question, or a single line text entry. The main complication is that I would then like to continue with functionality of the keybinding.

Concrete example: upon pressing key for quitting, I'd like to pop up "are you sure [y/n]" dialog box, and only quit (i.e., return ErrQuit) if answer was yes.

It feels like the modal dialog should be brought up in a goroutine, but somehow I don't think that would work (the main, originating window processing is stuck, which uses the same manager).

An example showing the best practices to achieve such modal dialogs would be very useful.

maciekk commented 6 years ago

The closest I have found to what I need is: https://aqatl.github.io/trego/2017/03/13/simple-prompt-dialog-in-gocui.html

But that seems incomplete and of questionable quality.

luengoi commented 6 years ago

How about something like this??

That is a very simple example, it really depends on how your UI is implemented. However, the common design pattern I can see is to create a new window when the event that triggers the dialog box occurs (for example pressing the quitting key), and make it the current view. This will allow you to set specific key bindings for that view or even set its own custom editor.

jakubgs commented 5 years ago

I'm getting 404 for both inks and I see no dialog.go in _examples. What is the proper way? A different view for each dialog you want? One dialog you adjust depending on what it displays?

Rudi9719 commented 5 years ago

Also looking for this functionality, is there any progress aside from the 404 links?

glvr182 commented 5 years ago

@Rudi9719 If you want you can open this issue at our community fork awesome-gocui/gocui