Add editor syntax highlighting

This commit is contained in:
Joscha 2018-10-24 17:30:12 +00:00
parent bac45278fe
commit b84f439c6c
2 changed files with 14 additions and 7 deletions

View file

@ -8,13 +8,14 @@ module TaskMachine.UI.TaskEdit
, updateTaskEdit
) where
import qualified Brick as B
import qualified Brick.Widgets.Edit as B
import qualified Data.Text.Zipper as T
import qualified Graphics.Vty as VTY
import qualified Brick as B
import qualified Brick.Widgets.Edit as B
import qualified Data.Text.Zipper as T
import qualified Graphics.Vty as VTY
import Text.Megaparsec
import TaskMachine.Task
import TaskMachine.UI.Task
data TaskEdit n = TaskEdit EditState (B.Editor String n)
deriving (Show)
@ -47,8 +48,14 @@ editedTask te = do
Left parseError -> Left $ parseErrorPretty parseError
Right task -> Right task
renderRow :: String -> B.Widget n
renderRow s =
case parse pTask "" s of
Left _ -> B.str s
Right task -> renderTask task
renderRows :: [String] -> B.Widget n
renderRows = B.vBox . map B.str
renderRows = B.vBox . map renderRow
renderTaskEdit :: (Ord n, Show n) => Bool -> TaskEdit n -> B.Widget n
renderTaskEdit focus (TaskEdit _ edit) = B.renderEditor renderRows focus edit

View file

@ -1,7 +1,7 @@
x2018-10-23 c2018-09-18 Clean up file (adding creation/completion dates)
- c2018-09-18 Purge - move completed tasks to a separate file
x2018-10-23 c2018-09-28 Move cursor to beginning of task description when editing tasks
- c2018-09-28 Syntax highlighting while editing tasks
x2018-10-24 c2018-09-28 Syntax highlighting while editing tasks
x2018-10-23 c2018-09-30 Display "-empty-" when TaskList is empty
x2018-09-27 c2018-09-18 Quit using Esc or q
x2018-09-29 c2018-09-28 Use B.EventM's MonadIO instance instead of B.suspendAndResume (facepalm)
@ -11,5 +11,5 @@ x2018-09-30 c2018-09-18 Offer "retry" or "quit" +dialogue - syntax error in todo
x2018-09-30 c2018-09-30 Custom exception messages
x2018-10-24 c2018-10-23 Don't crash on parse errors etc.
- c2018-10-24 Add "u" - undo and "z" - redo buttons
- c2018-10-24 Redo coloring - maybe black-on-white color scheme in-editor?
- c2018-10-24 Fix date coloring in editor
x2018-10-24 c2018-10-24 Reverse ordering of completed tasks - most recent at the top