Implement basic UI

This commit is contained in:
Joscha 2020-02-29 21:55:01 +00:00
parent c32d5faefc
commit fd10a59b86
6 changed files with 160 additions and 41 deletions

35
src/Profold/LineNode.hs Normal file
View file

@ -0,0 +1,35 @@
module Profold.LineNode
( LineNode(..)
, newLineNode
, Path
, flatten
, modify
) where
import qualified Data.Text as T
import qualified Data.Vector as V
import Profold.Util
data LineNode = LineNode
{ lineText :: T.Text
, lineChildren :: V.Vector LineNode
, lineFolded :: Bool
} deriving (Show)
newLineNode :: T.Text -> [LineNode] -> LineNode
newLineNode text children = LineNode text (V.fromList children) True
type Path = [Int]
flatten :: LineNode -> V.Vector (Path, LineNode)
flatten ln
| lineFolded ln = V.singleton ([], ln)
| otherwise =
V.cons ([], ln) $
V.imap (\i (is, n) -> (i : is, n)) $ V.concatMap flatten $ lineChildren ln
modify :: (LineNode -> LineNode) -> Path -> LineNode -> LineNode
modify f [] ln = f ln
modify f (i:is) ln =
ln {lineChildren = modifyAtIndex i (modify f is) $ lineChildren ln}