Skip to content

Commit

Permalink
improves code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerojas26 committed Sep 4, 2024
1 parent 9c69379 commit b75994e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/Tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,20 @@ func NewTree(dbName string, dbdriver drivers.Driver) *Tree {
tree.SetFocusFunc(nil)
})

selectedNodeTextColor := fmt.Sprintf("[black:%s]", tview.Styles.SecondaryTextColor.Name())
previouslyFocusedNode := tree.GetCurrentNode()
previouslyFocusedNode.SetText(fmt.Sprintf("[black:%s]%s", tview.Styles.SecondaryTextColor.Name(), previouslyFocusedNode.GetText()))
previouslyFocusedNode.SetText(selectedNodeTextColor + previouslyFocusedNode.GetText())

tree.SetChangedFunc(func(node *tview.TreeNode) {
// Set colors on focused node
nodeText := node.GetText()
node.SetText(fmt.Sprintf("[black:%s]%s", tview.Styles.SecondaryTextColor.Name(), nodeText))
if !strings.Contains(nodeText, selectedNodeTextColor) {
node.SetText(selectedNodeTextColor + nodeText)
}

// Remove colors on previously focused node
previousNodeText := previouslyFocusedNode.GetText()
splittedNodeText := strings.Split(previousNodeText, "]")
splittedNodeText := strings.Split(previousNodeText, selectedNodeTextColor)
if len(splittedNodeText) > 1 {
previouslyFocusedNode.SetText(splittedNodeText[1])
}
Expand Down

0 comments on commit b75994e

Please sign in to comment.