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() var x, y int x, y = 1, 2 update := func() { term.SaveCursor() term.MoveCursorTo(1, 1) term.EraseLine() w, h, _ := term.Size() term.Print( aes.ETF("%dx%d %d %d", w, h, x, y). Bold(). With(aes.EffectRedBG). With(aes.EffectBlackFG), ) term.UndoCursor() } term.MoveCursorTo(x, y) update() MAIN: for { select { // Handling signals. case sig := <-signals : if sig == tx.SignalWinChange { } // 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) y++ case 'k': if y == 2 { break } term.MoveCursorUp(1) y-- case 'h': if x == 1 { break } term.MoveCursorLeft(1) x-- case 'l' : term.MoveCursorRight(1) x++ 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), ) } update() } }