Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ui and bump dependency #40

Merged
merged 3 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions cmd/internal/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/containerd/console"
"github.com/muesli/termenv"
)

type SpinnerCmd struct {
p *tea.Program
spinnerModel spinner.Model
size console.WinSize
err error
title string
cmd *exec.Cmd
Expand All @@ -28,7 +30,7 @@ type SpinnerCmd struct {

func NewSpinnerCmd(cmd *exec.Cmd, title ...string) *SpinnerCmd {
spinnerModel := spinner.NewModel()
spinnerModel.Frames = spinner.Dot
spinnerModel.Spinner = spinner.Dot

c := &SpinnerCmd{
spinnerModel: spinnerModel,
Expand All @@ -49,7 +51,7 @@ func NewSpinnerCmd(cmd *exec.Cmd, title ...string) *SpinnerCmd {
}

func (t *SpinnerCmd) Init() tea.Cmd {
return tea.Batch(t.init(), spinner.Tick(t.spinnerModel))
return tea.Batch(t.init(), spinner.Tick)
}

func (t *SpinnerCmd) init() tea.Cmd {
Expand Down Expand Up @@ -100,7 +102,7 @@ func (t *SpinnerCmd) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

var cmd tea.Cmd
t.spinnerModel, cmd = spinner.Update(msg, t.spinnerModel)
t.spinnerModel, cmd = t.spinnerModel.Update(msg)
return t, cmd
}

Expand All @@ -110,13 +112,19 @@ func (t *SpinnerCmd) View() string {
}

s := termenv.
String(spinner.View(t.spinnerModel)).
String(t.spinnerModel.View()).
Foreground(term.Color("205")).
String()

t.UpdateOutput(t.stdout)
t.UpdateOutput(t.stderr)

// Make sure buf length not exceed screen width
maxWidth := int(t.size.Width) - 2 - len(s) - 1 - len(t.title) - 1
if len(t.buf) > maxWidth {
t.buf = append(t.buf[:maxWidth-3], []byte("...")...)
}

return fmt.Sprintf(spinnerCmdTemplate, s, t.title, t.buf)
}

Expand All @@ -128,7 +136,7 @@ const spinnerCmdTemplate = `
`

func (t *SpinnerCmd) Run() (err error) {
if err = checkConsole(); err != nil {
if t.size, err = checkConsole(); err != nil {
return
}

Expand Down
6 changes: 2 additions & 4 deletions cmd/internal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ var term = termenv.ColorProfile()

type finishedMsg struct{ error }

func checkConsole() (err error) {
func checkConsole() (size console.WinSize, err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("%v", e)
}
}()

console.Current()

return
return console.Current().Size()
}

func errCmd(err error) tea.Cmd {
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func parseBool(str string) bool {
}

func (p *Prompt) Answer() (result string, err error) {
if err = checkConsole(); err != nil {
if _, err = checkConsole(); err != nil {
return
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Test_Prompt_Update(t *testing.T) {
at.NotNil(p.err)
at.Nil(cmd)

_, cmd = p.Update(tea.KeyMsg{Type: tea.KeyRune, Rune: 'a'})
_, cmd = p.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'a'}})
at.Nil(cmd)

_, cmd = p.Update(tea.KeyMsg{Type: tea.KeyCtrlC})
Expand Down
10 changes: 5 additions & 5 deletions cmd/internal/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SpinnerTask struct {

func NewSpinnerTask(title string, task Task) *SpinnerTask {
spinnerModel := spinner.NewModel()
spinnerModel.Frames = spinner.Dot
spinnerModel.Spinner = spinner.Dot

at := &SpinnerTask{
title: title,
Expand All @@ -37,7 +37,7 @@ func (t *SpinnerTask) Init() tea.Cmd {
return tea.Batch(
func() tea.Msg {
return finishedMsg{t.task()}
}, spinner.Tick(t.spinnerModel))
}, spinner.Tick)
}

func (t *SpinnerTask) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
Expand All @@ -58,7 +58,7 @@ func (t *SpinnerTask) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

default:
var cmd tea.Cmd
t.spinnerModel, cmd = spinner.Update(msg, t.spinnerModel)
t.spinnerModel, cmd = t.spinnerModel.Update(msg)
return t, cmd
}

Expand All @@ -70,15 +70,15 @@ func (t *SpinnerTask) View() string {
}

s := termenv.
String(spinner.View(t.spinnerModel)).
String(t.spinnerModel.View()).
Foreground(term.Color("205")).
String()

return fmt.Sprintf("\n %s %s\n\n(esc/q/ctrl+c to quit)\n\n", s, t.title)
}

func (t *SpinnerTask) Run() (err error) {
if err = checkConsole(); err != nil {
if _, err = checkConsole(); err != nil {
return
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

const version = "0.0.5"
const version = "0.0.6"
const configName = ".fiberconfig"

var (
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/gofiber/cli
go 1.14

require (
github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c
github.com/charmbracelet/bubbletea v0.12.2-0.20201030073758-eae4d669176e
github.com/charmbracelet/bubbles v0.7.5
github.com/charmbracelet/bubbletea v0.12.2
github.com/containerd/console v1.0.1
github.com/fsnotify/fsnotify v1.4.9
github.com/jarcoal/httpmock v1.0.6
Expand All @@ -13,7 +13,8 @@ require (
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 // indirect
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 // indirect
golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c h1:sXhe4YmFER1XE+Xl4z5aKmxB1vgYFS35rYHl+SdqStw=
github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc=
github.com/charmbracelet/bubbles v0.7.5 h1:N6TiahuRt2iGNE5gYxKBQ5/C6Lc8xxSp5LY9QJ09mS4=
github.com/charmbracelet/bubbles v0.7.5/go.mod h1:IRTORFvhEI6OUH7WhN2Ks8Z8miNGimk1BE6cmHijOkM=
github.com/charmbracelet/bubbletea v0.12.1 h1:t21pkG2IDBRduPbt2J64Dx5yt8yIidAkXwhhrc11SzY=
github.com/charmbracelet/bubbletea v0.12.1/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg=
github.com/charmbracelet/bubbletea v0.12.2-0.20201030073758-eae4d669176e h1:YtuSHt+8rTjzKIenKZ0I15Abt9wfItNjHvwTdiwem8U=
github.com/charmbracelet/bubbletea v0.12.2-0.20201030073758-eae4d669176e/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg=
github.com/charmbracelet/bubbletea v0.12.2 h1:y9Yo2Pv8tcm3mAJsWONGsmHhzrbNxJVxpVtemikxE9A=
github.com/charmbracelet/bubbletea v0.12.2/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/containerd/console v1.0.1 h1:u7SFAJyRqWcG6ogaMAx3KjSTy1e3hT9QxqX7Jco7dRc=
github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=
Expand Down Expand Up @@ -227,6 +231,8 @@ golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1V
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 h1:phUcVbl53swtrUN8kQEXFhUxPlIlWyBfKmidCu7P95o=
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -281,13 +287,18 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a h1:e3IU37lwO4aq3uoRKINC7JikojFmE5gO7xhfxs8VC34=
golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 h1:HlFl4V6pEMziuLXyRkm5BIYq1y1GAbb02pRlWvI54OM=
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7 h1:s330+6z/Ko3J0o6rvOcwXe5nzs7UT9tLKHoOXYn6uE0=
golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down