aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-02-25 14:51:38 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-02-25 14:51:38 -0700
commit3ced073c900ae0389771b438da3d0584a6dfec63 (patch)
treece62f7d1d67e041c61c1cc4e4a87fea224846bb4
parent1a48af859360e388c829f78ace708d32131d0a9b (diff)
downloadsscan-3ced073c900ae0389771b438da3d0584a6dfec63.tar.gz
types for presets
-rw-r--r--Main.hs62
-rw-r--r--Presets.hs28
-rw-r--r--Types/Preset.hs11
-rw-r--r--Types/State.hs (renamed from Types.hs)3
-rw-r--r--sscan.cabal1
5 files changed, 74 insertions, 31 deletions
diff --git a/Main.hs b/Main.hs
index 32d7616..4ab6c93 100644
--- a/Main.hs
+++ b/Main.hs
@@ -4,6 +4,7 @@ import Control.Monad (void)
import Data.Monoid
import qualified Graphics.Vty as V
import Lens.Micro ((&), (.~), (^.))
+import qualified Data.Text as T
import Brick.AttrMap
import Brick.Main
@@ -15,7 +16,9 @@ import Brick.Widgets.Center as C
import Brick.Widgets.Core
import Data.Text.Markup ((@@))
-import Types
+import Presets
+import Types.State
+import Types.Preset
drawUI :: St -> [Widget ()]
drawUI st = [ui]
@@ -23,43 +26,42 @@ drawUI st = [ui]
ui = vBox [ hBorderWithLabel (str "[ Status ]")
, C.center $ status
, hBorderWithLabel (str "[ Current settings ]")
- , padAll 1 $ C.center $ settings
+ , padAll 1 $ C.center $ settingsBox
, hBorderWithLabel (str "[ Presets ]")
- , padAll 1 $ C.center $ presets
+ , padAll 1 $ C.center $ presetsBox
, hBorderWithLabel (str "[ Actions ]")
- , padAll 1 $ C.center $ actions
+ , padAll 1 $ C.center $ actionsBox
]
status = str "Ready to scan first page"
- settings = vBox [ str $ "run OCRmyPDF: " ++ if st^.stOCR then "yes" else "no"
- , str $ "colour data: " ++ (show $ st^.stColour)
- , str $ "page size: " ++ (show $ st^.stPaper)
- , str $ "DPI: " ++ (show $ st^.stDPI)
- ]
- presets = vBox [ markup $ ("h:" @@ (V.withStyle V.currentAttr V.bold))
- <> (" handwritten notes" @@ fg V.white)
- ]
- actions = str "actions"
+ settingsBox = vBox [ str $ "run OCRmyPDF: "
+ <> if st^.stOCR then "yes" else "no"
+ , str $ "colour data: " ++ (show $ st^.stColour)
+ , str $ "page size: " ++ (show $ st^.stPaper)
+ , str $ "DPI: " ++ (show $ st^.stDPI)
+ ]
+ presetsBox = vBox $
+ (\(Preset k desc _) ->
+ markup $
+ (((T.pack [k]) <> ": ") @@ (V.withStyle V.currentAttr V.bold))
+ <> (desc @@ fg V.white))
+ <$> presets
+ actionsBox = str "actions"
+
+handleHotKey :: St -> Char -> EventM () (Next St)
+handleHotKey st 'q' = halt st
+handleHotKey st 'o' = continue $ st & stOCR .~ (not $ st^.stOCR)
+handleHotKey st 'c' = continue $
+ st & stColour .~ (cycleColour $ st^.stColour)
+handleHotKey st 'p' = continue $
+ st & stPaper .~ (cyclePaper $ st^.stPaper)
+handleHotKey st c = case lookupPreset c of
+ Just (Preset _ _ f) -> continue $ f st
+ _ -> continue st
appEvent :: St -> BrickEvent () e -> EventM () (Next St)
appEvent st (VtyEvent e) =
case e of
- -- settings toggles
- V.EvKey (V.KChar 'o') [] -> continue $ st & stOCR .~ (not $ st^.stOCR)
- V.EvKey (V.KChar 'c') [] -> continue $
- st & stColour .~ (cycleColour $ st^.stColour)
- V.EvKey (V.KChar 'p') [] -> continue $
- st & stPaper .~ (cyclePaper $ st^.stPaper)
-
- -- presets: set several settings toggles at once
- V.EvKey (V.KChar 'h') [] -> continue $ st
- { _stOCR = False
- , _stColour = Greyscale
- , _stDPI = 75
- }
-
- -- actions
- V.EvKey (V.KChar 'q') [] -> halt st
-
+ V.EvKey (V.KChar c) [] -> handleHotKey st c
_ -> continue st
appEvent st _ = continue st
diff --git a/Presets.hs b/Presets.hs
new file mode 100644
index 0000000..a783eb8
--- /dev/null
+++ b/Presets.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Presets (presets, lookupPreset) where
+
+import Data.List (find)
+
+import Types.Preset
+import Types.State
+
+presets :: [Preset]
+presets = [ Preset 'h' "handwritten notes" handwrittenNotes
+ , Preset 't' "typewritten docs" typewrittenDocs
+ ]
+
+lookupPreset :: Char -> Maybe Preset
+lookupPreset c = find (\(Preset k _ _) -> c == k) presets
+
+handwrittenNotes = \st -> st
+ { _stOCR = False
+ , _stColour = Greyscale
+ , _stDPI = 75
+ }
+
+typewrittenDocs = \st -> st
+ { _stOCR = True
+ , _stColour = Greyscale
+ , _stDPI = 300
+ }
diff --git a/Types/Preset.hs b/Types/Preset.hs
new file mode 100644
index 0000000..78f0231
--- /dev/null
+++ b/Types/Preset.hs
@@ -0,0 +1,11 @@
+module Types.Preset where
+
+import qualified Data.Text as T
+
+import Types.State
+
+type PresetToggleKey = Char
+type PresetDesc = T.Text
+type PresetPreset = St -> St
+
+data Preset = Preset PresetToggleKey PresetDesc PresetPreset
diff --git a/Types.hs b/Types/State.hs
index 721b00d..139310d 100644
--- a/Types.hs
+++ b/Types/State.hs
@@ -1,6 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
-module Types where
+module Types.State where
import Lens.Micro.TH (makeLenses)
@@ -27,6 +27,7 @@ cyclePaper Auto = A4
-- | DPI to scan
type DPI = Int
+-- | Application state
data St =
St { _stScanningSession :: Maybe FilePath -- ^ if a session is in
-- progress, accmulate
diff --git a/sscan.cabal b/sscan.cabal
index f57c059..1a29574 100644
--- a/sscan.cabal
+++ b/sscan.cabal
@@ -21,6 +21,7 @@ executable sscan
, brick >=0.17 && <0.18
, microlens >= 0.4.7.0
, microlens-th >= 0.4.1.1
+ , text >= 1.2.2.1
, vty >= 5.15
-- hs-source-dirs:
default-language: Haskell2010