2
1
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
sloum 76187af9ff Merge branch 'master' of https://tildegit.org/sloum/swim 2021-03-25 13:03:48 -07:00
sloum c80382b1ae Adds some job control help and quick toggling for tasks 2021-03-25 13:03:40 -07:00
2 changed files with 33 additions and 0 deletions

26
main.go
View File

@ -7,9 +7,11 @@ import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"os/user"
"path/filepath"
"strings"
"syscall"
"tildegit.org/sloum/swim/termios"
)
@ -142,6 +144,25 @@ func LoadFile(path string, cols, rows int) {
board.message = fmt.Sprintf("Loaded file: %s", path)
}
func handleSignals(c <-chan os.Signal) {
for {
switch <-c {
case syscall.SIGTSTP:
termios.Restore()
fmt.Print("\033[?25h")
_ = syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
case syscall.SIGCONT:
termios.SetCharMode()
fmt.Print("\033[?25l")
board.Draw()
case syscall.SIGINT:
termios.Restore()
fmt.Print("\033[?25h")
os.Exit(1)
}
}
}
func main() {
flag.Parse()
args := flag.Args()
@ -163,5 +184,10 @@ func main() {
Zoom: 3}
}
// watch for signals, send them to be handled
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT)
go handleSignals(c)
board.Run()
}

View File

@ -38,6 +38,7 @@ func (s *Story) View(b *Board) {
b.EnterCommand()
case 'h':
s.offset = 0
b.ClearMessage()
return
case 'Q':
Quit()
@ -51,6 +52,12 @@ func (s *Story) View(b *Board) {
s.Update([]string{"user"}, b)
case 'p':
s.Update([]string{"points"}, b)
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
call := []string{"toggle", string(ch)}
if ch == '0' {
call[1] = "10"
}
s.Update(call, b)
}
}
}