Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
update progress rendering to be closer to `v0.1.10`
Jeffrey Morganc06b9b7304a5
diff --git a/cmd/cmd.go b/cmd/cmd.goindex d4c5f92cd..68636dcf2 100644--- a/cmd/cmd.go+++ b/cmd/cmd.go@@ -53,10 +53,6 @@ func CreateHandler(cmd *cobra.Command, args []string) error {bars := make(map[string]*progress.Bar)- status := fmt.Sprintf("creating %s", args[0])- spinner := progress.NewSpinner(status)- p.Add(status, spinner)-modelfile, err := os.ReadFile(filename)if err != nil {return err@@ -72,10 +68,8 @@ func CreateHandler(cmd *cobra.Command, args []string) error {return err}- spinner.Stop()-- status = "transferring model data"- spinner = progress.NewSpinner(status)+ status := "transferring model data"+ spinner := progress.NewSpinner(status)p.Add(status, spinner)for _, c := range commands {@@ -179,14 +173,14 @@ func PushHandler(cmd *cobra.Command, args []string) error {defer p.Stop()bars := make(map[string]*progress.Bar)-- status := fmt.Sprintf("pushing %s", args[0])- spinner := progress.NewSpinner(status)- p.Add(status, spinner)+ var status string+ var spinner *progress.Spinnerfn := func(resp api.ProgressResponse) error {if resp.Digest != "" {- spinner.Stop()+ if spinner != nil {+ spinner.Stop()+ }bar, ok := bars[resp.Digest]if !ok {@@ -197,7 +191,9 @@ func PushHandler(cmd *cobra.Command, args []string) error {bar.Set(resp.Completed)} else if status != resp.Status {- spinner.Stop()+ if spinner != nil {+ spinner.Stop()+ }status = resp.Statusspinner = progress.NewSpinner(status)@@ -373,13 +369,14 @@ func PullHandler(cmd *cobra.Command, args []string) error {bars := make(map[string]*progress.Bar)- status := fmt.Sprintf("pulling %s", args[0])- spinner := progress.NewSpinner(status)- p.Add(status, spinner)+ var status string+ var spinner *progress.Spinnerfn := func(resp api.ProgressResponse) error {if resp.Digest != "" {- spinner.Stop()+ if spinner != nil {+ spinner.Stop()+ }bar, ok := bars[resp.Digest]if !ok {@@ -390,7 +387,9 @@ func PullHandler(cmd *cobra.Command, args []string) error {bar.Set(resp.Completed)} else if status != resp.Status {- spinner.Stop()+ if spinner != nil {+ spinner.Stop()+ }status = resp.Statusspinner = progress.NewSpinner(status)diff --git a/progress/bar.go b/progress/bar.goindex 6be4ab2b7..a8383f5cd 100644--- a/progress/bar.go+++ b/progress/bar.go@@ -66,7 +66,8 @@ func (b *Bar) String() string {mid.WriteString("▕")- f := termWidth - pre.Len() - suf.Len() - 2+ // add 3 extra spaces: 2 boundary characters and 1 space at the end+ f := termWidth - pre.Len() - suf.Len() - 3n := int(float64(f) * b.percent() / 100)if n > 0 {diff --git a/progress/progress.go b/progress/progress.goindex 8c195be9d..3c488307f 100644--- a/progress/progress.go+++ b/progress/progress.go@@ -12,9 +12,10 @@ type State interface {}type Progress struct {- mu sync.Mutex+ mu sync.Mutex+ w io.Writer+pos int- w io.Writerticker *time.Tickerstates []State@@ -37,6 +38,7 @@ func (p *Progress) Stop() bool {p.ticker.Stop()p.ticker = nilp.render()+ fmt.Fprint(p.w, "\n")return true}@@ -50,11 +52,8 @@ func (p *Progress) StopAndClear() bool {stopped := p.Stop()if stopped {// clear the progress bar by:- // 1. for each line in the progress:- // a. move the cursor up one line- // b. clear the linefor i := 0; i < p.pos; i++ {- fmt.Fprint(p.w, "\033[A\033[2K")+ fmt.Fprint(p.w, "\033[A\033[2K\033[1G")}}@@ -75,17 +74,23 @@ func (p *Progress) render() error {fmt.Fprint(p.w, "\033[?25l")defer fmt.Fprint(p.w, "\033[?25h")- if p.pos > 0 {- fmt.Fprintf(p.w, "\033[%dA", p.pos)+ // clear already rendered progress lines+ for i := 0; i < p.pos; i++ {+ if i > 0 {+ fmt.Fprint(p.w, "\033[A")+ }+ fmt.Fprint(p.w, "\033[2K\033[1G")}- for _, state := range p.states {- fmt.Fprintln(p.w, state.String())+ // render progress lines+ for i, state := range p.states {+ fmt.Fprint(p.w, state.String())+ if i < len(p.states)-1 {+ fmt.Fprint(p.w, "\n")+ }}- if len(p.states) > 0 {- p.pos = len(p.states)- }+ p.pos = len(p.states)return nil}diff --git a/progress/spinner.go b/progress/spinner.goindex bc46bc023..62ed4f094 100644--- a/progress/spinner.go+++ b/progress/spinner.go@@ -2,11 +2,8 @@ package progressimport ("fmt"- "os""strings""time"-- "golang.org/x/term")type Spinner struct {@@ -35,45 +32,28 @@ func NewSpinner(message string) *Spinner {}func (s *Spinner) String() string {- termWidth, _, err := term.GetSize(int(os.Stderr.Fd()))- if err != nil {- panic(err)- }-- var pre strings.Builder+ var sb strings.Builderif len(s.message) > 0 {message := strings.TrimSpace(s.message)if s.messageWidth > 0 && len(message) > s.messageWidth {message = message[:s.messageWidth]}- fmt.Fprintf(&pre, "%s", message)- if s.messageWidth-pre.Len() >= 0 {- pre.WriteString(strings.Repeat(" ", s.messageWidth-pre.Len()))+ fmt.Fprintf(&sb, "%s", message)+ if s.messageWidth-sb.Len() >= 0 {+ sb.WriteString(strings.Repeat(" ", s.messageWidth-sb.Len()))}- pre.WriteString(" ")+ sb.WriteString(" ")}- var pad intif s.stopped.IsZero() {- // spinner has a string length of 3 but a rune length of 1- // in order to align correctly, we need to pad with (3 - 1) = 2 spacesspinner := s.parts[s.value]- pre.WriteString(spinner)- pad = len(spinner) - len([]rune(spinner))- }-- var suf strings.Builder- fmt.Fprintf(&suf, "(%s)", s.elapsed())-- var mid strings.Builder- f := termWidth - pre.Len() - mid.Len() - suf.Len() + pad- if f > 0 {- mid.WriteString(strings.Repeat(" ", f))+ sb.WriteString(spinner)+ sb.WriteString(" ")}- return pre.String() + mid.String() + suf.String()+ return sb.String()}func (s *Spinner) start() {@@ -91,12 +71,3 @@ func (s *Spinner) Stop() {s.stopped = time.Now()}}--func (s *Spinner) elapsed() time.Duration {- stopped := s.stopped- if stopped.IsZero() {- stopped = time.Now()- }-- return stopped.Sub(s.started).Round(time.Second)-}