[client] Grey out tree lines

This commit is contained in:
Joscha 2020-02-24 00:20:37 +00:00
parent 6359555db6
commit 901a1c4bce
2 changed files with 12 additions and 5 deletions

View file

@ -124,9 +124,10 @@ clientHandleEvent cs _ = continue cs
clientAttrMap :: AttrMap
clientAttrMap = attrMap Vty.defAttr
[ ("expand", Vty.currentAttr `Vty.withStyle` Vty.bold `Vty.withForeColor` Vty.yellow)
, ("focus", Vty.currentAttr `Vty.withBackColor` Vty.blue)
, ("flags", Vty.currentAttr `Vty.withForeColor` Vty.brightBlack)
[ ("expand", Vty.defAttr `Vty.withStyle` Vty.bold `Vty.withForeColor` Vty.yellow)
, ("focus", Vty.defAttr `Vty.withBackColor` Vty.blue)
, ("flags", Vty.defAttr `Vty.withForeColor` Vty.brightBlack)
, (treeLineAttr, Vty.defAttr `Vty.withForeColor` Vty.brightBlack)
]
clientApp :: App ClientState Event ResourceName

View file

@ -3,6 +3,7 @@
module Forest.Client.WidgetTree
( WidgetTree(..)
, renderWidgetTree
, treeLineAttr
, IndentOptions(..)
, boxDrawingBranching
, boxDrawingLine
@ -15,6 +16,7 @@ import Brick.BorderMap
import Control.Monad.Trans.Reader
import qualified Data.Text as T
import qualified Graphics.Vty as Vty
import Lens.Micro
data WidgetTree n = WidgetTree (Widget n) [WidgetTree n]
@ -50,9 +52,10 @@ indentWith firstLine otherLines wrapped = Widget
renderWidget = do
context <- ask
result <- render $ hLimit (availWidth context - maxWidth) wrapped
let resultHeight = Vty.imageHeight $ image result
let attribute = attrMapLookup treeLineAttr $ context ^. ctxAttrMapL
resultHeight = Vty.imageHeight $ image result
textLines = firstLine : replicate (resultHeight - 1) otherLines
leftImage = Vty.vertCat $ map (Vty.text' Vty.defAttr) textLines
leftImage = Vty.vertCat $ map (Vty.text' attribute) textLines
newImage = leftImage Vty.<|> image result
newResult = offsetResult (Location (maxWidth, 0)) $ result{image=newImage}
pure newResult
@ -68,6 +71,9 @@ renderWidgetTree :: IndentOptions -> WidgetTree n -> Widget n
renderWidgetTree opts (WidgetTree node children) =
node <=> indent opts (map (renderWidgetTree opts) children)
treeLineAttr :: AttrName
treeLineAttr = "treeLine"
-- | These options control how a tree is rendered. For more information on how
-- the various options are used, try rendering a tree with 'boxDrawingBranhing'
-- and inspect the results.