Cleanup a little

This commit is contained in:
Timothy Warren 2021-03-30 11:52:44 -04:00
parent 663c4304f0
commit 5194fe1e9b

View File

@ -1,6 +1,7 @@
package editor package editor
import ( import (
"strings"
"timshome.page/gilo/fn" "timshome.page/gilo/fn"
"timshome.page/gilo/terminal" "timshome.page/gilo/terminal"
) )
@ -27,10 +28,9 @@ func New() *editor {
} }
func (e *editor) ProcessKeypress() bool { func (e *editor) ProcessKeypress() bool {
ch, size := terminal.ReadKey()
var runes []rune var runes []rune
for ; size != 0; ch, size = terminal.ReadKey() { for ch, size := terminal.ReadKey(); size != 0; ch, size = terminal.ReadKey() {
if ch == fn.Ctrl('q') { if ch == fn.Ctrl('q') {
// Clean up on exit // Clean up on exit
terminal.Write(terminal.ClearScreen + terminal.ResetCursor) terminal.Write(terminal.ClearScreen + terminal.ResetCursor)
@ -39,46 +39,30 @@ func (e *editor) ProcessKeypress() bool {
} }
runes = append(runes, ch) runes = append(runes, ch)
print(runes)
} }
terminal.Write("%v", runes) terminal.Write("%v", runes)
str := string(runes)
runes = runes[:0]
return false // Escape sequences can be less fun...
if strings.Contains(str, terminal.EscPrefix) {
code := strings.TrimPrefix(str, terminal.EscPrefix)
//str = terminal.Read() switch code {
// case KeyArrowUp, KeyArrowDown, KeyArrowLeft, KeyArrowRight:
//// Handle simplest inputs first e.moveCursor(code)
//ch, _ := terminal.ReadKey() runes = runes[:0]
return true
default:
// Do something later
terminal.Write("Code: %v", str)
}
}
return true
//runes := terminal.Read()
//str := string(runes)
//
//terminal.Write(terminal.ClearScreen + terminal.ResetCursor)
//terminal.WriteLn(fmt.Sprintf("%v\r\r", runes))
//
////// Escape sequences can be less fun...
//if strings.Contains(str, terminal.EscPrefix) {
// code := strings.TrimPrefix(str, terminal.EscPrefix)
//
// switch code {
// case KeyArrowUp, KeyArrowDown, KeyArrowLeft, KeyArrowRight:
// e.moveCursor(code)
// return true
// default:
// // Do something later
// }
//}
//
//return true
} }
//func (e *editor) processEscapeCode() bool {
//
//}
func (e *editor) moveCursor (rawKey string) { func (e *editor) moveCursor (rawKey string) {
key := keyMap[rawKey] key := keyMap[rawKey]