src/bar_items/buffer_plugin.rs
38 lines · 1047 bytes
3 symbols in this file
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)
24 | BufferOwner::Room(s, _)
25 | BufferOwner::Verification(s, _) => {
26 format!(
27 "{plugin_name}{del_color}/{color}{name}",
28 plugin_name = PLUGIN_NAME,
29 del_color = Weechat::color("bar_delim"),
30 color = Weechat::color("bar_fg"),
31 name = s.name()
32 )
33 }
34
35 BufferOwner::None => "".to_owned(),
36 }
37 }
38}