Skip to content

Commit

Permalink
feat(pg): prompt size info
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Feb 9, 2022
1 parent 41daa61 commit 8299782
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strings"

"github.com/beetcb/ghdl/helper/pg"
humanize "github.com/dustin/go-humanize"
)

type GHReleaseDl struct {
Expand Down Expand Up @@ -61,7 +62,7 @@ func (dl *GHReleaseDl) DlAndDecompression() {
panic(err)
}
}
pg.Progress(starter)
pg.Progress(starter, humanize.Bytes(uint64(fileSize)))

// `file` has no content, we must open it for reading
openfile, err := os.Open(file.Name())
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require (
github.com/charmbracelet/bubbles v0.10.2
github.com/charmbracelet/bubbletea v0.19.3
github.com/charmbracelet/lipgloss v0.4.0
github.com/dustin/go-humanize v1.0.0
github.com/spf13/cobra v1.3.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
8 changes: 4 additions & 4 deletions helper/pg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ProgressBytesReader struct {

type model struct {
percent float64
humanize string
progress progress.Model
init func() tea.Msg
}
Expand Down Expand Up @@ -50,12 +51,12 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (e model) View() string {
pad := strings.Repeat(" ", padding)
return "\n" +
pad + e.progress.ViewAs(e.percent) + "\n"
pad + e.progress.ViewAs(e.percent) + fmt.Sprintf(" of %s", e.humanize) + "\n"
}

func Progress(starter func(updater func(float64))) {
func Progress(starter func(updater func(float64)), humanize string) {
prog := progress.New(progress.WithScaledGradient("#FF7CCB", "#FDFF8C"))
state := model{progress: prog}
state := model{progress: prog, humanize: humanize}
updater := func(p float64) {
state.percent = p
}
Expand All @@ -68,5 +69,4 @@ func Progress(starter func(updater func(float64))) {
fmt.Println("Oh no!", err)
os.Exit(1)
}

}
24 changes: 14 additions & 10 deletions helper/sl/sl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type model struct {
func initialModel(choices *[]string) model {
return model{
choices: *choices,
selected: 0,
selected: -1,
}
}

Expand Down Expand Up @@ -54,17 +54,21 @@ func (m model) View() string {
paddingS := lipgloss.NewStyle().PaddingLeft(2).MaxWidth(maxWidth)
colorS := paddingS.Copy().
Foreground(blue).BorderLeft(true).BorderForeground(blue)

s := paddingS.Render("gh-dl can't figure out which release to download\nplease select it manully") + "\n\n"
for i, choice := range m.choices {
if m.cursor == i {
s += colorS.Render(choice) + "\n"
} else {
s += paddingS.Render(choice) + "\n"
if m.selected == -1 {
s := "\n" + paddingS.Render("gh-dl can't figure out which release to download\nplease select it manully") + "\n\n"
for i, choice := range m.choices {
if m.cursor == i {
s += colorS.Render(choice) + "\n"
} else {
s += paddingS.Render(choice) + "\n"
}
}
// Send the UI for rendering
return s
} else {
s := paddingS.Render(fmt.Sprintf("start downloading %s", lipgloss.NewStyle().Foreground(blue).Render(m.choices[m.selected])))
return "\n" + s + "\n"
}
// Send the UI for rendering
return s
}

func Select(choices *[]string) int {
Expand Down

0 comments on commit 8299782

Please sign in to comment.