fix temporary newline created and removed with spinner in ollama run
This commit is contained in:
parent
e6ad4813d3
commit
6bbd6e26fb
2 changed files with 15 additions and 6 deletions
|
@ -457,7 +457,7 @@ func generate(cmd *cobra.Command, model, prompt string, wordWrap bool, format st
|
||||||
}
|
}
|
||||||
|
|
||||||
p := progress.NewProgress(os.Stderr)
|
p := progress.NewProgress(os.Stderr)
|
||||||
defer p.Stop()
|
defer p.StopAndClear()
|
||||||
|
|
||||||
spinner := progress.NewSpinner("")
|
spinner := progress.NewSpinner("")
|
||||||
p.Add("", spinner)
|
p.Add("", spinner)
|
||||||
|
@ -492,7 +492,6 @@ func generate(cmd *cobra.Command, model, prompt string, wordWrap bool, format st
|
||||||
|
|
||||||
request := api.GenerateRequest{Model: model, Prompt: prompt, Context: generateContext, Format: format}
|
request := api.GenerateRequest{Model: model, Prompt: prompt, Context: generateContext, Format: format}
|
||||||
fn := func(response api.GenerateResponse) error {
|
fn := func(response api.GenerateResponse) error {
|
||||||
spinner.Stop()
|
|
||||||
p.StopAndClear()
|
p.StopAndClear()
|
||||||
|
|
||||||
latest = response
|
latest = response
|
||||||
|
|
|
@ -27,7 +27,7 @@ func NewProgress(w io.Writer) *Progress {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Progress) Stop() bool {
|
func (p *Progress) stop() bool {
|
||||||
for _, state := range p.states {
|
for _, state := range p.states {
|
||||||
if spinner, ok := state.(*Spinner); ok {
|
if spinner, ok := state.(*Spinner); ok {
|
||||||
spinner.Stop()
|
spinner.Stop()
|
||||||
|
@ -38,22 +38,32 @@ func (p *Progress) Stop() bool {
|
||||||
p.ticker.Stop()
|
p.ticker.Stop()
|
||||||
p.ticker = nil
|
p.ticker = nil
|
||||||
p.render()
|
p.render()
|
||||||
fmt.Fprint(p.w, "\n")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Progress) Stop() bool {
|
||||||
|
stopped := p.stop()
|
||||||
|
if stopped {
|
||||||
|
fmt.Fprint(p.w, "\n")
|
||||||
|
}
|
||||||
|
return stopped
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Progress) StopAndClear() bool {
|
func (p *Progress) StopAndClear() bool {
|
||||||
fmt.Fprint(p.w, "\033[?25l")
|
fmt.Fprint(p.w, "\033[?25l")
|
||||||
defer fmt.Fprint(p.w, "\033[?25h")
|
defer fmt.Fprint(p.w, "\033[?25h")
|
||||||
|
|
||||||
stopped := p.Stop()
|
stopped := p.stop()
|
||||||
if stopped {
|
if stopped {
|
||||||
// clear all progress lines
|
// clear all progress lines
|
||||||
for i := 0; i < p.pos; i++ {
|
for i := 0; i < p.pos; i++ {
|
||||||
fmt.Fprint(p.w, "\033[A\033[2K\033[1G")
|
if i > 0 {
|
||||||
|
fmt.Fprint(p.w, "\033[A")
|
||||||
|
}
|
||||||
|
fmt.Fprint(p.w, "\033[2K\033[1G")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue