From cc5ae3f61b598fc9b660e604b38dec837cdd46cc Mon Sep 17 00:00:00 2001 From: damianfral Date: Sat, 7 Oct 2023 14:59:32 +0000 Subject: [PATCH] Clean eventHandler. --- src/CLI.hs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/CLI.hs b/src/CLI.hs index 8f01a47..db1be0d 100644 --- a/src/CLI.hs +++ b/src/CLI.hs @@ -158,16 +158,26 @@ eventHandler (VtyEvent evt) = case evt of V.EvKey (KChar 'q') _ -> halt V.EvKey (KChar 'J') _ -> modify movePrev V.EvKey (KChar 'K') _ -> modify moveNext - V.EvKey (KChar 'j') _ -> - gets current >>= \Entry {..} -> vScrollBy (viewportScroll $ Content entryDay) 1 - V.EvKey (KChar 'k') _ -> - gets current >>= \Entry {..} -> vScrollBy (viewportScroll $ Content entryDay) (-1) - V.EvKey (KChar 'e') _ -> - gets current >>= \Entry {..} -> - suspendAndResume' $ callProcess "$EDITOR" [entryFile] + V.EvKey (KChar 'j') _ -> increaseScrollContent + V.EvKey (KChar 'k') _ -> decreaseScrollContent + V.EvKey (KChar 'e') _ -> editContent _ -> pure () eventHandler _ = pure () +increaseScrollContent = do + Entry {..} <- gets current + let resource = Content entryDay + vScrollBy (viewportScroll resource) 1 + +decreaseScrollContent = do + Entry {..} <- gets current + let resource = Content entryDay + vScrollBy (viewportScroll resource) (-1) + +editContent = do + Entry {..} <- gets current + suspendAndResume' $ callProcess "hx" [entryFile] + isMarkdownFile :: FilePath -> Bool isMarkdownFile file = takeExtension file == ".md"