Commit adb9865c01

adb9865c016bbb98045af2224dbcafe8d8906008

parent: e8e4f88aa6

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-12-08 20:04 UTC

bar_items: Add the buffer_plugin bar item.

Layout: unified · split

src/bar_items/buffer_plugin.rs added +38
@@ -0,0 +1,38 @@
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 => {
34 "".to_owned()
35 }
36 }
37 }
38}
src/bar_items/mod.rs +6 −1
@@ -1,9 +1,11 @@
11mod buffer_name;
2mod buffer_plugin;
23mod status;
34
45use weechat::hooks::BarItem;
56
67use crate::Servers;
8use buffer_plugin::BufferPlugin;
79use buffer_name::BufferName;
810use status::Status;
911
@@ -12,13 +14,16 @@ pub struct BarItems {
1214 status: BarItem,
1315 #[used]
1416 buffer_name: BarItem,
17 #[used]
18 buffer_plugin: BarItem,
1519}
1620
1721impl BarItems {
1822 pub fn hook_all(servers: Servers) -> Result<Self, ()> {
1923 Ok(Self {
2024 status: Status::create(servers.clone())?,
21 buffer_name: BufferName::create(servers)?,
25 buffer_name: BufferName::create(servers.clone())?,
26 buffer_plugin: BufferPlugin::create(servers)?,
2227 })
2328 }
2429}