cli/cmd/termsize/main.go

39 lines
655 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"
//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
}
term.Printf("shit: %q\r\n", key)
}
}