~mna/zztermtest

825d7e993658368a128d33e5737745dd36a73687 — Martin Angers 2 years ago d365888
add timeout and close-after flags
1 files changed, 14 insertions(+), 4 deletions(-)

M main.go
M main.go => main.go +14 -4
@@ 7,6 7,7 @@ import (
	"log"
	"runtime"
	"strconv"
	"time"

	"git.sr.ht/~mna/zzcsi"
	"git.sr.ht/~mna/zzterm"


@@ 15,13 16,15 @@ import (

func main() {
	var (
		flagCSI  = flag.Bool("csi", false, "Run in CSI test mode.")
		flagEcho = flag.Bool("echo", false, "Run in zero-allocation echo mode.")
		flagInfo = flag.Bool("info", true, "Run in information mode (default).")
		flagCSI        = flag.Bool("csi", false, "Run in CSI test mode.")
		flagEcho       = flag.Bool("echo", false, "Run in zero-allocation echo mode.")
		flagInfo       = flag.Bool("info", true, "Run in information mode (default).")
		flagTimeout    = flag.Duration("timeout", 0, "Read timeout.")
		flagCloseAfter = flag.Duration("close-after", 0, "Close terminal fd after this duration.")
	)
	flag.Parse()

	t, err := term.Open("/dev/tty", term.RawMode)
	t, err := term.Open("/dev/tty", term.RawMode, term.ReadTimeout(*flagTimeout))
	if err != nil {
		log.Panic(err)
	}


@@ 30,6 33,13 @@ func main() {
		t.Close()
	}()

	if *flagCloseAfter > 0 {
		go func() {
			<-time.After(*flagCloseAfter)
			t.Close()
		}()
	}

	switch {
	case *flagCSI:
		csiMode(t)