[−][src]Crate weechat
rust-weechat
rust-weechat implements high level bindings for the Weechat plugin API.
The bindings make it possible to create powerful Weechat plugins using rust.
use std::borrow::Cow; use weechat::buffer::{Buffer, BufferSettings, NickSettings}; use weechat::hooks::{CommandSettings, Command}; use weechat::{weechat_plugin, ArgsWeechat, Weechat, WeechatPlugin}; struct SamplePlugin { _command: Command, } impl SamplePlugin { fn input_cb( _weechat: &Weechat, buffer: &Buffer, input: Cow<str>, ) -> Result<(), ()> { buffer.print(&input); Ok(()) } fn close_cb(_weechat: &Weechat, _buffer: &Buffer) -> Result<(), ()> { Weechat::print("Closing buffer"); Ok(()) } fn rust_command_cb(_weechat: &Weechat, buffer: &Buffer, args: ArgsWeechat) { buffer.print("Hello world"); for arg in args { buffer.print(&arg) } } } impl WeechatPlugin for SamplePlugin { fn init(weechat: &Weechat, _args: ArgsWeechat) -> Result<Self, ()> { Weechat::print("Hello Rust!"); let buffer_settings = BufferSettings::new("Test buffer") .input_callback(SamplePlugin::input_cb) .close_callback(SamplePlugin::close_cb); let buffer_handle = Weechat::buffer_new(buffer_settings).expect("Can't create buffer"); let buffer = buffer_handle.upgrade().expect("Buffer already closed?"); let op_group = buffer .add_nicklist_group("operators", "blue", true, None) .expect("Can't create nick group"); let emma = op_group .add_nick( NickSettings::new("Emma") .set_color("magenta") .set_prefix("&") .set_prefix_color("green"), ) .expect("Can't add nick to group"); let sample_command = CommandSettings::new("rustcommand"); let command = Command::new( sample_command, SamplePlugin::rust_command_cb, ); Ok(SamplePlugin { _command: command.unwrap(), }) } } impl Drop for SamplePlugin { fn drop(&mut self) { Weechat::print("Bye rust"); } }
The above plugin implementation still needs to be registered as a Weechat plugin:
weechat_plugin!( SamplePlugin, name: "rust_sample", author: "poljar", description: "", version: "0.1.0", license: "MIT" );
Re-exports
pub use paste; |
pub use strum; |
pub use libc; |
pub use weechat_sys; |
Modules
buffer | Weechat Buffer module containing Buffer and Nick types. |
config | Weechat configuration for plugins. |
hooks | Weechat Hook module. |
infolist | Infolists can be used to share information between scripts and plugins. |
Macros
config | Declare a Weechat configuration file. |
weechat_plugin | Register a struct that implements the |
Structs
ArgsWeechat | An iterator over the arguments of a Weechat command, yielding a String value for each argument. |
JoinHandle | A handle that awaits the result of a task. |
Weechat | Main Weechat struct that encapsulates common weechat API functions. It has a similar API as the weechat script API. |
Enums
ReturnCode | Status values for Weechat callbacks |
Traits
WeechatPlugin | Weechat plugin trait. |