cli/cmd/termsize/main.go

71 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.Fatal("tx.NewTerminal(...): %s\n", err)
}
term.MakeRaw()
term.EnableAltBuffer()
defer term.Restore()
w, h, err := term.GetSize()
if err != nil {
log.Fatalf("term.GetSize(...): %s\n", err)
}
term.Printf("TermSize: %dx%d\r\n", w, h)
for {
key, _, err := term.ReadKey()
if key == tx.KeyControlC {
break
}
if !normalMode && key == tx.KeyESC {
normalMode = true
continue
}
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
}
continue }
if key == tx.KeyEnter {
term.NextLine(1)
//term.Print("enter")
continue
}
if err != nil {
if err == io.EOF {
break
}
log.Fatalf("term.ReadLine(...): %s\n", err)
}
term.Print(
aes.ETF("%s", string(key)).
Bold().
With(aes.EffectRedFG),
)
}
}