gilo/gilo.go

36 lines
570 B
Go
Raw Normal View History

2021-03-18 16:30:04 -04:00
package main
import (
2021-03-25 13:55:17 -04:00
"fmt"
"golang.org/x/term"
2021-03-24 16:23:17 -04:00
"timshome.page/gilo/editor"
"timshome.page/gilo/terminal"
2021-03-18 16:30:04 -04:00
)
2021-03-25 13:55:17 -04:00
func cleanup(oldState *term.State) {
defer terminal.RawOff(oldState)
// Recover from panic to allow restoring terminal state
if a := recover(); a != nil {
fmt.Println("RECOVER", a)
}
}
2021-03-19 12:46:43 -04:00
func main() {
2021-03-19 16:39:49 -04:00
// Go to proper raw mode, but restore canonical mode at exit
oldState := terminal.RawOn()
2021-03-25 13:55:17 -04:00
defer cleanup(oldState)
2021-03-18 19:15:19 -04:00
e := editor.New()
2021-03-30 18:00:06 -04:00
e.Open()
2021-03-19 17:39:15 -04:00
// The input loop
2021-03-22 09:12:39 -04:00
for {
e.RefreshScreen()
2021-03-22 09:12:39 -04:00
if e.ProcessKeypress() == false {
2021-03-22 09:12:39 -04:00
break
}
2021-03-18 19:15:19 -04:00
}
2021-03-18 16:30:04 -04:00
}