awesome-gocui / gocui

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

Create public methods to init and close tcell screen #83

Closed lawrencegripper closed 3 years ago

lawrencegripper commented 3 years ago

As mentioned in #83 this change enables azbrowse to load another terminal app then, once it has closed, re-enable the gocui.

Our calls to this look like this:

        if editorConfig.RevertToStandardBuffer {
        // Close to revert to normal buffer
        gocui.TCellClose()
    }

        // open nano/vim or other and wait for it to close
    editorErr := openEditor(editorConfig.Command, editorTmpFile)

    if editorConfig.RevertToStandardBuffer {
        // Init tcell to switch back to alternate buffer and Flush content
        gocui.TcellInit()
    }
dankox commented 3 years ago

I want to test it a bit more, if there is no problem with the goroutines running in the background. I would assume most of them will get blocked (like pollEvent and loaderTick) because the channels are unbuffered and the MainLoop is blocked by the user event which runs other terminal program (like vi). At least that's how I understand the usage here.

Another thing is, as I mentioned in #82, if it wouldn't be better to name those functions something like Suspend and Resume, to make it more obvious what they are designed for? But that's just the naming anyway :)

lawrencegripper commented 3 years ago

Sounds good to me, I agree on renamed the methods - pushed this up now. From my testing so far with azbrowse this works as expected (granted relatively limited)

lawrencegripper commented 3 years ago

Done some more testing and this all plays nicely for me and feels good to go, any tweaks needed or feedback?

dankox commented 3 years ago

Looks good. I did some testing on my app too and the change seems quite well behaved (also the code is much more simple) :) I'm using UpdateAsync though, so it gets blocked (which is good).
If somebody is using Update in their goroutines, the amount of spawned go routines could be increased, but I guess people have to deal with it on their own (and don't do Update when they call Suspend).

@mjarkk what do you think about this? Could be merged?