src/bar_items/buffer_plugin.rs
36 lines · 989 bytes
1use weechat::{
2 buffer::Buffer,
3 hooks::{BarItem, BarItemCallback},
4 Weechat,
5};
6
7use crate::{BufferOwner, Servers, PLUGIN_NAME};
8
9pub(super) struct BufferPlugin {
10 servers: Servers,
11}
12
13impl BufferPlugin {
14 pub(super) fn create(servers: Servers) -> Result<BarItem, ()> {
15 let status = Self { servers };
16 BarItem::new("buffer_plugin", status)
17 }
18}
19
20impl BarItemCallback for BufferPlugin {
21 fn callback(&mut self, _: &Weechat, buffer: &Buffer) -> String {
22 match self.servers.buffer_owner(buffer) {
23 BufferOwner::Server(s) | BufferOwner::Room(s, _) => {
24 format!(
25 "{plugin_name}{del_color}/{color}{name}",
26 plugin_name = PLUGIN_NAME,
27 del_color = Weechat::color("bar_delim"),
28 color = Weechat::color("bar_fg"),
29 name = s.name()
30 )
31 }
32
33 BufferOwner::None => "".to_owned(),
34 }
35 }
36}