File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,10 @@ type WordWrap struct {
3030
3131 hardWriter ansi.Writer
3232
33- lineLen int
34- ansi bool
35- lastAnsi bytes.Buffer
33+ wroteBegin bool
34+ lineLen int
35+ ansi bool
36+ lastAnsi bytes.Buffer
3637}
3738
3839// NewWriter returns a new instance of a word-wrapping writer, initialized with
@@ -86,6 +87,7 @@ func (w *WordWrap) addNewLine() {
8687 w .buf .WriteRune ('\n' )
8788 w .lineLen = 0
8889 w .space .Reset ()
90+ w .wroteBegin = false
8991}
9092
9193func inGroup (a []rune , c rune ) bool {
@@ -110,10 +112,11 @@ func (w *WordWrap) Write(b []byte) (int, error) {
110112
111113 for _ , c := range s {
112114 // Restart Ansi after line break if there is more text
113- if w . lineLen == 0 && w . buf . Len () == 0 && w .lastAnsi .Len () != 0 {
115+ if ! w . wroteBegin && ! w . ansi && w .lastAnsi .Len () != 0 {
114116 w .buf .Write (w .lastAnsi .Bytes ())
115117 w .addWord ()
116118 }
119+ w .wroteBegin = true
117120 if c == '\x1B' {
118121 // ANSI escape sequence
119122 w .word .WriteRune (c )
@@ -126,7 +129,7 @@ func (w *WordWrap) Write(b []byte) (int, error) {
126129 // ANSI sequence terminated
127130 w .ansi = false
128131 }
129- if w .lastAnsi .String () == "\x1b [0m" {
132+ if c == 'm' && strings . HasSuffix ( w .lastAnsi .String (), "\x1b [0m" ) {
130133 w .lastAnsi .Reset ()
131134 }
132135 } else if inGroup (w .Newline , c ) {
You can’t perform that action at this time.
0 commit comments