stop all spinners on progress stop
This commit is contained in:
parent
4d677ee389
commit
976068369b
2 changed files with 24 additions and 34 deletions
52
cmd/cmd.go
52
cmd/cmd.go
|
@ -53,7 +53,7 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
|
|||
|
||||
bars := make(map[string]*progress.Bar)
|
||||
|
||||
status := "transferring context"
|
||||
status := fmt.Sprintf("creating %s", args[0])
|
||||
spinner := progress.NewSpinner(status)
|
||||
p.Add(status, spinner)
|
||||
|
||||
|
@ -72,6 +72,12 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
spinner.Stop()
|
||||
|
||||
status = "transferring context"
|
||||
spinner = progress.NewSpinner(status)
|
||||
p.Add(status, spinner)
|
||||
|
||||
for _, c := range commands {
|
||||
switch c.Name {
|
||||
case "model", "adapter":
|
||||
|
@ -133,10 +139,6 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if spinner != nil {
|
||||
spinner.Stop()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -178,15 +180,13 @@ func PushHandler(cmd *cobra.Command, args []string) error {
|
|||
|
||||
bars := make(map[string]*progress.Bar)
|
||||
|
||||
var status string
|
||||
var spinner *progress.Spinner
|
||||
status := fmt.Sprintf("pushing %s", args[0])
|
||||
spinner := progress.NewSpinner(status)
|
||||
p.Add(status, spinner)
|
||||
|
||||
fn := func(resp api.ProgressResponse) error {
|
||||
if resp.Digest != "" {
|
||||
if spinner != nil {
|
||||
spinner.Stop()
|
||||
spinner = nil
|
||||
}
|
||||
spinner.Stop()
|
||||
|
||||
bar, ok := bars[resp.Digest]
|
||||
if !ok {
|
||||
|
@ -197,10 +197,7 @@ func PushHandler(cmd *cobra.Command, args []string) error {
|
|||
|
||||
bar.Set(resp.Completed)
|
||||
} else if status != resp.Status {
|
||||
if spinner != nil {
|
||||
spinner.Stop()
|
||||
spinner = nil
|
||||
}
|
||||
spinner.Stop()
|
||||
|
||||
status = resp.Status
|
||||
spinner = progress.NewSpinner(status)
|
||||
|
@ -215,10 +212,7 @@ func PushHandler(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if spinner != nil {
|
||||
spinner.Stop()
|
||||
}
|
||||
|
||||
spinner.Stop()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -379,15 +373,13 @@ func PullHandler(cmd *cobra.Command, args []string) error {
|
|||
|
||||
bars := make(map[string]*progress.Bar)
|
||||
|
||||
var status string
|
||||
var spinner *progress.Spinner
|
||||
status := fmt.Sprintf("pulling %s", args[0])
|
||||
spinner := progress.NewSpinner(status)
|
||||
p.Add(status, spinner)
|
||||
|
||||
fn := func(resp api.ProgressResponse) error {
|
||||
if resp.Digest != "" {
|
||||
if spinner != nil {
|
||||
spinner.Stop()
|
||||
spinner = nil
|
||||
}
|
||||
spinner.Stop()
|
||||
|
||||
bar, ok := bars[resp.Digest]
|
||||
if !ok {
|
||||
|
@ -398,10 +390,7 @@ func PullHandler(cmd *cobra.Command, args []string) error {
|
|||
|
||||
bar.Set(resp.Completed)
|
||||
} else if status != resp.Status {
|
||||
if spinner != nil {
|
||||
spinner.Stop()
|
||||
spinner = nil
|
||||
}
|
||||
spinner.Stop()
|
||||
|
||||
status = resp.Status
|
||||
spinner = progress.NewSpinner(status)
|
||||
|
@ -416,10 +405,6 @@ func PullHandler(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if spinner != nil {
|
||||
spinner.Stop()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -476,7 +461,6 @@ func generate(cmd *cobra.Command, model, prompt string, wordWrap bool, format st
|
|||
defer p.Stop()
|
||||
|
||||
spinner := progress.NewSpinner("")
|
||||
defer spinner.Stop()
|
||||
p.Add("", spinner)
|
||||
|
||||
var latest api.GenerateResponse
|
||||
|
|
|
@ -31,6 +31,12 @@ func NewProgress(w io.Writer) *Progress {
|
|||
}
|
||||
|
||||
func (p *Progress) Stop() bool {
|
||||
for _, state := range p.states {
|
||||
if spinner, ok := state.(*Spinner); ok {
|
||||
spinner.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
if p.ticker != nil {
|
||||
p.ticker.Stop()
|
||||
p.ticker = nil
|
||||
|
|
Loading…
Reference in a new issue