File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -200,29 +200,29 @@ func (f *Formatter) Flush(limit bool) error {
200200 if len (f .buf .Bytes ()) == 0 {
201201 return nil
202202 }
203+ defer f .buf .Reset ()
203204
204- out := string (f .buf . Bytes () )
205+ termStartOfRow (f .w )
205206 if limit {
207+ out := string (f .buf .Bytes ())
206208 width := 0
207209 lines := 0
208- for i , r := range out {
209- if r == '\n' {
210- width = 0
211- lines ++
212- } else if width ++ ; width > cols {
210+ for _ , r := range out {
211+ width ++
212+ if r == '\n' || width > cols {
213213 width = 0
214214 lines ++
215- }
216- if lines == rows {
217- out = out [0 :i ]
218- break
215+ if lines == rows {
216+ break
217+ }
218+ if _ , err := f .w .Write ([]byte ("\n " )); err != nil {
219+ return err
220+ }
221+ } else if _ , err := f .w .Write ([]byte (string (r ))); err != nil {
222+ return err
219223 }
220224 }
221- }
222- termStartOfRow (f .w )
223- _ , err := f .w .Write ([]byte (out ))
224- f .buf .Reset ()
225- if err != nil {
225+ } else if _ , err := f .w .Write (f .buf .Bytes ()); err != nil {
226226 return err
227227 }
228228 return f .w .Flush ()
You can’t perform that action at this time.
0 commit comments