From 2e5206eb038f61fb8fa5e76a73bc986696ad9fa1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 9 Dec 2023 21:27:56 +0100 Subject: activity_bar.pl: Update the AnyBar colour when messages are received --- activity_bar.pl | 31 ++++++++++++++++++++++++++----- 1 file 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); +} -- cgit v1.2.3