From b84f439c6c6dc6fedeef97076591e2b2042c4041 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 24 Oct 2018 17:30:12 +0000 Subject: [PATCH] Add editor syntax highlighting --- src/TaskMachine/UI/TaskEdit.hs | 17 ++++++++++++----- todo.txt | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/TaskMachine/UI/TaskEdit.hs b/src/TaskMachine/UI/TaskEdit.hs index fcf018b..0ebea6b 100644 --- a/src/TaskMachine/UI/TaskEdit.hs +++ b/src/TaskMachine/UI/TaskEdit.hs @@ -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 diff --git a/todo.txt b/todo.txt index d6c6610..d30151a 100644 --- a/todo.txt +++ b/todo.txt @@ -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