WIP handle ctrl-z nicely to fix #48 #53
No reviewers
Labels
No Label
blocked
bug
build
documentation
duplicate
enhancement
finger
gemini
gopher
help wanted
http
in progress
invalid
local
needs-info
non-code
non-functional
non-urgent
question
release
rendering
suggestion
telnet
terminal
urgent
wontfix
No Milestone
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sloum/bombadillo#53
Loading…
Reference in New Issue
No description provided.
Delete Branch "asdf/bombadillo:handle-ctrlz"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a first go at fixing this issue.
Most of this was taken from your suggestion in #48 and this cool blog post
It only handles SIGCONT, which is the signal sent to the application when you bring it back to the foreground. I don't think we need to worry about the initial SIGINT, which is when you press CTRL+Z.
It works like this:
handleSIGCONT
takes this channel as an argument, and is started as a goroutine. It waits for the signal before doing anything.handleSIGCONT
fixes the display, then starts another instance ofhandleSIGCONT
before finishing.A few things:
init()
functionI left a few comments re: channels. Other than that it looks good. The only other thing I can think of is that maybe there needs to be a call to redraw the screen within
handleSIGCONT
? That way it forces the screen to go back to normal. I'm on my way out to work and will look at this more later, but you may have access tobombadillo.Draw()
from there. If so, that would be the thing to do right at the end, before the next goroutine.@ -147,0 +154,4 @@
cui.Tput("rmam") // turn off line wrapping
cui.Tput("smcup") // use alternate screen
cui.SetCharMode()
go handleSIGCONT(c)
Can channels be reused like this? I have used goroutines a good amount but had not had occasion until now to use a channel. So long as this works it looks fine and makes sense to me (the logic is clean and I actually really like the recursion)
I'm not certain, but this may be able to be rewritten:
I'm not certain that this behavior works and I'm not sure if the goroutine gets cleaned up on program exit properly or not. both are things to think about. But if this works, it saves passing the channel to a new goroutine.
Sorry, it wont let me edit the above. This is better:
In terms of fixing the display, adding
bombadillo.Draw()
now makes it work perfectly.Regarding recursive routines, reuse of channels - I don't know enough to say. It works as it is, as well as when using the loop you suggest, but your advice raises a lot of things to look in to.
Awesome that adding the call to draw works! I'm not sure whether the loop or recursion would be better. I feel like the loop is, but I'm not really sure. Have you tested that subsequent ctrl+z and fg calls work? I am hopeful that they just work and that this issue is solved! Thanks for researching this. I read a good bit about channels while at work today and even talked them over with a co-worker. I get the concept but the usage in practice never fails to confuse me, lol.
@ -156,0 +169,4 @@
// buffered channel to capture SIGCONT for handling
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGCONT)
go handleSIGCONT(c)
Are channels always pointers? Or does this need to be passed as a pointer?
I don't know enough to say, but a quick search find this that says:
As above, I need to do more reading to understand this better.That seems to answer the question pretty well :) Good to know that a channel is already a reference type :) Thanks for finding that
Indefinite loop used instead of recursive function
Added screen draw - this was the final piece, the display is shown correctly.
This now occurs after
initClient()
is called to ensurebombadillo.Draw()
will exist.These changes look good to me. I approve this fix into develop. I'll wait for confirmation that you are happy with where it is at and dont want to make further revisions but then I'll merge (or you can just merge in if you like)
@ -166,6 +181,11 @@ func main() {
panic(err)
}
// watch for SIGCONT, send it to be handled
👍
I'm ok with how this works now, and can't find anything wrong from what I've been reading.
While testing, I noticed that the initial CTRL+Z (SIGINT) is breaking the console a bit. Normally a flashing cursor is shown in the terminal, but while Bombadillo is suspended, it is not shown. The same occurs when CTRL+C (SIGTERM) is used. These are not new issues and are observable on the development branch.
These new issues can be handled by small extensions to this new functionality. It's probably worth adding them in before merging, but let me know if this isn't a good approach.
I think this approach forks fine. There is a simple vt-100 escape code to turn the cursor back on. That would need to happen when catching the SIGINT or SIGTSTP or whatever else changes to terminal out of "Bombadillo mode". I think this is a good step here so far and can be merged in (which I'll do now). Lets keep it in mind that we may want to listen for an interrupt signal at some point.