diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2017-02-25 21:56:51 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2017-02-25 22:00:12 -0700 |
commit | 423247140f7248410bfd5d469f30ab15200aafe6 (patch) | |
tree | 5156ee75a0157a7b2f86655d07782bd2a7090e52 | |
parent | c05517582ea253a8a1b662269c4e2ede6d69f197 (diff) | |
download | sscan-423247140f7248410bfd5d469f30ab15200aafe6.tar.gz |
factor out ifScanSess
-rw-r--r-- | Main.hs | 24 | ||||
-rw-r--r-- | Types/State.hs | 7 |
2 files changed, 17 insertions, 14 deletions
@@ -19,7 +19,6 @@ import Brick.Widgets.Core import Data.Text.Markup ((@@)) import Brick.Widgets.DefnList -import Data.Maybe (isJust) import Presets import Types.Preset import Types.State @@ -51,16 +50,16 @@ drawUI st = [ui] actionsBox = defnList AlignLeft (Just $ V.withStyle V.currentAttr V.bold) $ (if st^.stOutFormat == PDF - then (if isJust $ st^.stScanningSession - then [ ("SPC", "scan next page") - , ("RET", "scan final page") - , ("q", "declare last scanned page was the final page") - , ("ESC", "abort/restart scanning this document") - ] - else [ ("SPC", "scan first page of multi-page document") - , ("RET", "scan single page document") - , ("q", "quit sscan") - ] + then (ifScanSess st + [ ("SPC", "scan next page") + , ("RET", "scan final page") + , ("q", "declare last scanned page was the final page") + , ("ESC", "abort/restart scanning this document") + ] + [ ("SPC", "scan first page of multi-page document") + , ("RET", "scan single page document") + , ("q", "quit sscan") + ] ) else [ ("SPC", "scan page") , ("q", "quit sscan") @@ -94,8 +93,7 @@ handleHotKey st c = updateStateOutsideSession st $ _ -> id updateStateOutsideSession :: St -> (St -> St) -> EventM () (Next St) -updateStateOutsideSession st f = continue $ - if isJust $ st^.stScanningSession then st else f st +updateStateOutsideSession st f = continue $ ifScanSess st st (f st) appEvent :: St -> BrickEvent () e -> EventM () (Next St) appEvent st (VtyEvent e) = diff --git a/Types/State.hs b/Types/State.hs index c3f1ecf..befba24 100644 --- a/Types/State.hs +++ b/Types/State.hs @@ -2,7 +2,9 @@ module Types.State where -import Lens.Micro.TH (makeLenses) +import Data.Maybe +import Lens.Micro ((^.)) +import Lens.Micro.TH (makeLenses) -- | Whether to do colour, grey or b&w scans data Colour = Lineart | Greyscale | Colour @@ -48,3 +50,6 @@ data St = -- other device-specific scanimage options we could support: --swdespeck; --color-filter; --depth makeLenses ''St + +ifScanSess :: St -> a -> a -> a +ifScanSess st a b = if isJust $ st^.stScanningSession then a else b |