jaor/xmobar — pull request #192 by projedi (2014-09-14 09:49:33+00:00)
Title: "Dynamic Strings"

This adds an ability to use icons instead of vertical bars for things like battery charge, volume, wi-fi strength, ...

#### In terms of user config:
A number of monitors (those that already use vbars in fact) have new custom options and template variables for "dynamic strings". For example, icon `on_5.xpm` will be displayed when battery is charging and its current charge is 5 out of 0..8 range (the same value that is used when deciding what character to use for ``):

```haskell
Run Battery
[ "--template", ""
, "--"
, "--on-dynamic-string", ""
, "--off-dynamic-string", ""
, "--idle-dynamic-string", ""
] 30
```

#### In terms of code:
* In `Plugins.Monitors.Common` there is a new type synonym `type DynamicString = Int -> String` and a default parser `parseDynamicString` that given a `str` and an `i` replaces all `"%%"` in `str` with `show i` such that `"%%%"` produces `\i -> show i ++ "%"`. And also functions that mirror `bar` and `vbar` api: `showDynamicString` and `showLogDynamicString` that take a `Maybe DynamicString` as a first argument
and will produce `""` when it is `Nothing` or `dstr t` when it's a `Just dstr` where `t` is the same that is used in `showVerticalBar` to decide what character to use.
* In `Plugins.Monitors` and `Plugins.Monitors.Wireless`: `runWireless` now takes interface as a first function argument instead of as a first element in options list.
* In monitors `Batt`, `Bright`, `Cpu`, `Disk`, `MPD`, `Mem`, `MultiCpu`, `Net`, `Volume`, `Wireless`: new options and template variables are added to support "dynamic strings". For monitors that didn't have custom options, code to handle them is added by pretty much copy-pasting from `Batt`.

#### In terms of idea:
Ideally this "dynamic strings" should be functions that take an actual value from monitors, can pattern match on it and produce vastly different strings as a result. But this would require something like #100 so I consider this pull request as a good-enough-workaround when you want pretty icons instead of bars or numbers to display values.

*P.S. Possibly (probably (most likely)) the "dynamic strings" name should be changed.*