72 lines
1.2 KiB
Go
72 lines
1.2 KiB
Go
package main
|
|
|
|
import "surdeus.su/core/cli/tx"
|
|
import "log"
|
|
import "os"
|
|
//import "io"
|
|
import "surdeus.su/core/cli/aes"
|
|
//import "fmt"
|
|
|
|
func main() {
|
|
normalMode := true
|
|
term, err := tx.NewTerminal(os.Stdin)
|
|
if err != nil {
|
|
// Some not terminal handling.
|
|
log.Fatalf("tx.NewTerminal(...): %s\n", err)
|
|
}
|
|
keys, signals, err := term.MakeRaw()
|
|
if err != nil {
|
|
log.Fatalf("term.MakeRaw(...) %s\n", err)
|
|
}
|
|
term.EnableAltBuffer()
|
|
defer term.Restore()
|
|
|
|
MAIN:
|
|
for { select {
|
|
// Handling signals.
|
|
case sig := <-signals :
|
|
if sig == tx.SignalWinChange {
|
|
term.SaveCursor()
|
|
term.MoveCursorHome()
|
|
w, h, _ := term.Size()
|
|
term.Printf("%dx%d", w, h)
|
|
term.UndoCursor()
|
|
}
|
|
// Handling keys.
|
|
case key := <-keys :
|
|
if key == tx.KeyControlC {
|
|
break MAIN
|
|
}
|
|
if !normalMode && key == tx.KeyESC {
|
|
normalMode = true
|
|
break
|
|
}
|
|
if normalMode { switch key {
|
|
case 'j':
|
|
term.MoveCursorDown(1)
|
|
case 'k':
|
|
term.MoveCursorUp(1)
|
|
case 'h':
|
|
term.MoveCursorLeft(1)
|
|
case 'l' :
|
|
term.MoveCursorRight(1)
|
|
case tx.KeyESC :
|
|
case 'i' :
|
|
normalMode = false
|
|
}
|
|
break }
|
|
|
|
if key == tx.KeyEnter {
|
|
term.NextLine(1)
|
|
//term.Print("enter")
|
|
break
|
|
}
|
|
|
|
term.Print(
|
|
aes.ETF("%s", string(key)).
|
|
Bold().
|
|
With(aes.EffectRedFG),
|
|
)
|
|
}}
|
|
}
|
|
|