Permalink
Browse files

Example xmobar.hs

  • Loading branch information...
jaor committed Dec 2, 2018
1 parent 6fc4f0c commit 2ff796f843bbd51e7cd0aa24b7b98251d263e487
Showing with 89 additions and 100 deletions.
  1. +0 −24 examples/Plugins/HelloWorld.hs
  2. +0 −12 examples/Plugins/helloworld.config
  3. +76 −0 examples/xmobar.hs
  4. +10 −61 readme.md
  5. +3 −3 xmobar.cabal

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,76 @@
------------------------------------------------------------------------------
-- |
-- Copyright: (c) 2018 Jose Antonio Ortega Ruiz
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: jao@gnu.org
-- Stability: unstable
-- Portability: portable
-- Created: Sat Nov 24, 2018 21:03
--
--
-- An example of a Haskell-based xmobar. Compile it with
-- ghc --make -- xmobar.hs
-- with the xmobar library installed or simply call:
-- xmobar /path/to/xmobar.hs
-- and xmobar will compile and launch it for you and
------------------------------------------------------------------------------


import Xmobar

-- Example user-defined plugin

data HelloWorld = HelloWorld
deriving (Read, Show)

instance Exec HelloWorld where
alias HelloWorld = "hw"
run HelloWorld = return "<fc=red>Hello World!!</fc>"

-- Configuration, using predefined monitors as well as our HelloWorld
-- plugin:

config = defaultConfig {
font = "xft:Sans Mono-9"
, additionalFonts = []
, borderColor = "black"
, border = TopB
, bgColor = "black"
, fgColor = "grey"
, alpha = 255
, position = Top
, textOffset = -1
, iconOffset = -1
, lowerOnStart = True
, pickBroadest = False
, persistent = False
, hideOnStart = False
, iconRoot = "."
, allDesktops = True
, overrideRedirect = True
, commands = [ Run $ Weather "EGPH" ["-t","<station>: <tempC>C",
"-L","18","-H","25",
"--normal","green",
"--high","red",
"--low","lightblue"] 36000
, Run $ Network "eth0" ["-L","0","-H","32",
"--normal","green","--high","red"] 10
, Run $ Network "eth1" ["-L","0","-H","32",
"--normal","green","--high","red"] 10
, Run $ Cpu ["-L","3","-H","50",
"--normal","green","--high","red"] 10
, Run $ Memory ["-t","Mem: <usedratio>%"] 10
, Run $ Swap [] 10
, Run $ Com "uname" ["-s","-r"] "" 36000
, Run $ Date "%a %b %_d %Y %H:%M:%S" "date" 10
, Run HelloWorld
]
, sepChar = "%"
, alignSep = "}{"
, template = "%cpu% | %memory% * %swap% | %eth0% - %eth1% }\
\ %hw% { <fc=#ee9a00>%date%</fc>| %EGPH% | %uname%"
}

main :: IO ()
main = xmobar config
@@ -1501,74 +1501,23 @@ This implementation is equivalent to the one you can read in
`alias` is the name to be used in the output template. Default alias
will be the data type constructor.
Implementing a plugin requires importing the plugin API (the `Exec`
class definition), that is exported by `Plugins.hs`. So you just need
to import it in your module with:
import Plugins
After that your type constructor can be used as an argument for the
Runnable type constructor `Run` in the `commands` list of the
configuration options.
This requires importing your plugin into `Config.hs` and adding your
type to the type list in the type signature of `Config.runnableTypes`.
For a very basic example see `examples/Plugins/HelloWorld.hs` or the
other plugins that are distributed with xmobar.
## Installing/Removing a Plugin
Installing a plugin should require 3 steps. Here we are going to
install the HelloWorld plugin that comes with xmobar, assuming that
you copied it to `src/Plugins`:
1. import the plugin module in `Config.hs`, by adding:
import Plugins.HelloWorld
2. add the plugin data type to the list of data types in the type
signature of `runnableTypes` in `Config.hs`. For instance, for the
HelloWorld plugin, change `runnableTypes` into:
runnableTypes :: Command :*: Monitors :*: HelloWorld :*: ()
runnableTypes = undefined
3. Rebuild and reinstall xmobar. Now test it with:
xmobar Plugins/helloworld.config
As you may see in the example configuration file, the plugin can be
used by adding, in the `commands` list:
Run HelloWorld
and, in the output template, the alias of the plugin:
%helloWorld%
That's it.
To remove a plugin, just remove its type from the type signature of
runnableTypes and remove the imported modules.
To remove the system monitor plugin:
1. remove, from `Config.hs`, the line
import Plugins.Monitors
2. in `Config.hs` change
runnableTypes :: Command :*: Monitors :*: ()
runnableTypes = undefined
## Using a Plugin
to
To use your new plugin, you need to use a pure Haskell configuration
for xmobar, and load your definitions there. You can see an example
in [examples/xmobar.hs] showing you how to write a Haskell
configuration that uses a new plugin, all in one file.
runnableTypes :: Command :*: ()
runnableTypes = undefined
When xmobar runs with the full path to that Haskell file as its
argument (or if you put it in `~/.config/xmobar/xmobar.hs`), and with
the xmobar library installed, the Haskell code will be compiled as
needed, and the new executable spawned for you.
3. rebuild xmobar.
That's it!
# Authors and credits
@@ -18,9 +18,9 @@ build-type: Simple

extra-source-files: readme.md, changelog.md,
examples/padding-icon.sh,
examples/xmobar.config, examples/xmonadpropwrite.hs
examples/Plugins/helloworld.config,
examples/Plugins/HelloWorld.hs
examples/xmobar.config,
examples/xmobar.hs,
examples/xmonadpropwrite.hs

source-repository head
type: git

0 comments on commit 2ff796f

Please sign in to comment.