@@ -70,6 +70,9 @@ type LinesToRead struct {
70
70
// do an initial refresh. Only set for the initial read request; -1 for
71
71
// subsequent requests.
72
72
InitialRefreshAfter int
73
+
74
+ // Function to call after reading the lines is done
75
+ Then func ()
73
76
}
74
77
75
78
func (m * ViewBufferManager ) GetTaskKey () string {
@@ -105,6 +108,16 @@ func (self *ViewBufferManager) ReadLines(n int) {
105
108
}
106
109
}
107
110
111
+ func (self * ViewBufferManager ) ReadToEnd (then func ()) {
112
+ if self .readLines != nil {
113
+ go utils .Safe (func () {
114
+ self .readLines <- LinesToRead {Total : - 1 , InitialRefreshAfter : - 1 , Then : then }
115
+ })
116
+ } else if then != nil {
117
+ then ()
118
+ }
119
+ }
120
+
108
121
func (self * ViewBufferManager ) NewCmdTask (start func () (* exec.Cmd , io.Reader ), prefix string , linesToRead LinesToRead , onDoneFn func ()) func (TaskOpts ) error {
109
122
return func (opts TaskOpts ) error {
110
123
var onDoneOnce sync.Once
@@ -234,11 +247,17 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
234
247
case <- opts .Stop :
235
248
break outer
236
249
case linesToRead := <- self .readLines :
237
- for i := 0 ; i < linesToRead .Total ; i ++ {
250
+ callThen := func () {
251
+ if linesToRead .Then != nil {
252
+ linesToRead .Then ()
253
+ }
254
+ }
255
+ for i := 0 ; linesToRead .Total == - 1 || i < linesToRead .Total ; i ++ {
238
256
var ok bool
239
257
var line []byte
240
258
select {
241
259
case <- opts .Stop :
260
+ callThen ()
242
261
break outer
243
262
case line , ok = <- lineChan :
244
263
break
@@ -258,6 +277,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
258
277
// if we're here then there's nothing left to scan from the source
259
278
// so we're at the EOF and can flush the stale content
260
279
self .onEndOfInput ()
280
+ callThen ()
261
281
break outer
262
282
}
263
283
writeToView (append (line , '\n' ))
@@ -272,6 +292,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
272
292
}
273
293
refreshViewIfStale ()
274
294
onFirstPageShown ()
295
+ callThen ()
275
296
}
276
297
}
277
298
0 commit comments