gilo/internal/editor/editor.go

35 lines
560 B
Go
Raw Normal View History

2021-03-19 16:36:02 -04:00
package editor
2021-03-19 17:03:56 -04:00
import (
"bufio"
"timshome.page/gilo/internal/char"
"timshome.page/gilo/internal/terminal"
)
func readKey(reader *bufio.Reader) (rune, int) {
ch, size, err := reader.ReadRune()
if err != nil {
panic(err)
}
return ch, size
}
func ProcessKeypress(reader *bufio.Reader) bool {
ch, _ := readKey(reader)
// Ugliest syntax structure ever?
switch {
case ch == char.Ctrl('q'):
terminal.OutLn("bye!")
return false
case char.IsCtrl(ch):
terminal.OutLn("%d", ch)
default:
terminal.OutLn("%d ('%c')", ch, ch)
}
return true
}