diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-12-12 00:44:24 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-12-12 00:44:24 +0100 |
commit | 75827353b4ece85cb4e1e927404692f136b270b8 (patch) | |
tree | 02ed358fc2dd17c1d8c69e263e9f66105f41faa2 /.i3/conky-wrapper.pl | |
parent | 1f005773df11ea43d886476e922b8fefe9f2a6a1 (diff) | |
download | dotfiles-75827353b4ece85cb4e1e927404692f136b270b8.tar.gz dotfiles-75827353b4ece85cb4e1e927404692f136b270b8.tar.xz |
i3: Rewrite conky wrapper in perl
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to '.i3/conky-wrapper.pl')
-rwxr-xr-x | .i3/conky-wrapper.pl | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/.i3/conky-wrapper.pl b/.i3/conky-wrapper.pl new file mode 100755 index 0000000..2ab2925 --- /dev/null +++ b/.i3/conky-wrapper.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl + +use v5.14; +use strict; +use warnings; + +use JSON; +use Clone 'clone'; +use IO::Handle; + +# Send the header so that i3bar knows we want to use JSON: +printf "%s", '{"version":1}'; + +# Begin the endless array. +printf "%s", '['; + +# We send an empty first array of blocks to make the loop simpler: +printf "%s",'[],'; + +open my $conky, "-|:encoding(utf8)", "conky -c $ENV{HOME}/.i3/conkyrc-perl"; +STDOUT->autoflush(); + +my @data; +my %in_progress; +my $json = JSON->new; +$json->ascii([1]); + +my %simple_mappings = ( + "SHORTTEXT" => "shorttext", +); + +while (<$conky>) { + chomp($_); + + next if m/^\s+$/; + + if (m/^END_BLOCK$/) { + STDOUT->printf("%s,\n", $json->encode(\@data)); + undef @data; + next; + } + + if (m/^COLOR: (#[a-zA-Z0-9]+)$/) { + $in_progress{color} = $1; + next; + } + + for my $key (keys %simple_mappings) { + if (m/^$key: (.*)$/) { + $in_progress{$simple_mappings{$key}} = $1; + next; + } + } + + if (m/^FULLTEXT: (.*)$/) { + my $fulltext = $1; + $in_progress{full_text} = $fulltext; + push @data, clone \%in_progress; + undef %in_progress; + next; + } + + printf STDERR "Got unexpected data: %s\n", $_; +} + |