diff --git a/src/App/Fontifier.hs b/src/App/Fontifier.hs new file mode 100644 index 0000000..aa64563 --- /dev/null +++ b/src/App/Fontifier.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE TemplateHaskell #-} -- needed for lenses + +module Fontifier (fontMap, fontify) where + +{---- Imports ----} + +---- Brick, for markup specifications ---- +import Brick.AttrMap (AttrMap, attrMap, attrName) +import Brick.Util (bg, fg) +import qualified Graphics.Vty as Vty + +---- Various ---- +import Lens.Micro +import Lens.Micro.TH (makeLenses) + + +{---- Type Definitions ----} +-- defines an attribute for a text slice +data Fontification = FT { _ftStart :: Integer -- start index in string + , _ftEnd :: Integer -- end index in string + , _ftAttr :: String -- attribute name + } +makeLenses ''Fontification + +{---- Functions ----} + +fontMap :: AttrMap +fontMap = attrMap Vty.defAttr + [ + (attrName "assignment" , fg Vty.blue), + (attrName "return" , fg Vty.green), + (attrName "guard" , fg Vty.yellow), + (attrName "err_braces" , fg Vty.red), -- unbalanced braces + (attrName "err_string" , fg Vty.red) -- unterminated strings + ] + +-- calls the fontification functions +-- and returns a list of attributes for text slices +fontify :: String -> [Fontification] +fontify s = [] diff --git a/src/App/Gui.hs b/src/App/Gui.hs index 9093603..4e7bc43 100644 --- a/src/App/Gui.hs +++ b/src/App/Gui.hs @@ -1,5 +1,4 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TemplateHaskell #-} -- needed for lenses module Gui (runEditor) where @@ -22,6 +21,9 @@ import Data.Text.Markup (Markup, (@@)) import System.IO (IOMode (..), hClose, hGetContents, openFile) +---- Markup ---- +import qualified Fontifier as Fontifier + ---- Various ---- import Control.Monad.IO.Class (liftIO) import Data.List @@ -45,7 +47,6 @@ makeLenses ''HeditState - {---- Functions ----} runEditor :: FilePath -> IO () @@ -73,7 +74,7 @@ theApp = App { appDraw = drawUI , appChooseCursor = showFirstCursor , appHandleEvent = appEvent , appStartEvent = return - , appAttrMap = const (attrMap Vty.defAttr [ ]) + , appAttrMap = const $ Fontifier.fontMap , appLiftVtyEvent = id } @@ -109,14 +110,14 @@ appEvent st ev --- TODO Refactor parts into SyntaxChecker.hs somehow --- Rough idea: --- 1) make some monad that carries kind of markup-info --- state from one checker function to the next --- 2) call checker functions in editor --- 3) get (combined) markup-info from checkers --- 4) apply markup-info in editor function - +-- TODO Refactor +-- 1) Forget the monad thing that used to stand here, no need to +-- introduce state +-- 2) Rough idea: +-- -> call Fontifier.fontify (public interface to whatever +-- the fontification functions do) +-- -> get list of attributes for text slices +-- -> apply attributes to text in editor gui brackets :: [(Char,Char)] brackets = [('(',')'),('[',']'),('{','}')]