File tree 1 file changed +8
-5
lines changed
1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,10 @@ type WordWrap struct {
30
30
31
31
hardWriter ansi.Writer
32
32
33
- lineLen int
34
- ansi bool
35
- lastAnsi bytes.Buffer
33
+ wroteBegin bool
34
+ lineLen int
35
+ ansi bool
36
+ lastAnsi bytes.Buffer
36
37
}
37
38
38
39
// NewWriter returns a new instance of a word-wrapping writer, initialized with
@@ -86,6 +87,7 @@ func (w *WordWrap) addNewLine() {
86
87
w .buf .WriteRune ('\n' )
87
88
w .lineLen = 0
88
89
w .space .Reset ()
90
+ w .wroteBegin = false
89
91
}
90
92
91
93
func inGroup (a []rune , c rune ) bool {
@@ -110,10 +112,11 @@ func (w *WordWrap) Write(b []byte) (int, error) {
110
112
111
113
for _ , c := range s {
112
114
// 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 {
114
116
w .buf .Write (w .lastAnsi .Bytes ())
115
117
w .addWord ()
116
118
}
119
+ w .wroteBegin = true
117
120
if c == '\x1B' {
118
121
// ANSI escape sequence
119
122
w .word .WriteRune (c )
@@ -126,7 +129,7 @@ func (w *WordWrap) Write(b []byte) (int, error) {
126
129
// ANSI sequence terminated
127
130
w .ansi = false
128
131
}
129
- if w .lastAnsi .String () == "\x1b [0m" {
132
+ if c == 'm' && strings . HasSuffix ( w .lastAnsi .String (), "\x1b [0m" ) {
130
133
w .lastAnsi .Reset ()
131
134
}
132
135
} else if inGroup (w .Newline , c ) {
You can’t perform that action at this time.
0 commit comments