aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-02-25 21:54:08 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-02-25 21:54:08 -0700
commitc05517582ea253a8a1b662269c4e2ede6d69f197 (patch)
treefca6365defbca89de60421c988c58388e9ee6928
parent7f017a7d50b944426d1bbc59036a840d5c087997 (diff)
downloadsscan-c05517582ea253a8a1b662269c4e2ede6d69f197.tar.gz
factor out updateStateOutsideSession
-rw-r--r--Main.hs31
1 files 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) =