Handle more signals #61
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#61
Loading…
Reference in New Issue
No description provided.
Delete Branch "handle-signals"
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 PR expands on previous signal handling work.
It handles CTRL+Z, CTRL+C as well as returning to a stopped process, without breaking the terminal.
This was moved to cui.InitTerm() which is now executed directly in main(). I'm not sure on the full impact of this move.
This looks great! I think these are very solid changes. :) I left a few comments, but nothing requiring action codewise. Approved :)
@ -140,7 +140,6 @@ func loadConfig() error {
func initClient() error {
bombadillo = MakeClient(" ((( Bombadillo ))) ")
cui.SetCharMode()
I see no reason that should be a problem.
Yeah upon further investigation it looks ok to me too, I was just a bit worried about error handling.
@ -158,3 +156,1 @@
cui.Tput("smcup") // use alternate screen
cui.SetCharMode()
bombadillo.Draw()
switch <-c {
I have not used channels a lot (though did recently for a game I made...plummet, available on my tildegit). We are in a goroutine so it wont matter, but just for my own knowledge: this line will block until a signal is received, yeah?
That's correct. It's a buffered channel, and blocks until a value is received.
This is the first time I've used channels, but they are interesting and work well.
The general logic here is that
signal.Notify
listens for the specified signals, then sends them to the channel when they are received. In this goroutine, the channel is blocked until it gets a signal, and then it does the appropriate thing.You can assign the value from a channel using
x := <- c
like you have done in plummet. You can also just do<- c
if you just want to wait until it receives a value, but don't actually want to do anything with that value.The way it is being used here, you could also write it as:
x := <-c
switch x {
case ...
This is also the first time I'm seeing the select statement, so thanks for the prompt on that.
btw plummet is pretty cool! A nice little game.
@ -161,0 +156,4 @@
switch <-c {
case syscall.SIGTSTP:
cui.CleanupTerm()
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
I would have never found this :( The documentation for the syscall lib is the one really swampy place in golang.
Yeah, documentation is a bit light, and it seems like a lot of the code is automatically generated.
I actually found this by searching around. This is the same way that other languages perform this task. Also, in the shell, the command is very similar:
kill -s SIGNAL pid
Also - syscall is also apparently deprecated, but I'm not sure when it is going to be replaced. I guess eventually this will have to be rewritten slightly.