From c05517582ea253a8a1b662269c4e2ede6d69f197 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 25 Feb 2017 21:54:08 -0700 Subject: factor out updateStateOutsideSession --- Main.hs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Main.hs b/Main.hs index 9688cc9..c0a7ad8 100644 --- a/Main.hs +++ b/Main.hs @@ -82,23 +82,20 @@ handleESC st = undefined handleHotKey :: St -> Char -> EventM () (Next St) handleHotKey st 'q' = handleQ st handleHotKey st ' ' = handleSPC st -handleHotKey st 'o' = continue $ - if isJust $ st^.stScanningSession - then st - else st & stOCR .~ (not $ st^.stOCR) -handleHotKey st 'c' = continue $ - if isJust $ st^.stScanningSession - then st - else st & stColour .~ (cycleColour $ st^.stColour) -handleHotKey st 'p' = continue $ - if isJust $ st^.stScanningSession - then st - else st & stPaper .~ (cyclePaper $ st^.stPaper) -handleHotKey st c = continue $ if isJust $ st^.stScanningSession - then st - else case lookupPreset c of - Just (Preset _ _ f) -> f st - _ -> st +handleHotKey st 'o' = updateStateOutsideSession st + (\s -> s & stOCR .~ (not $ st^.stOCR)) +handleHotKey st 'c' = updateStateOutsideSession st + (\s -> s & stColour .~ (cycleColour $ st^.stColour)) +handleHotKey st 'p' = updateStateOutsideSession st + (\s -> s & stPaper .~ (cyclePaper $ st^.stPaper)) +handleHotKey st c = updateStateOutsideSession st $ + case lookupPreset c of + Just (Preset _ _ f) -> f + _ -> id + +updateStateOutsideSession :: St -> (St -> St) -> EventM () (Next St) +updateStateOutsideSession st f = continue $ + if isJust $ st^.stScanningSession then st else f st appEvent :: St -> BrickEvent () e -> EventM () (Next St) appEvent st (VtyEvent e) = -- cgit v1.2.3