summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Config/Parse.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-09-16 17:00:07 +0100
committerjao <jao@gnu.org>2022-09-16 17:00:52 +0100
commit98438363998a992ded2318d51a614c616a365f6d (patch)
tree3bdb826e156c63a4299bbadfb87fcb9c030850b8 /src/Xmobar/Config/Parse.hs
parent684fee419fb6ee35efd28c196b0c520d800fffa9 (diff)
downloadxmobar-98438363998a992ded2318d51a614c616a365f6d.tar.gz
xmobar-98438363998a992ded2318d51a614c616a365f6d.tar.bz2
little clean-ups
Diffstat (limited to 'src/Xmobar/Config/Parse.hs')
-rw-r--r--src/Xmobar/Config/Parse.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/Xmobar/Config/Parse.hs b/src/Xmobar/Config/Parse.hs
index 41088e9..16af3db 100644
--- a/src/Xmobar/Config/Parse.hs
+++ b/src/Xmobar/Config/Parse.hs
@@ -16,7 +16,10 @@
------------------------------------------------------------------------------
-module Xmobar.Config.Parse(readConfig, parseConfig) where
+module Xmobar.Config.Parse(readConfig
+ , parseConfig
+ , indexedFont
+ , indexedOffset) where
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Number (int)
@@ -174,3 +177,17 @@ commandsErr = "commands: this usually means that a command could not" ++
readConfig :: Config -> FilePath -> IO (Either ParseError (Config,[String]))
readConfig defaultConfig f =
liftIO (S.readFile f) <&> parseConfig defaultConfig
+
+-- | Extracts from a configuration the additional font at the corresponding index.
+-- Returns the default font if not present.
+indexedFont :: Config -> FontIndex -> String
+indexedFont config idx =
+ if idx < 1 || idx > length (additionalFonts config)
+ then font config else additionalFonts config !! (idx - 1)
+
+-- | Extracts from a configuration the offset at the corresponding index.
+-- Returns the default offset if not present.
+indexedOffset :: Config -> FontIndex -> Int
+indexedOffset config idx =
+ if idx < 1 || idx > length (textOffsets config)
+ then textOffset config else textOffsets config !! (idx - 1)