summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/Plugins/HelloWorld.hs24
-rw-r--r--examples/Plugins/helloworld.config12
-rw-r--r--examples/xmobar.hs76
-rw-r--r--readme.md71
-rw-r--r--xmobar.cabal6
5 files changed, 89 insertions, 100 deletions
diff --git a/examples/Plugins/HelloWorld.hs b/examples/Plugins/HelloWorld.hs
deleted file mode 100644
index d2267ae..0000000
--- a/examples/Plugins/HelloWorld.hs
+++ /dev/null
@@ -1,24 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module : Plugins.HelloWorld
--- Copyright : (c) Andrea Rossato
--- License : BSD-style (see LICENSE)
---
--- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org>
--- Stability : unstable
--- Portability : unportable
---
--- A plugin example for Xmobar, a text based status bar
---
------------------------------------------------------------------------------
-
-module Xmobar.Plugins.HelloWorld where
-
-import Xmobar.Plugins
-
-data HelloWorld = HelloWorld
- deriving (Read, Show)
-
-instance Exec HelloWorld where
- alias HelloWorld = "helloWorld"
- run HelloWorld = return "<fc=red>Hello World!!</fc>"
diff --git a/examples/Plugins/helloworld.config b/examples/Plugins/helloworld.config
deleted file mode 100644
index 3818bfa..0000000
--- a/examples/Plugins/helloworld.config
+++ /dev/null
@@ -1,12 +0,0 @@
-Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
- , bgColor = "#000000"
- , fgColor = "#BFBFBF"
- , position = TopW C 90
- , commands = [ Run Cpu [] 10
- , Run Weather "LIPB" [] 36000
- , Run HelloWorld
- ]
- , sepChar = "%"
- , alignSep = "}{"
- , template = "%cpu% } %helloWorld% { %LIPB% | <fc=yellow>%date%</fc>"
- }
diff --git a/examples/xmobar.hs b/examples/xmobar.hs
new file mode 100644
index 0000000..1325ae7
--- /dev/null
+++ b/examples/xmobar.hs
@@ -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
diff --git a/readme.md b/readme.md
index 98dc345..d316acb 100644
--- a/readme.md
+++ b/readme.md
@@ -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
diff --git a/xmobar.cabal b/xmobar.cabal
index 1c75761..41fad30 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -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