From 731ffd45f3d6d2750cd1fa2a62f90dbe87723fc5 Mon Sep 17 00:00:00 2001 From: UnnoTed Date: Sun, 20 Oct 2019 10:33:07 -0400 Subject: [PATCH] Upgrade termui --- go.mod | 6 +++--- go.sum | 14 ++++++-------- updater/updater.go | 43 +++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/go.mod b/go.mod index 3ff3e65..11ace54 100644 --- a/go.mod +++ b/go.mod @@ -2,19 +2,17 @@ module github.com/UnnoTed/fileb0x require ( github.com/BurntSushi/toml v0.3.1 - github.com/airking05/termui v2.2.0+incompatible github.com/bmatcuk/doublestar v1.1.1 github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/gizak/termui/v3 v3.1.0 github.com/karrick/godirwalk v1.7.8 github.com/labstack/echo v3.2.1+incompatible github.com/labstack/gommon v0.2.7 // indirect - github.com/maruel/panicparse v1.1.1 // indirect github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-isatty v0.0.4 // indirect github.com/mattn/go-runewidth v0.0.3 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect - github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.2 github.com/valyala/bytebufferpool v1.0.0 // indirect @@ -24,3 +22,5 @@ require ( golang.org/x/sys v0.0.0-20181019160139-8e24a49d80f8 // indirect gopkg.in/yaml.v2 v2.2.1 ) + +go 1.13 diff --git a/go.sum b/go.sum index 0f2f280..1fa6a4d 100644 --- a/go.sum +++ b/go.sum @@ -1,33 +1,31 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/airking05/termui v2.2.0+incompatible h1:S3j2WJzr70u8KjUktaQ0Cmja+R0edOXChltFoQSGG8I= -github.com/airking05/termui v2.2.0+incompatible/go.mod h1:B/M5sgOwSZlvGm3TsR98s1BSzlSH4wPQzUUNwZG+uUM= github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTSaiQ= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/karrick/godirwalk v1.7.3 h1:UP4CfXf1LfNwXrX6vqWf1DOhuiFRn2hXsqtRAQlQOUQ= -github.com/karrick/godirwalk v1.7.3/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34= +github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc= +github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= github.com/karrick/godirwalk v1.7.8 h1:VfG72pyIxgtC7+3X9CMHI0AOl4LwyRAg98WAgsvffi8= github.com/karrick/godirwalk v1.7.8/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34= github.com/labstack/echo v3.2.1+incompatible h1:J2M7YArHx4gi8p/3fDw8tX19SXhBCoRpviyAZSN3I88= github.com/labstack/echo v3.2.1+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= github.com/labstack/gommon v0.2.7 h1:2qOPq/twXDrQ6ooBGrn3mrmVOC+biLlatwgIu8lbzRM= github.com/labstack/gommon v0.2.7/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4= -github.com/maruel/panicparse v1.1.1 h1:k62YPcEoLncEEpjMt92GtG5ugb8WL/510Ys3/h5IkRc= -github.com/maruel/panicparse v1.1.1/go.mod h1:nty42YY5QByNC5MM7q/nj938VbgPU7avs45z6NClpxI= github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e h1:fvw0uluMptljaRKSU8459cJ4bmi3qUYyMs5kzpic2fY= -github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= +github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= +github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/updater/updater.go b/updater/updater.go index 966dc5d..fcb5806 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -18,7 +18,8 @@ import ( "encoding/json" "github.com/UnnoTed/fileb0x/file" - "github.com/airking05/termui" + termui "github.com/gizak/termui/v3" + "github.com/gizak/termui/v3/widgets" ) // Auth holds authentication for the http basic auth @@ -53,7 +54,7 @@ func (pr *ProgressReader) Read(p []byte) (n int, err error) { type Updater struct { Server string Auth Auth - ui []termui.Bufferer + ui []termui.Drawable RemoteHashes map[string]string LocalHashes map[string]string @@ -229,10 +230,11 @@ func (up *Updater) UpdateFiles(files map[string]*file.File) error { defer termui.Close() // info text - p := termui.NewPar("PRESS ANY KEY TO QUIT") - p.Height = height - p.Width = 50 - p.TextFgColor = termui.ColorWhite + p := widgets.NewParagraph() + p.Text = "fileb0x updater - PRESS q TO QUIT" + p.TitleStyle.Fg = termui.ColorWhite + termWidth, _ := termui.TerminalDimensions() + p.SetRect(0, 0, termWidth, height) up.ui = append(up.ui, p) doneTotal := 0 @@ -244,17 +246,19 @@ func (up *Updater) UpdateFiles(files map[string]*file.File) error { up.Workers = 1 } - // just so it can listen to events + // listen to events go func() { - termui.Loop() + uiEvents := termui.PollEvents() + for { + e := <-uiEvents + switch e.ID { + case "q", "": + termui.Close() + os.Exit(1) + } + } }() - // cancel with any key - termui.Handle("/sys/kbd", func(termui.Event) { - termui.StopLoop() - os.Exit(1) - }) - // stops rendering when total is reached go func(upp *Updater, d *int) { for { @@ -268,11 +272,10 @@ func (up *Updater) UpdateFiles(files map[string]*file.File) error { for i := 0; i < up.Workers; i++ { // creates a progress bar - g := termui.NewGauge() - g.Width = termui.TermWidth() - g.Height = height + g := widgets.NewGauge() + top := height + (height * i) + g.SetRect(0, top, termWidth, top+height) g.BarColor = termui.ColorBlue - g.Y = len(up.ui) * height up.ui = append(up.ui, g) go up.worker(jobs, done, g) @@ -295,11 +298,11 @@ func (up *Updater) UpdateFiles(files map[string]*file.File) error { return nil } -func (up *Updater) worker(jobs <-chan *job, done chan<- bool, g *termui.Gauge) { +func (up *Updater) worker(jobs <-chan *job, done chan<- bool, g *widgets.Gauge) { for job := range jobs { f := job.files fr := bytes.NewReader(f.Bytes) - g.BorderLabel = fmt.Sprintf("%d/%d %s", job.current, job.total, f.Path) + g.Title = fmt.Sprintf("%d/%d %s", job.current, job.total, f.Path) // updates progress bar's percentage var total int64