summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2019-10-12 15:33:10 +0100
committerjao <jao@gnu.org>2019-10-12 15:33:24 +0100
commit6173b1cab8a5df50de7d72eb42f3ababae782e49 (patch)
treec707de57adef8cc24dec3dd1b6b2c04dc7d92af0
parent55981bd182a38ddff96bed317dafb8e54cb697e5 (diff)
downloadxmobar-config-6173b1cab8a5df50de7d72eb42f3ababae782e49.tar.gz
xmobar-config-6173b1cab8a5df50de7d72eb42f3ababae782e49.tar.bz2
toggleMonitor
-rwxr-xr-xbin/toggle-pipe.sh16
-rw-r--r--src/lib/Monitors.hs12
2 files changed, 24 insertions, 4 deletions
diff --git a/bin/toggle-pipe.sh b/bin/toggle-pipe.sh
new file mode 100755
index 0000000..2dfc8b9
--- /dev/null
+++ b/bin/toggle-pipe.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+[[ -z $1 ]] && echo "Usage: toggle-pipe.sh path-to-pipe" && exit 1
+
+state="$1.state"
+
+[[ -p $1 ]] || mkfifo $1
+
+[[ -f $state ]] || echo 0 > $state
+
+v=$(<$state)
+
+if [[ x$v == x1 ]]; then v=0; else v=1; fi
+
+echo $v > $state;
+echo -e "$v\\\n" > $1;
diff --git a/src/lib/Monitors.hs b/src/lib/Monitors.hs
index 5639185..0dbe8b1 100644
--- a/src/lib/Monitors.hs
+++ b/src/lib/Monitors.hs
@@ -25,16 +25,20 @@ startMonitors a b cmb = do
stb <- atomically $ newTVar ""
_ <- async $ start a (\x -> atomically $ writeTVar sta x)
_ <- async $ start b (\x -> atomically $ writeTVar stb x)
- go sta stb cmb
- where go sta' stb' cmb' = do
+ go sta stb
+ where go sta' stb' = do
s <- atomically $ readTVar sta'
t <- atomically $ readTVar stb'
- cmb' s t
+ cmb s t
tenthSeconds $ min (rate b) (rate a)
- go sta' stb' cmb'
+ go sta' stb'
+
+guardedMonitor a p = CombinedMonitor (PipeReader p (alias a ++ "_g")) a f
+ where f s t = if (null s || head s == '0') then "" else t
altMonitor a b = CombinedMonitor a b (\s t -> if null s then t else s)
concatMonitor sep a b = CombinedMonitor a b (\s t -> s ++ sep ++ t)
+toggleMonitor path a b = altMonitor (guardedMonitor a path) b
topProc p = TopProc (p <~> ["-t" , "<mboth3> <mboth2> <mboth1> \
\ยท <both3> <both2> <both1>"