Skip to content

Commit

Permalink
Resolve crash I hope
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Aug 27, 2019
1 parent e2a4fda commit 9d9c20d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
34 changes: 18 additions & 16 deletions processor/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func tuiSearch(app *tview.Application, textView *tview.TextView) {
searchSliceMutex.Unlock()

if strings.TrimSpace(searchTerm) == "" {
drawText(textView, "")
drawText(app, textView, "")
return
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func tuiSearch(app *tview.Application, textView *tview.TextView) {
for update {
// Every 100 ms redraw
if makeTimestampMilli()-reset >= 100 {
drawResults(results, textView, searchTerm, string(spinString[spinLoc]))
drawResults(app, results, textView, searchTerm, string(spinString[spinLoc]))
reset = makeTimestampMilli()
spinLoc++

Expand All @@ -88,10 +88,10 @@ func tuiSearch(app *tview.Application, textView *tview.TextView) {

update = false
StopProcessing = true
drawResults(results, textView, searchTerm, "")
drawResults(app, results, textView, searchTerm, "")
}

func drawResults(results []*FileJob, textView *tview.TextView, searchTerm string, inProgress string) {
func drawResults(app *tview.Application, results []*FileJob, textView *tview.TextView, searchTerm string, inProgress string) {
RankResults(results)
sort.Slice(results, func(i, j int) bool {
if results[i].Score == results[j].Score {
Expand Down Expand Up @@ -122,18 +122,20 @@ func drawResults(results []*FileJob, textView *tview.TextView, searchTerm string
resultText += rel + "\n\n"
}

drawText(textView, resultText)
drawText(app, textView, resultText)
}

func drawText(textView *tview.TextView, text string) {
textView.Clear()
_, err := fmt.Fprintf(textView, "%s", text)
func drawText(app *tview.Application, textView *tview.TextView, text string) {
app.QueueUpdateDraw(func() {
textView.Clear()
_, err := fmt.Fprintf(textView, "%s", text)

if err != nil {
return
}
if err != nil {
return
}

textView.ScrollToBeginning()
textView.ScrollToBeginning()
})
}

var searchSlice = []string{}
Expand All @@ -148,16 +150,16 @@ func ProcessTui() {
SetColumns(1).
SetBorders(false)

var drawMutex sync.Mutex
//var drawMutex sync.Mutex
textView := tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
ScrollToBeginning().
SetChangedFunc(func() {
drawMutex.Lock()
//drawMutex.Lock()
//app.QueueUpdateDraw(func() {})
app.Draw()
drawMutex.Unlock()
//app.Draw()
//drawMutex.Unlock()
})

inputField := tview.NewInputField().
Expand Down
6 changes: 0 additions & 6 deletions vendor/github.com/rivo/tview/textview.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d9c20d

Please sign in to comment.