diff --git a/ishell.go b/ishell.go index 97b30d6..f9db90e 100644 --- a/ishell.go +++ b/ishell.go @@ -478,7 +478,8 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu return nil } - _, maxRows, err := readline.GetSize(0) + stdoutFd := int(os.Stdout.Fd()) + _, maxRows, err := readline.GetSize(stdoutFd) if err != nil { return nil } @@ -533,6 +534,8 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu if multiResults { selected = toggle(selected, cur) } + } else { + return } refresh <- struct{}{} return @@ -540,6 +543,8 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu conf.Listener = readline.FuncListener(listener) oldconf := s.reader.scanner.SetConfig(conf) + update() + stop := make(chan struct{}) defer func() { stop <- struct{}{} @@ -555,7 +560,7 @@ func (s *Shell) multiChoice(options []string, text string, init []int, multiResu case <-refresh: update() case <-t.C: - _, rows, _ := readline.GetSize(0) + _, rows, _ := readline.GetSize(stdoutFd) if maxRows != rows { maxRows = rows update() diff --git a/progress.go b/progress.go index 2d73c66..7e746d6 100644 --- a/progress.go +++ b/progress.go @@ -119,17 +119,25 @@ func (p *progressBarImpl) write(s string) error { } func (p *progressBarImpl) erase(n int) { - for i := 0; i < n; i++ { - p.writer.Write([]byte{'\b'}) + // Don't use '\b' - it's only move cursor to back + b := make([]byte, 0, n+2) + b = append(b, '\r') + for i := 0; i < n; i ++ { + b = append(b, ' ') } + b = append(b, '\r') + p.writer.Write(b) } func (p *progressBarImpl) done() { p.wMutex.Lock() defer p.wMutex.Unlock() - p.erase(p.writtenLen) - fmt.Fprintln(p.writer, p.final) + if p.final != "" { + p.erase(p.writtenLen) + fmt.Fprintln(p.writer, p.final) + } + } func (p *progressBarImpl) output() string {