gilo/internal/editor/editor.go

51 lines
791 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 (
"timshome.page/gilo/internal/char"
"timshome.page/gilo/internal/terminal"
)
2021-03-23 15:51:59 -04:00
type Editor struct {
rows int
cols int
}
2021-03-22 09:12:39 -04:00
func drawRows() {
2021-03-24 13:24:40 -04:00
_, rows := terminal.Size()
for y :=0; y < rows; y += 1 {
2021-03-22 09:12:39 -04:00
terminal.OutLn("~")
}
}
2021-03-19 17:39:15 -04:00
func RefreshScreen() {
terminal.ANSICode(terminal.ClearScreen)
terminal.ANSICode(terminal.ResetCursor)
2021-03-22 09:12:39 -04:00
drawRows()
terminal.ANSICode(terminal.ResetCursor)
2021-03-19 17:39:15 -04:00
}
func ProcessKeypress() bool {
2021-03-24 13:24:40 -04:00
ch, _ := terminal.ReadKey()
2021-03-19 17:39:15 -04:00
// Clean up on exit
if ch == char.Ctrl('q') {
terminal.ANSICode(terminal.ClearScreen)
terminal.ANSICode(terminal.ResetCursor)
return false
}
2021-03-19 17:03:56 -04:00
// Ugliest syntax structure ever?
switch {
case char.IsCtrl(ch):
terminal.OutLn("%d", ch)
default:
terminal.OutLn("%d ('%c')", ch, ch)
}
return true
}