1
0
Fork 0

Cleanup a little

This commit is contained in:
Timothy Warren 2021-03-30 11:52:44 -04:00
parent 663c4304f0
commit 5194fe1e9b
1 changed files with 18 additions and 34 deletions

View File

@ -1,6 +1,7 @@
package editor
import (
"strings"
"timshome.page/gilo/fn"
"timshome.page/gilo/terminal"
)
@ -27,10 +28,9 @@ func New() *editor {
}
func (e *editor) ProcessKeypress() bool {
ch, size := terminal.ReadKey()
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') {
// Clean up on exit
terminal.Write(terminal.ClearScreen + terminal.ResetCursor)
@ -39,46 +39,30 @@ func (e *editor) ProcessKeypress() bool {
}
runes = append(runes, ch)
print(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()
//
//// Handle simplest inputs first
//ch, _ := terminal.ReadKey()
switch code {
case KeyArrowUp, KeyArrowDown, KeyArrowLeft, KeyArrowRight:
e.moveCursor(code)
runes = runes[:0]
return true
default:
// Do something later
terminal.Write("Code: %v", str)
}
}
//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
return true
}
//func (e *editor) processEscapeCode() bool {
//
//}
func (e *editor) moveCursor (rawKey string) {
key := keyMap[rawKey]