Skip to content

Commit

Permalink
Upgrade termui
Browse files Browse the repository at this point in the history
  • Loading branch information
UnnoTed committed Oct 20, 2019
1 parent 88e9138 commit 731ffd4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
43 changes: 23 additions & 20 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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", "<C-c>":
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 {
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 731ffd4

Please sign in to comment.