58 lines
882 B
Go
58 lines
882 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 drawRows() {
|
|
for y :=0; y < 24; y += 1 {
|
|
terminal.OutLn("~")
|
|
}
|
|
}
|
|
|
|
func RefreshScreen() {
|
|
terminal.ANSICode(terminal.ClearScreen)
|
|
terminal.ANSICode(terminal.ResetCursor)
|
|
|
|
drawRows()
|
|
|
|
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
|
|
}
|