summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/X11/Parsers.hs
diff options
context:
space:
mode:
authortulthix <tulthix@gmail.com>2021-11-02 19:31:18 -0500
committertulthix <tulthix@gmail.com>2021-11-02 19:35:31 -0500
commit9d21a7dd818ece5247e2f75f13d588111e334d8c (patch)
tree75e11000996f68454f42e545872760b8776968a3 /src/Xmobar/X11/Parsers.hs
parent8ca3cfced681ae6c069450cc6d0352910433d46b (diff)
downloadxmobar-9d21a7dd818ece5247e2f75f13d588111e334d8c.tar.gz
xmobar-9d21a7dd818ece5247e2f75f13d588111e334d8c.tar.bz2
hspace feature. Initial intent: make space for a tray
Diffstat (limited to 'src/Xmobar/X11/Parsers.hs')
-rw-r--r--src/Xmobar/X11/Parsers.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/Xmobar/X11/Parsers.hs b/src/Xmobar/X11/Parsers.hs
index d35cfa0..513f63b 100644
--- a/src/Xmobar/X11/Parsers.hs
+++ b/src/Xmobar/X11/Parsers.hs
@@ -28,11 +28,11 @@ import Text.Read (readMaybe)
import Graphics.X11.Types (Button)
import Foreign.C.Types (CInt)
-data Widget = Icon String | Text String
+data Widget = Icon String | Text String | Hspace Int32 deriving Show
-data BoxOffset = BoxOffset Align Int32 deriving Eq
+data BoxOffset = BoxOffset Align Int32 deriving (Eq, Show)
-- margins: Top, Right, Bottom, Left
-data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving Eq
+data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving (Eq, Show)
data BoxBorder = BBTop
| BBBottom
| BBVBoth
@@ -40,14 +40,14 @@ data BoxBorder = BBTop
| BBRight
| BBHBoth
| BBFull
- deriving ( Read, Eq )
-data Box = Box BoxBorder BoxOffset CInt String BoxMargins deriving Eq
+ deriving ( Read, Eq, Show )
+data Box = Box BoxBorder BoxOffset CInt String BoxMargins deriving (Eq, Show)
data TextRenderInfo =
TextRenderInfo { tColorsString :: String
, tBgTopOffset :: Int32
, tBgBottomOffset :: Int32
, tBoxes :: [Box]
- }
+ } deriving Show
type FontIndex = Int
-- | Runs the string parser
@@ -68,6 +68,7 @@ allParsers :: TextRenderInfo
-> Parser [(Widget, TextRenderInfo, FontIndex, Maybe [Action])]
allParsers c f a = textParser c f a
<|> try (iconParser c f a)
+ <|> try (hspaceParser c f a)
<|> try (rawParser c f a)
<|> try (actionParser c f a)
<|> try (fontParser c a)
@@ -91,6 +92,7 @@ textParser c f a = do s <- many1 $
try (string "action=") <|>
try (string "/action>") <|>
try (string "icon=") <|>
+ try (string "hspace=") <|>
try (string "raw=") <|>
try (string "/fn>") <|>
try (string "/box>") <|>
@@ -133,6 +135,13 @@ iconParser c f a = do
i <- manyTill (noneOf ">") (try (string "/>"))
return [(Icon i, c, f, a)]
+hspaceParser :: TextRenderInfo -> FontIndex -> Maybe [Action]
+ -> Parser [(Widget, TextRenderInfo, FontIndex, Maybe [Action])]
+hspaceParser c f a = do
+ string "<hspace="
+ pVal <- manyTill digit (try (string "/>"))
+ return [(Hspace (fromMaybe 0 $ readMaybe pVal), c, f, a)]
+
actionParser :: TextRenderInfo -> FontIndex -> Maybe [Action]
-> Parser [(Widget, TextRenderInfo, FontIndex, Maybe [Action])]
actionParser c f act = do