Skip to content

Commit

Permalink
WTF-1221 Remove explicit calls to *Draw() functions from within the m…
Browse files Browse the repository at this point in the history
…odule go routines (#1229)

Signed-off-by: Chris Cummer <[email protected]>
  • Loading branch information
senorprogrammer authored Apr 29, 2022
1 parent 9bba717 commit e72dcda
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 49 deletions.
1 change: 1 addition & 0 deletions app/wtf_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (wtfApp *WtfApp) stopAllWidgets() {

func (wtfApp *WtfApp) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
// These keys are global keys used by the app. Widgets should not implement these keys

switch event.Key() {
case tcell.KeyCtrlC:
wtfApp.Stop()
Expand Down
10 changes: 0 additions & 10 deletions modules/bargraph/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,5 @@ func (widget *Widget) Refresh() {
}

widget.View.Clear()

widget.tviewApp.QueueUpdateDraw(func() {
display(widget)
})

}

/* -------------------- Unexported Functions -------------------- */

func display(widget *Widget) {
MakeGraph(widget)
}
8 changes: 3 additions & 5 deletions modules/git/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ func (widget *Widget) addCancelButton(form *tview.Form) {
}

func (widget *Widget) modalFocus(form *tview.Form) {
widget.tviewApp.QueueUpdateDraw(func() {
frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true)
widget.tviewApp.SetFocus(frame)
})
frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true)
widget.tviewApp.SetFocus(frame)
}

func (widget *Widget) modalForm(lbl, text string) *tview.Form {
Expand Down
8 changes: 3 additions & 5 deletions modules/mercurial/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ func (widget *Widget) addCancelButton(form *tview.Form) {
}

func (widget *Widget) modalFocus(form *tview.Form) {
widget.tviewApp.QueueUpdateDraw(func() {
frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true)
widget.tviewApp.SetFocus(frame)
})
frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true)
widget.tviewApp.SetFocus(frame)
}

func (widget *Widget) modalForm(lbl, text string) *tview.Form {
Expand Down
10 changes: 2 additions & 8 deletions modules/resourceusage/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,12 @@ func (widget *Widget) Refresh() {
return
}

widget.tviewApp.QueueUpdateDraw(func() {
widget.View.Clear()
display(widget)
})
widget.View.Clear()
MakeGraph(widget)
}

/* -------------------- Unexported Functions -------------------- */

func display(widget *Widget) {
MakeGraph(widget)
}

func getDataFromSystem(widget *Widget) (cpuStats []float64, memInfo mem.VirtualMemoryStat) {
if widget.settings.showCPU {
rCPUStats, err := cpu.Percent(time.Duration(0), !widget.settings.cpuCombined)
Expand Down
12 changes: 3 additions & 9 deletions modules/todo/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ func (widget *Widget) processFormInput(prompt string, initValue string, onSave f

widget.addButtons(form, saveFctn)
widget.modalFocus(form)

widget.tviewApp.QueueUpdate(func() {
widget.tviewApp.Draw()
})
}

// updateSelectedItem update the text of the selected item.
Expand Down Expand Up @@ -377,11 +373,9 @@ func (widget *Widget) addSaveButton(form *tview.Form, fctn func()) {
}

func (widget *Widget) modalFocus(form *tview.Form) {
widget.tviewApp.QueueUpdateDraw(func() {
frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true)
widget.tviewApp.SetFocus(frame)
})
frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true)
widget.tviewApp.SetFocus(frame)
}

func (widget *Widget) modalForm(lbl, text string) *tview.Form {
Expand Down
6 changes: 2 additions & 4 deletions view/scrollable_widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ func (widget *ScrollableWidget) Unselect() {
func (widget *ScrollableWidget) Redraw(data func() (string, string, bool)) {
widget.TextWidget.Redraw(data)

widget.tviewApp.QueueUpdateDraw(func() {
widget.View.Highlight(strconv.Itoa(widget.Selected))
widget.View.ScrollToHighlight()
})
widget.View.Highlight(strconv.Itoa(widget.Selected))
widget.View.ScrollToHighlight()
}
14 changes: 6 additions & 8 deletions view/text_widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ func (widget *TextWidget) TextView() *tview.TextView {

// Redraw forces a refresh of the onscreen text content of this widget
func (widget *TextWidget) Redraw(data func() (string, string, bool)) {
widget.tviewApp.QueueUpdateDraw(func() {
title, content, wrap := data()

widget.View.Clear()
widget.View.SetWrap(wrap)
widget.View.SetTitle(widget.ContextualTitle(title))
widget.View.SetText(strings.TrimRight(content, "\n"))
})
title, content, wrap := data()

widget.View.Clear()
widget.View.SetWrap(wrap)
widget.View.SetTitle(widget.ContextualTitle(title))
widget.View.SetText(strings.TrimRight(content, "\n"))
}

/* -------------------- Unexported Functions -------------------- */
Expand Down

0 comments on commit e72dcda

Please sign in to comment.