diff --git a/editor.hs b/editor.hs index 9535b72..5ed96d6 100644 --- a/editor.hs +++ b/editor.hs @@ -1,4 +1,10 @@ import Brick +import Brick.Markup +import Data.Maybe +import Data.Monoid +import Data.List +import Data.Text (pack, singleton) +import Data.Text.Markup ((@@)) import qualified Brick.Widgets.Edit as E import qualified Graphics.Vty as V @@ -6,7 +12,18 @@ data Name = Text deriving (Ord, Show, Eq) type St = E.Editor Name initialState :: St -initialState = E.editor Text (str . unlines) Nothing "" +initialState = E.editor Text drawContent Nothing "" + +drawContent :: [String] -> Widget n +drawContent = markup . createMarkup . unlines + +createMarkup :: String -> Markup V.Attr +createMarkup [] = mempty +createMarkup s@('"':ss) = case i of + Just n -> (pack (take (2+n) s) @@ fg V.blue) <> (createMarkup (drop (1+n) ss)) + Nothing -> pack s @@ fg V.red + where i = elemIndex '"' ss +createMarkup (c:ss) = (singleton c @@ fg V.white) <> (createMarkup ss) drawUI :: St -> [Widget Name] drawUI st = [E.renderEditor True st]