48 lines
752 B
Go
48 lines
752 B
Go
package editor
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
|
|
"timshome.page/gilo/internal/char"
|
|
"timshome.page/gilo/internal/terminal"
|
|
)
|
|
|
|
var reader = bufio.NewReader(os.Stdin)
|
|
|
|
func readKey() (rune, int) {
|
|
ch, size, err := reader.ReadRune()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return ch, size
|
|
}
|
|
|
|
func RefreshScreen() {
|
|
terminal.ANSICode(terminal.ClearScreen)
|
|
terminal.ANSICode(terminal.ResetCursor)
|
|
}
|
|
|
|
func ProcessKeypress() bool {
|
|
ch, _ := readKey()
|
|
|
|
// Clean up on exit
|
|
if ch == char.Ctrl('q') {
|
|
terminal.ANSICode(terminal.ClearScreen)
|
|
terminal.ANSICode(terminal.ResetCursor)
|
|
|
|
return false
|
|
}
|
|
|
|
// Ugliest syntax structure ever?
|
|
switch {
|
|
case char.IsCtrl(ch):
|
|
terminal.OutLn("%d", ch)
|
|
default:
|
|
terminal.OutLn("%d ('%c')", ch, ch)
|
|
}
|
|
|
|
return true
|
|
}
|