summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-08-07 01:49:40 +0100
committerjao <jao@gnu.org>2020-08-07 01:49:40 +0100
commit80a716edf95ca61b347d8f20b080f88f4bf55bbf (patch)
tree44d52a137272c9d94ff2295cb6e3ca91760454c7
parent52749121672080f93ead1cf4408fef7b2b8adde4 (diff)
downloadxmobar-80a716edf95ca61b347d8f20b080f88f4bf55bbf.tar.gz
xmobar-80a716edf95ca61b347d8f20b080f88f4bf55bbf.tar.bz2
String index as progress bar
-rw-r--r--readme.md4
-rw-r--r--src/Xmobar/Plugins/Monitors/Common/Output.hs9
2 files changed, 10 insertions, 3 deletions
diff --git a/readme.md b/readme.md
index d9ea24b..1b12095 100644
--- a/readme.md
+++ b/readme.md
@@ -792,6 +792,10 @@ These are the options available for all monitors below:
- Total number of characters used to draw bars.
- Long option: `--bwidth`
- Default value: 10
+ - Special value: 0. When this parameter is 0, the percentage to
+ display is interpreted as a position in the bar foreground
+ string (given by `-f`), and the character at that position is
+ displayed.
- `-x` _string_ N/A string
- String to be used when the monitor is not available
- Long option: `--nastring`
diff --git a/src/Xmobar/Plugins/Monitors/Common/Output.hs b/src/Xmobar/Plugins/Monitors/Common/Output.hs
index c41ef19..4733a9f 100644
--- a/src/Xmobar/Plugins/Monitors/Common/Output.hs
+++ b/src/Xmobar/Plugins/Monitors/Common/Output.hs
@@ -221,9 +221,12 @@ showPercentBar v x = do
bb <- getConfigValue barBack
bf <- getConfigValue barFore
bw <- getConfigValue barWidth
- let len = min bw $ round (fromIntegral bw * x)
- s <- colorizeString v (take len $ cycle bf)
- return $ s ++ take (bw - len) (cycle bb)
+ let c = bw < 1
+ w = if c then length bf else bw
+ len = min w $ round (fromIntegral w * x)
+ bfs = if c then [bf !! (len - 1)] else take len $ cycle bf
+ s <- colorizeString v bfs
+ return $ s ++ if c then "" else take (bw - len) (cycle bb)
showIconPattern :: Maybe IconPattern -> Float -> Monitor String
showIconPattern Nothing _ = return ""