diff options
author | Teddy Wing | 2023-12-09 21:27:56 +0100 |
---|---|---|
committer | Teddy Wing | 2023-12-09 21:27:56 +0100 |
commit | 2e5206eb038f61fb8fa5e76a73bc986696ad9fa1 (patch) | |
tree | 6d5621c2d414e4c9b356e20aa490af07edf3e072 | |
parent | 3b1b1577710cab043bc35c92b3d295eab3ffbfe3 (diff) | |
download | weechat-activity-bar-2e5206eb038f61fb8fa5e76a73bc986696ad9fa1.tar.bz2 |
activity_bar.pl: Update the AnyBar colour when messages are received
-rw-r--r-- | activity_bar.pl | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/activity_bar.pl b/activity_bar.pl index c612092..e76486b 100644 --- a/activity_bar.pl +++ b/activity_bar.pl @@ -1,33 +1,54 @@ use strict; use warnings; +use IO::Socket::INET; + weechat::register( 'activity_bar', 'Teddy Wing', '1.0', 'GPL-3.0-or-later', 'Monitor activity in all buffers and update AnyBar', - '', + 'shutdown', '' ); +# Flush socket immediately. +$| = 1; + +my $socket = IO::Socket::INET->new( + PeerAddr => 'localhost', + PeerPort => '1738', + Proto => 'udp', +) or die "error: can't create socket: $!"; + +sub shutdown { + $socket->close(); +} + + weechat::hook_print('', '', '', 0, 'print_cb', ''); sub print_cb { my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message) = @_; my $buffer_type = weechat::buffer_get_string($buffer, 'localvar_type'); - my $buffer_name = weechat::buffer_get_string($buffer, 'short_name'); if ($buffer_type eq 'private') { - weechat::print('', "Private message in $buffer_name: $message"); + anybar_send('blue'); } elsif ($highlight == 1) { - weechat::print('', "Highlight in $buffer_name: $message"); + anybar_send('purple'); } else { - weechat::print('', "Message in $buffer_name: $message"); + anybar_send('orange'); } return weechat::WEECHAT_RC_OK; } + +sub anybar_send { + my ($message) = @_; + + $socket->send($message); +} |