From 17f86db92db8432baeeaaac7967dc34ab89497af Mon Sep 17 00:00:00 2001 From: chessman Date: Mon, 29 Jan 2018 19:47:53 +0200 Subject: [PATCH 1/3] multiChoice: refresh only if it is necessary --- ishell.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ishell.go b/ishell.go index 97b30d6..70dd6a7 100644 --- a/ishell.go +++ b/ishell.go @@ -533,6 +533,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 +542,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{}{} From a9347218b3867e84af91e33a6a60e80d1a80b570 Mon Sep 17 00:00:00 2001 From: chessman Date: Tue, 13 Feb 2018 16:59:47 +0200 Subject: [PATCH 2/3] multiChoice: use stdout.Fd instead of hardcoded zero --- ishell.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ishell.go b/ishell.go index 70dd6a7..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 } @@ -559,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() From aa7686a29edabb9cea882eac1dcc19ef73e4ec34 Mon Sep 17 00:00:00 2001 From: dssysolyatin Date: Fri, 12 Apr 2019 17:30:39 +0300 Subject: [PATCH 3/3] Change \b to \r\r (#3) --- progress.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 {