Handle more signals #61

Manually merged
asdf merged 2 commits from handle-signals into develop 2019-10-25 02:01:42 +00:00
Collaborator

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 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.
asdf added the
enhancement
non-functional
non-urgent
labels 2019-10-24 03:13:25 +00:00
asdf self-assigned this 2019-10-24 03:13:37 +00:00
sloum was assigned by asdf 2019-10-24 03:13:38 +00:00
asdf reviewed 2019-10-24 03:17:40 +00:00
Author
Collaborator

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 was moved to cui.InitTerm() which is now executed directly in main(). I'm not sure on the full impact of this move.
sloum approved these changes 2019-10-24 03:33:27 +00:00
sloum left a comment
Owner

This looks great! I think these are very solid changes. :) I left a few comments, but nothing requiring action codewise. Approved :)

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()
Owner

I see no reason that should be a problem.

I see no reason that should be a problem.
Author
Collaborator

Yeah upon further investigation it looks ok to me too, I was just a bit worried about error handling.

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 {
Owner

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?

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?
Author
Collaborator

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.

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](https://tour.golang.org/concurrency/5) 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)
Owner

I would have never found this :( The documentation for the syscall lib is the one really swampy place in golang.

I would have never found this :( The documentation for the syscall lib is the one really swampy place in golang.
Author
Collaborator

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.

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.
asdf closed this pull request 2019-10-25 02:01:41 +00:00
asdf deleted branch handle-signals 2019-10-25 02:01:56 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sloum/bombadillo#61
No description provided.