Compare commits
2 Commits
7d66b4eeba
...
76187af9ff
Author | SHA1 | Date |
---|---|---|
sloum | 76187af9ff | |
sloum | c80382b1ae |
26
main.go
26
main.go
|
@ -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()
|
||||
}
|
||||
|
|
7
story.go
7
story.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue