public
Created

A library which can be used to define an .xmobarrc configuration as a haskell object (with all the benefits of defining things in haskell) and export it to a config file to be used by xmobar.

  • Download Gist
XMobarHs.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
module XMobarHs
( Config (..)
, Position (..)
, Align (..)
, Border (..)
, Command (..)
, Run (..)
, config
, export
) where
 
import Data.List
 
data Config = Config { font :: String
, bgColor :: String
, fgColor :: String
, position :: Position
, lowerOnStart :: Bool
, hideOnStart :: Bool
, persistent :: Bool
, border :: Border
, borderColor :: String
, commands :: [Run Command]
, sepChar :: String
, alignSep :: String
, template :: String
}
 
cfgPairs :: [(String, (Config -> String))]
cfgPairs = [ ("font" , show.font )
, ("bgColor" , show.bgColor )
, ("fgColor" , show.fgColor )
, ("position" , show.position )
, ("lowerOnStart" , show.lowerOnStart)
, ("hideOnStart" , show.hideOnStart )
, ("persistent" , show.persistent )
, ("border" , show.border )
, ("borderColor" , show.borderColor )
, ("commands" , show.commands )
, ("sepChar" , show.sepChar )
, ("alignSep" , show.alignSep )
, ("template" , show.template )
]
 
config :: Config
config = Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
, bgColor = "#000000"
, fgColor = "#BFBFBF"
, position = Top
, lowerOnStart = True
, hideOnStart = False
, persistent = False
, border = NoBorder
, borderColor = "#BFBFBF"
, commands = [ Run $ Date "%a %b %_d %Y * %H:%M:%S" "theDate" 10, Run StdinReader]
, sepChar = "%"
, alignSep = "}{"
, template = "%StdinReader% }{ <fc=#00FF00>%uname%</fc> * <fc=#FF0000>%theDate%</fc>"
}
 
-- Must be rewritten, to remove unnecessary defaults
instance Show Config where
showsPrec _ n s = "Config {" ++ e n ++ "}" ++ s
where e x = intercalate ", " [g (fst y) | y <- f x, uncurry (/=) y]
f x = zip (h x) (h config)
g x = fst x ++ " = " ++ snd x
h x = map (\y -> (fst y, snd y x)) cfgPairs
 
data Position = Top | TopW Align Int | TopSize Align Int Int
| Bottom | BottomW Align Int | BottomSize Align Int Int
| Static { xpos :: Int, ypos :: Int
, width :: Int, height :: Int
} deriving Show
 
data Align = L | C | R deriving Show
 
data Border = TopB | TopBM Int
| BottomB | BottomBM Int
| FullB | FullBM Int
| NoBorder deriving Show
 
data Command = Uptime [String] Int
| Weather String [String] Int
| Network String [String] Int
| DynNetwork [String] Int
| Wireless String [String] Int
| Memory [String] Int
| Swap [String] Int
| Cpu [String] Int
| MultiCpu [String] Int
| Battery [String] Int
| BatteryP [String] [String] Int
| TopProc [String] Int
| TopMem [String] Int
| DiskU [(String, String)] [String] Int
| DiskIO [(String, String)] [String] Int
| ThermalZone Int [String] Int
| Thermal String [String] Int
| CpuFreq [String] Int
| CoreTemp [String] Int
| Volume String String [String] Int
| MPD [String] Int
| Mpris1 String [String] Int
| Mpris2 String [String] Int
| Mail [(String, String)] String
| Mbox [(String, String, String)] [String] String
| XPropertyLog String
| NamedXPropertyLog String String
| Brightness [String] Int
| Kbd [(String, String)]
| Locks
| Com String [String] String Int
| StdinReader
| Date String String Int
| DateZone String String String String Int
| CommandReader String String
| PipeReader String String
| BufferedPipeReader String [(Int, Bool, String)]
| XMonadLog
deriving Show
 
data Run a = Run a
 
-- Must be rewritten, as derived version inserts parens
instance Show a => Show (Run a) where
showsPrec _ (Run x) s = "Run " ++ show x ++ s
 
-- Example of use:
-- main = export $ config { ... }
-- remember to put a "$" after every "Run"
-- otherwise, configure it the same as you would a normal .xmobarrc
export :: Config -> IO ()
export = writeFile ".xmobarrc".show

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.