New vhs for 0.1 release
- commit
- 86b12d7ccb4a6f6e032f0a69d5e5f4adcada24f5
- author
- bnema · · 2023-11-09 15:12 UTC
- parent
- d8a0f1d
- signature
- unsigned
7 files · +55 -36
D assets/vhs/demo.gif +0 -0 binary file: no text diff
binary file: no text diff
M assets/vhs/demo.tape +4 -5
| @@ -56,6 +56,7 @@ Output demo.gif | |||
| 56 | 56 | ||
| 57 | 57 | Require echo | |
| 58 | 58 | Require gordon | |
| 59 | + | Require curl | |
| 59 | 60 | ||
| 60 | 61 | Set TypingSpeed 75ms | |
| 61 | 62 | Set Shell "bash" | |
| @@ -80,12 +81,10 @@ Type "-t hello.bamen.dev" | |||
| 80 | 81 | Sleep 1 | |
| 81 | 82 | Enter | |
| 82 | 83 | ||
| 83 | - | Sleep 10 | |
| 84 | - | ||
| 85 | - | Type "curl" | |
| 84 | + | Sleep 15 | |
| 85 | + | Enter | |
| 86 | + | Type "curl https://hello.bamen.dev" | |
| 86 | 87 | Sleep 1 | |
| 87 | - | Space | |
| 88 | - | Type "https://hello.bamen.dev" | |
| 89 | 88 | Enter | |
| 90 | 89 | ||
| 91 | 90 | Sleep 10 | |
| @@ -56,6 +56,7 @@ Output demo.gif | |||||
| 56 | 56 | ||||
| 57 | Require echo | 57 | Require echo | ||
| 58 | Require gordon | 58 | Require gordon | ||
| 59 | + | Require curl | |||
| 59 | 60 | ||||
| 60 | Set TypingSpeed 75ms | 61 | Set TypingSpeed 75ms | ||
| 61 | Set Shell "bash" | 62 | Set Shell "bash" | ||
| @@ -80,12 +81,10 @@ Type "-t hello.bamen.dev" | |||||
| 80 | Sleep 1 | 81 | Sleep 1 | ||
| 81 | Enter | 82 | Enter | ||
| 82 | 83 | ||||
| 83 | - | Sleep 10 | 84 | + | Sleep 15 |
| 84 | - | 85 | + | Enter | |
| 85 | - | Type "curl" | 86 | + | Type "curl https://hello.bamen.dev" |
| 86 | Sleep 1 | 87 | Sleep 1 | ||
| 87 | - | Space | |||
| 88 | - | Type "https://hello.bamen.dev" | |||
| 89 | Enter | 88 | Enter | ||
| 90 | 89 | ||||
| 91 | Sleep 10 | 90 | Sleep 10 | ||
A assets/vhs/demo_deploy.gif +0 -0 binary file: no text diff
binary file: no text diff
M go.mod +0 -1
| @@ -8,7 +8,6 @@ require ( | |||
| 8 | 8 | github.com/charmbracelet/bubbles v0.16.1 | |
| 9 | 9 | github.com/charmbracelet/bubbletea v0.24.1 | |
| 10 | 10 | github.com/charmbracelet/lipgloss v0.7.1 | |
| 11 | - | github.com/cheggaaa/pb v1.0.29 | |
| 12 | 11 | github.com/docker/docker v24.0.6+incompatible | |
| 13 | 12 | github.com/docker/go-connections v0.4.0 | |
| 14 | 13 | github.com/fatih/color v1.15.0 | |
| @@ -8,7 +8,6 @@ require ( | |||||
| 8 | github.com/charmbracelet/bubbles v0.16.1 | 8 | github.com/charmbracelet/bubbles v0.16.1 | ||
| 9 | github.com/charmbracelet/bubbletea v0.24.1 | 9 | github.com/charmbracelet/bubbletea v0.24.1 | ||
| 10 | github.com/charmbracelet/lipgloss v0.7.1 | 10 | github.com/charmbracelet/lipgloss v0.7.1 | ||
| 11 | - | github.com/cheggaaa/pb v1.0.29 | |||
| 12 | github.com/docker/docker v24.0.6+incompatible | 11 | github.com/docker/docker v24.0.6+incompatible | ||
| 13 | github.com/docker/go-connections v0.4.0 | 12 | github.com/docker/go-connections v0.4.0 | ||
| 14 | github.com/fatih/color v1.15.0 | 13 | github.com/fatih/color v1.15.0 | ||
M go.sum +0 -7 generated file: collapsed
M internal/cli/mvu/progressbar.go +1 -23
| @@ -1,9 +1,7 @@ | |||
| 1 | 1 | package mvu | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "fmt" | |
| 5 | 4 | "io" | |
| 6 | - | "os" | |
| 7 | 5 | "strings" | |
| 8 | 6 | ||
| 9 | 7 | "github.com/charmbracelet/bubbles/progress" | |
| @@ -33,7 +31,6 @@ type ProgressReader struct { | |||
| 33 | 31 | } | |
| 34 | 32 | ||
| 35 | 33 | func NewPBModel() Model { | |
| 36 | - | // Gradient from #011E5C to #007BC0 | |
| 37 | 34 | m := progress.New(progress.WithGradient("#007BC0", "#011E5C")) | |
| 38 | 35 | m.Width = maxWidth | |
| 39 | 36 | ||
| @@ -42,25 +39,6 @@ func NewPBModel() Model { | |||
| 42 | 39 | } | |
| 43 | 40 | } | |
| 44 | 41 | ||
| 45 | - | // Modify RunProgressBarTUI to return a pointer to Model. | |
| 46 | - | func RunProgressBarTUI(ProgressCh <-chan ProgressMsg) (*Model, error) { | |
| 47 | - | m := NewPBModel() | |
| 48 | - | p := tea.NewProgram(&m) | |
| 49 | - | // Start a goroutine that updates the progress bar as percentages are received on the channel. | |
| 50 | - | go func() { | |
| 51 | - | for percent := range ProgressCh { | |
| 52 | - | p.Send(ProgressMsg(percent)) | |
| 53 | - | } | |
| 54 | - | }() | |
| 55 | - | ||
| 56 | - | if _, err := p.Run(); err != nil { | |
| 57 | - | fmt.Println("Error running progress bar TUI:", err) | |
| 58 | - | os.Exit(1) | |
| 59 | - | } | |
| 60 | - | ||
| 61 | - | return &m, nil // Return a pointer to the model. | |
| 62 | - | } | |
| 63 | - | ||
| 64 | 42 | func (pr *ProgressReader) Read(p []byte) (int, error) { | |
| 65 | 43 | n, err := pr.Reader.Read(p) | |
| 66 | 44 | if err != nil { | |
| @@ -77,7 +55,7 @@ func (pr *ProgressReader) Close() error { | |||
| 77 | 55 | if closer, ok := pr.Reader.(io.Closer); ok { | |
| 78 | 56 | return closer.Close() | |
| 79 | 57 | } | |
| 80 | - | return nil // If there's nothing to close, return nil. | |
| 58 | + | return nil | |
| 81 | 59 | } | |
| 82 | 60 | ||
| 83 | 61 | func (m Model) Init() tea.Cmd { | |
| @@ -1,9 +1,7 @@ | |||||
| 1 | package mvu | 1 | package mvu | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | - | "fmt" | |||
| 5 | "io" | 4 | "io" | ||
| 6 | - | "os" | |||
| 7 | "strings" | 5 | "strings" | ||
| 8 | 6 | ||||
| 9 | "github.com/charmbracelet/bubbles/progress" | 7 | "github.com/charmbracelet/bubbles/progress" | ||
| @@ -33,7 +31,6 @@ type ProgressReader struct { | |||||
| 33 | } | 31 | } | ||
| 34 | 32 | ||||
| 35 | func NewPBModel() Model { | 33 | func NewPBModel() Model { | ||
| 36 | - | // Gradient from #011E5C to #007BC0 | |||
| 37 | m := progress.New(progress.WithGradient("#007BC0", "#011E5C")) | 34 | m := progress.New(progress.WithGradient("#007BC0", "#011E5C")) | ||
| 38 | m.Width = maxWidth | 35 | m.Width = maxWidth | ||
| 39 | 36 | ||||
| @@ -42,25 +39,6 @@ func NewPBModel() Model { | |||||
| 42 | } | 39 | } | ||
| 43 | } | 40 | } | ||
| 44 | 41 | ||||
| 45 | - | // Modify RunProgressBarTUI to return a pointer to Model. | |||
| 46 | - | func RunProgressBarTUI(ProgressCh <-chan ProgressMsg) (*Model, error) { | |||
| 47 | - | m := NewPBModel() | |||
| 48 | - | p := tea.NewProgram(&m) | |||
| 49 | - | // Start a goroutine that updates the progress bar as percentages are received on the channel. | |||
| 50 | - | go func() { | |||
| 51 | - | for percent := range ProgressCh { | |||
| 52 | - | p.Send(ProgressMsg(percent)) | |||
| 53 | - | } | |||
| 54 | - | }() | |||
| 55 | - | ||||
| 56 | - | if _, err := p.Run(); err != nil { | |||
| 57 | - | fmt.Println("Error running progress bar TUI:", err) | |||
| 58 | - | os.Exit(1) | |||
| 59 | - | } | |||
| 60 | - | ||||
| 61 | - | return &m, nil // Return a pointer to the model. | |||
| 62 | - | } | |||
| 63 | - | ||||
| 64 | func (pr *ProgressReader) Read(p []byte) (int, error) { | 42 | func (pr *ProgressReader) Read(p []byte) (int, error) { | ||
| 65 | n, err := pr.Reader.Read(p) | 43 | n, err := pr.Reader.Read(p) | ||
| 66 | if err != nil { | 44 | if err != nil { | ||
| @@ -77,7 +55,7 @@ func (pr *ProgressReader) Close() error { | |||||
| 77 | if closer, ok := pr.Reader.(io.Closer); ok { | 55 | if closer, ok := pr.Reader.(io.Closer); ok { | ||
| 78 | return closer.Close() | 56 | return closer.Close() | ||
| 79 | } | 57 | } | ||
| 80 | - | return nil // If there's nothing to close, return nil. | 58 | + | return nil |
| 81 | } | 59 | } | ||
| 82 | 60 | ||||
| 83 | func (m Model) Init() tea.Cmd { | 61 | func (m Model) Init() tea.Cmd { | ||
A internal/cli/mvu/run.go +50 -0
| @@ -0,0 +1,50 @@ | |||
| 1 | + | package mvu | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "fmt" | |
| 5 | + | "net/http" | |
| 6 | + | "os" | |
| 7 | + | ||
| 8 | + | tea "github.com/charmbracelet/bubbletea" | |
| 9 | + | ) | |
| 10 | + | ||
| 11 | + | // RunDeploymentTUI runs the complete deployment TUI and returns the final model | |
| 12 | + | func RunDeploymentTUI(client *http.Client, imageName, targetDomain, port string) (SpinnerModel, error) { | |
| 13 | + | m := NewSpinnerModel() | |
| 14 | + | m.deployment.imageName = imageName | |
| 15 | + | m.deployment.targetDomain = targetDomain | |
| 16 | + | m.deployment.port = port | |
| 17 | + | m.deployment.client = client | |
| 18 | + | ||
| 19 | + | p := tea.NewProgram(m) | |
| 20 | + | modelInterface, err := p.Run() | |
| 21 | + | if err != nil { | |
| 22 | + | return SpinnerModel{}, fmt.Errorf("error running TUI program: %w", err) | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | finalModel, ok := modelInterface.(SpinnerModel) | |
| 26 | + | if !ok { | |
| 27 | + | return SpinnerModel{}, fmt.Errorf("could not type assert tea model to concrete type") | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | return finalModel, nil | |
| 31 | + | } | |
| 32 | + | ||
| 33 | + | // RunProgressBarTUI runs the progress bar TUI and returns the final model | |
| 34 | + | func RunProgressBarTUI(ProgressCh <-chan ProgressMsg) (*Model, error) { | |
| 35 | + | m := NewPBModel() | |
| 36 | + | p := tea.NewProgram(&m) | |
| 37 | + | // Start a goroutine that updates the progress bar as percentages are received on the channel. | |
| 38 | + | go func() { | |
| 39 | + | for percent := range ProgressCh { | |
| 40 | + | p.Send(ProgressMsg(percent)) | |
| 41 | + | } | |
| 42 | + | }() | |
| 43 | + | ||
| 44 | + | if _, err := p.Run(); err != nil { | |
| 45 | + | fmt.Println("Error running progress bar TUI:", err) | |
| 46 | + | os.Exit(1) | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | return &m, nil | |
| 50 | + | } | |
| @@ -0,0 +1,50 @@ | |||||
| 1 | + | package mvu | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "fmt" | |||
| 5 | + | "net/http" | |||
| 6 | + | "os" | |||
| 7 | + | ||||
| 8 | + | tea "github.com/charmbracelet/bubbletea" | |||
| 9 | + | ) | |||
| 10 | + | ||||
| 11 | + | // RunDeploymentTUI runs the complete deployment TUI and returns the final model | |||
| 12 | + | func RunDeploymentTUI(client *http.Client, imageName, targetDomain, port string) (SpinnerModel, error) { | |||
| 13 | + | m := NewSpinnerModel() | |||
| 14 | + | m.deployment.imageName = imageName | |||
| 15 | + | m.deployment.targetDomain = targetDomain | |||
| 16 | + | m.deployment.port = port | |||
| 17 | + | m.deployment.client = client | |||
| 18 | + | ||||
| 19 | + | p := tea.NewProgram(m) | |||
| 20 | + | modelInterface, err := p.Run() | |||
| 21 | + | if err != nil { | |||
| 22 | + | return SpinnerModel{}, fmt.Errorf("error running TUI program: %w", err) | |||
| 23 | + | } | |||
| 24 | + | ||||
| 25 | + | finalModel, ok := modelInterface.(SpinnerModel) | |||
| 26 | + | if !ok { | |||
| 27 | + | return SpinnerModel{}, fmt.Errorf("could not type assert tea model to concrete type") | |||
| 28 | + | } | |||
| 29 | + | ||||
| 30 | + | return finalModel, nil | |||
| 31 | + | } | |||
| 32 | + | ||||
| 33 | + | // RunProgressBarTUI runs the progress bar TUI and returns the final model | |||
| 34 | + | func RunProgressBarTUI(ProgressCh <-chan ProgressMsg) (*Model, error) { | |||
| 35 | + | m := NewPBModel() | |||
| 36 | + | p := tea.NewProgram(&m) | |||
| 37 | + | // Start a goroutine that updates the progress bar as percentages are received on the channel. | |||
| 38 | + | go func() { | |||
| 39 | + | for percent := range ProgressCh { | |||
| 40 | + | p.Send(ProgressMsg(percent)) | |||
| 41 | + | } | |||
| 42 | + | }() | |||
| 43 | + | ||||
| 44 | + | if _, err := p.Run(); err != nil { | |||
| 45 | + | fmt.Println("Error running progress bar TUI:", err) | |||
| 46 | + | os.Exit(1) | |||
| 47 | + | } | |||
| 48 | + | ||||
| 49 | + | return &m, nil | |||
| 50 | + | } | |||