Wait for log-pipe to finish before opening another log

This commit is contained in:
Christian Muehlhaeuser 2018-03-27 06:37:05 +02:00
parent a65a7d236a
commit b247f20a9c
No known key found for this signature in database
GPG Key ID: BA4CF857DD4117E9
1 changed files with 9 additions and 6 deletions

View File

@ -92,7 +92,8 @@ func logsForm() (tview.Primitive, error) {
go pipeReader(errReader, errLogView) go pipeReader(errReader, errLogView)
list.SetSelectedFunc(func(index int, primText, secText string, shortcut rune) { list.SetSelectedFunc(func(index int, primText, secText string, shortcut rune) {
selectLog(pipe, list.Model[index], filter, logView) pipe = selectLog(pipe, list.Model[index], filter, logView)
app.SetFocus(logView)
}) })
flex := tview.NewFlex(). flex := tview.NewFlex().
@ -126,8 +127,9 @@ func logsForm() (tview.Primitive, error) {
SetAcceptanceFunc(nil). SetAcceptanceFunc(nil).
SetDoneFunc(func(key tcell.Key) { SetDoneFunc(func(key tcell.Key) {
search = searchInput.GetText() search = searchInput.GetText()
selectLog(pipe, list.Model[list.GetCurrentItem()], filter, logView)
menuPages.HidePage("search") menuPages.HidePage("search")
pipe = selectLog(pipe, list.Model[list.GetCurrentItem()], filter, logView)
app.SetFocus(logView)
}) })
menuPages.AddPage("menu", menu, true, true) menuPages.AddPage("menu", menu, true, true)
@ -144,7 +146,7 @@ func logsForm() (tview.Primitive, error) {
logLevelDropDown.SetSelectedFunc(func(index int, primText, secText string, shortcut rune) { logLevelDropDown.SetSelectedFunc(func(index int, primText, secText string, shortcut rune) {
filter = logLevelFilter(index) filter = logLevelFilter(index)
pages.HidePage("dropdown_loglevel") pages.HidePage("dropdown_loglevel")
selectLog(pipe, list.Model[list.GetCurrentItem()], filter, logView) pipe = selectLog(pipe, list.Model[list.GetCurrentItem()], filter, logView)
}) })
menu.AddItem("All Services", tcell.KeyF1, func() { menu.AddItem("All Services", tcell.KeyF1, func() {
@ -171,7 +173,7 @@ func logsForm() (tview.Primitive, error) {
AddItem(pages, 0, 1, true). AddItem(pages, 0, 1, true).
AddItem(menuPages, 1, 1, false) AddItem(menuPages, 1, 1, false)
selectLog(pipe, list.Model[0], filter, logView) pipe = selectLog(pipe, list.Model[0], filter, logView)
return layout, nil return layout, nil
} }
@ -189,10 +191,11 @@ func logLevelFilter(index int) []sdjournal.Match {
return f return f
} }
func selectLog(pipe *LogPipe, log ServiceItem, filter []sdjournal.Match, logView *tview.TextView) { func selectLog(pipe *LogPipe, log ServiceItem, filter []sdjournal.Match, logView *tview.TextView) *LogPipe {
// cancel previous reader // cancel previous reader
if pipe != nil { if pipe != nil {
pipe.Cancel <- time.Now() pipe.Cancel <- time.Now()
pipe.WaitGroup.Wait()
} }
logView.Clear() logView.Clear()
@ -207,7 +210,7 @@ func selectLog(pipe *LogPipe, log ServiceItem, filter []sdjournal.Match, logView
pipe = logPipe(log.Matches, filter) pipe = logPipe(log.Matches, filter)
go pipeReader(pipe, logView) go pipeReader(pipe, logView)
app.SetFocus(logView) return pipe
} }
func init() { func init() {