aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-02-25 21:20:19 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-02-25 21:33:39 -0700
commit0f443804011224eace10058d8c1672d3623a3b8f (patch)
treee37ef08c2fe913df594bc801d85b8a078ebc44ce
parent0876ced7760c8866f1b90b1bbaff9bdd19a7a7d8 (diff)
downloadsscan-0f443804011224eace10058d8c1672d3623a3b8f.tar.gz
improve defnList & factor out of Main.hs
-rw-r--r--Brick/Widgets/DefnList.hs37
-rw-r--r--Main.hs11
-rw-r--r--Types/Preset.hs2
3 files changed, 34 insertions, 16 deletions
diff --git a/Brick/Widgets/DefnList.hs b/Brick/Widgets/DefnList.hs
index 5750cdc..090428f 100644
--- a/Brick/Widgets/DefnList.hs
+++ b/Brick/Widgets/DefnList.hs
@@ -1,13 +1,34 @@
-module Brick.Widgets.DefnList (defnList) where
+{-# LANGUAGE OverloadedStrings #-}
+module Brick.Widgets.DefnList (defnList, Align(..)) where
+
+import Data.Monoid
+import qualified Data.Text as T
+import qualified Graphics.Vty as V
+
+import Brick.Markup (markup)
import Brick.Types
import Brick.Widgets.Core
+import Data.Text.Markup ((@@))
+
+data Align = AlignLeft | AlignRight
+ deriving (Eq)
-defnList :: [(String, String)] -> Widget ()
-defnList defns = vBox $ line <$> defns
+defnList :: Align -> Maybe V.Attr -> [(String, String)] -> Widget ()
+defnList align attr defns = vBox $ line <$> defns
where
- line (label, content) = str $
- label ++ sep ++ (gap label content) ++ content
- gap a b = take (maxWidth - length a - length b - length sep) $ repeat ' '
- maxWidth = maximum $ map (\(x,y) -> length sep + length x + length y) defns
- sep = ": "
+ line (label, content) = markup $
+ (T.pack label @@ labelAttr) <> (T.pack sep @@ V.defAttr)
+ <> (if align == AlignRight
+ then (T.pack (gap label content) @@ V.defAttr)
+ else mempty
+ )
+ <> (T.pack content @@ V.defAttr)
+
+ gap a b = take (maxWidth - length a - length b - length sep) $
+ repeat ' '
+ maxWidth = maximum $
+ map (\(x,y) -> length sep + length x + length y) defns
+ sep = if align == AlignRight then ": " else ": "
+
+ labelAttr = maybe V.defAttr id attr
diff --git a/Main.hs b/Main.hs
index 2acb0ff..ad0656d 100644
--- a/Main.hs
+++ b/Main.hs
@@ -36,7 +36,7 @@ drawUI st = [ui]
, padAll 1 $ C.center $ actionsBox
]
status = str "Ready to scan first page"
- settingsBox = defnList
+ settingsBox = defnList AlignRight Nothing
[ ("run OCRmyPDF", if st^.stOCR then "yes" else "no")
, ("colour data", show $ st^.stColour)
, ("page size", show $ st^.stPaper)
@@ -44,12 +44,9 @@ drawUI st = [ui]
, ("output format", show $ st^.stOutFormat)
, ("output dir", st^.stOutdir)
]
- presetsBox = vBox $
- (\(Preset k desc _) ->
- markup $
- (((T.pack [k]) <> ": ") @@ (V.withStyle V.currentAttr V.bold))
- <> (desc @@ fg V.white))
- <$> presets
+ presetsBox = defnList AlignLeft
+ (Just $ V.withStyle V.currentAttr V.bold)
+ (map (\(Preset k desc _) -> ([k], desc)) presets)
actionsBox = str "actions"
handleHotKey :: St -> Char -> EventM () (Next St)
diff --git a/Types/Preset.hs b/Types/Preset.hs
index 78f0231..84b4394 100644
--- a/Types/Preset.hs
+++ b/Types/Preset.hs
@@ -5,7 +5,7 @@ import qualified Data.Text as T
import Types.State
type PresetToggleKey = Char
-type PresetDesc = T.Text
+type PresetDesc = String
type PresetPreset = St -> St
data Preset = Preset PresetToggleKey PresetDesc PresetPreset