cli/cmd/termsize/main.go

42 lines
740 B
Go
Raw Normal View History

2024-06-05 11:45:03 +03:00
package main
import "surdeus.su/core/cli/tx"
import "log"
import "os"
2024-06-05 12:49:23 +03:00
import "io"
2024-06-05 14:18:54 +03:00
import "surdeus.su/core/cli/aes"
2024-06-05 12:49:23 +03:00
//import "fmt"
2024-06-05 11:45:03 +03:00
func main() {
2024-06-05 12:49:23 +03:00
term, err := tx.NewTerminal(os.Stdin)
if err != nil {
2024-06-05 11:45:03 +03:00
// Some not terminal handling.
2024-06-05 12:49:23 +03:00
log.Fatal("tx.NewTerminal(...): %s\n", err)
2024-06-05 11:45:03 +03:00
}
term.MakeRaw()
defer term.Restore()
w, h, err := term.GetSize()
if err != nil {
log.Fatalf("term.GetSize(...): %s\n", err)
}
2024-06-05 12:49:23 +03:00
term.Printf("TermSize: %dx%d\r\n", w, h)
2024-06-05 11:45:03 +03:00
for {
key, _, err := term.ReadKey()
if err != nil {
2024-06-05 12:49:23 +03:00
if err == io.EOF {
break
}
2024-06-05 11:45:03 +03:00
log.Fatalf("term.ReadLine(...): %s\n", err)
}
if key == tx.KeyControlC {
break
}
2024-06-05 14:18:54 +03:00
term.Print(
"shit:", aes.ETF("%q", key).Bold().With(aes.EffectRedFG), "\r\n",
)
2024-06-05 11:45:03 +03:00
}
}