Skip to content

Commit

Permalink
modified to fix the issues
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jun 22, 2020
1 parent 977ce08 commit 8a01212
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions asset/tui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ func main() {
case tcell.KeyTab:
//app.SetFocus(textView) need to change focus to the others but not the text itself
case tcell.KeyUp:
drawResultsSync.Lock()
if selected != 0 {
selected--
}
drawResults(displayResults, codeResults, selected, resultsFlex, app)

drawResultsChanged = true
drawResultsSync.Unlock()
case tcell.KeyDown:
drawResultsSync.Lock()
if selected != len(codeResults)-1 {
selected++
}

drawResults(displayResults, codeResults, selected, resultsFlex, app)
drawResultsChanged = true
drawResultsSync.Unlock()
}
})

Expand Down Expand Up @@ -122,10 +124,11 @@ func main() {
})
}

// render loop
go func() {
for {
drawResults(displayResults, codeResults, selected, resultsFlex, app)
time.Sleep(1 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
}
}()

Expand All @@ -134,13 +137,18 @@ func main() {
}
}


// below needs to go into a struct
var drawResultsCount int
var drawResultsSync sync.Mutex
var drawResultsChanged bool

// This is responsible for drawing all changes on the screen
func drawResults(displayResults []DisplayResult, codeResults []Result, selected int, resultsFlex *tview.Flex, app *tview.Application) {
drawResultsSync.Lock()
defer drawResultsSync.Unlock()
if !drawResultsChanged {
return
}
drawResultsCount++

// reset the elements by clearing out every one
Expand All @@ -167,5 +175,6 @@ func drawResults(displayResults []DisplayResult, codeResults []Result, selected
resultsFlex.ResizeItem(displayResults[i].Body, len(strings.Split(t.Content, "\n")), 0)
}
})
drawResultsSync.Unlock()

drawResultsChanged = false
}

0 comments on commit 8a01212

Please sign in to comment.