mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Fix potential race conditions in Logger
This commit is contained in:
parent
6e30961f25
commit
e97283433f
@ -16,6 +16,7 @@ const maxBufferSize int64 = 1024
|
|||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
|
app *tview.Application
|
||||||
filePath string
|
filePath string
|
||||||
settings *Settings
|
settings *Settings
|
||||||
}
|
}
|
||||||
@ -24,6 +25,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
|
app: app,
|
||||||
filePath: logFilePath(),
|
filePath: logFilePath(),
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
@ -48,15 +50,18 @@ func Log(msg string) {
|
|||||||
log.Println(msg)
|
log.Println(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh updates the onscreen contents of the widget
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
if logFileMissing() {
|
if logFileMissing() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetTitle(widget.Name())
|
|
||||||
|
|
||||||
logLines := widget.tailFile()
|
logLines := widget.tailFile()
|
||||||
|
|
||||||
|
widget.app.QueueUpdateDraw(func() {
|
||||||
|
widget.View.SetTitle(widget.Name())
|
||||||
widget.View.SetText(widget.contentFrom(logLines))
|
widget.View.SetText(widget.contentFrom(logLines))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -35,6 +35,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
|
// Refresh updates the onscreen contents of the widget
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.app.QueueUpdateDraw(func() {
|
widget.app.QueueUpdateDraw(func() {
|
||||||
sortedClocks := widget.clockColl.Sorted(widget.settings.sort)
|
sortedClocks := widget.clockColl.Sorted(widget.settings.sort)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user