pub struct Weechat { /* private fields */ }Expand description
Main Weechat struct that encapsulates common weechat API functions. It has a similar API as the weechat script API.
Implementations§
Source§impl Weechat
impl Weechat
Sourcepub unsafe fn weechat() -> &'static mut Weechat
pub unsafe fn weechat() -> &'static mut Weechat
Get the Weechat plugin.
§Safety
It is generally safe to call this method, the plugin pointer is valid for the durration of the plugin lifetime. The problem is that many Weechat objects need to have a lifetime bound to a Weechat context object that is only valid for the duration of a callback.
Since this one will have a static lifetime, objects that are fetched from this object may have a longer lifetime than they should.
Sourcepub fn log(msg: &str)
pub fn log(msg: &str)
Write a message in WeeChat log file (weechat.log).
§Panics
Panics if the method is not called from the main Weechat thread.
Sourcepub fn print(msg: &str)
pub fn print(msg: &str)
Display a message on the core weechat buffer.
§Panics
Panics if the method is not called from the main Weechat thread.
Sourcepub fn color_pair(foreground_color: &str, background_color: &str) -> String
pub fn color_pair(foreground_color: &str, background_color: &str) -> String
Sourcepub fn info_get(name: &str, arguments: &str) -> Option<String>
pub fn info_get(name: &str, arguments: &str) -> Option<String>
Get some info from Weechat or a plugin.
§Arguments
-
name- name the info -
arguments- arguments for the info
Sourcepub fn remove_color(string: &str) -> String
pub fn remove_color(string: &str) -> String
Sourcepub fn execute_modifier(
modifier: &str,
modifier_data: &str,
input_string: &str,
) -> Result<String, ()>
pub fn execute_modifier( modifier: &str, modifier_data: &str, input_string: &str, ) -> Result<String, ()>
Execute a modifier.
A modifier takes a string and modifies it in some way, Weechat has a list of defined modifiers. For example to parse a string with some color format (ansi, irc…) and to convert it to another format.
Returns the modified string or an empty error if the string couldn’t be modified.
§Arguments
-
modifier- The name of a modifier. The list of modifiers can be found in the official Weechat documentation. -
modifier_data- Data that will be passed to the modifier, this depends on the modifier that was chosen, consult the list of modifiers in the Weechat documentation. -
input_string- The string that should be modified.
§Panics
Panics if the method is not called from the main Weechat thread.
Sourcepub fn bar_item_update(name: &str)
pub fn bar_item_update(name: &str)
Update the content of a bar item, by calling its build callback.
§Arguments
name- The name of the bar item that should be updated.
Sourcepub fn spawn<F>(future: F) -> Task<F::Output> ⓘ
Available on async only.
pub fn spawn<F>(future: F) -> Task<F::Output> ⓘ
async only.Spawn a new Future on the main Weechat thread.
§Panics
Panics if the method is not called from the main Weechat thread.
§Example
use weechat::Weechat;
use async_std::sync::{channel, Receiver};
use futures::executor::block_on;
pub async fn task(receiver: Receiver<String>) {
loop {
match receiver.recv().await {
Ok(m) => {
Weechat::print(&format!("Received message: {}", m));
},
Err(e) => {
Weechat::print(
&format!("Error receiving on channel {:?}", e)
);
return;
}
}
}
}
let (tx, rx) = channel(1000);
Weechat::spawn(task(rx));
block_on(tx.send("Hello wordl".to_string()));Sourcepub fn spawn_from_thread<F>(future: F)
Available on async only.
pub fn spawn_from_thread<F>(future: F)
async only.Spawn a new Future on the main Weechat thread.
This can be called from any thread and will execute the future on the main Weechat thread.
Source§impl Weechat
impl Weechat
Sourcepub fn buffer_search(
&self,
plugin_name: &str,
buffer_name: &str,
) -> Option<Buffer<'_>>
pub fn buffer_search( &self, plugin_name: &str, buffer_name: &str, ) -> Option<Buffer<'_>>
Search a buffer by plugin and/or name.
Returns a Buffer if one is found, otherwise None.
§Arguments
-
plugin_name- name of a plugin, the following special value is allowed: “==”, the buffer name used is the buffers full name. -
buffer_name- name of a buffer, if this is an empty string, the current buffer is returned (buffer displayed by current window); if the name starts with (?i), the search is case insensitive.
Sourcepub fn current_buffer(&self) -> Buffer<'_>
pub fn current_buffer(&self) -> Buffer<'_>
Get the currently open buffer
Source§impl Weechat
impl Weechat
Sourcepub fn config_get(&self, option_name: &str) -> Option<ConfigOption<'_>>
pub fn config_get(&self, option_name: &str) -> Option<ConfigOption<'_>>
Search an option with a full name.
§Arguments
option_name- The full name of the option that should be searched for (format: “file.section.option”).
Sourcepub fn get_plugin_option(&self, option: &str) -> Option<Cow<'_, str>>
pub fn get_plugin_option(&self, option: &str) -> Option<Cow<'_, str>>
Get value of a plugin option
Sourcepub fn set_plugin_option(&self, option: &str, value: &str) -> OptionChanged
pub fn set_plugin_option(&self, option: &str, value: &str) -> OptionChanged
Set the value of a plugin option
Source§impl Weechat
impl Weechat
Sourcepub fn hook_signal_send<'a, D: Into<SignalData<'a>>>(
signal_name: &str,
data: D,
) -> ReturnCode
pub fn hook_signal_send<'a, D: Into<SignalData<'a>>>( signal_name: &str, data: D, ) -> ReturnCode
Send a signal.
This will send out a signal and callbacks that are registered with a
SignalHook to listen to that signal wil get called.
§Arguments
-
signal_name- The name of the signal that should be sent out. Common signals can be found in the Weechat plugin API reference. -
data- Data that should be provided to the signal callback. This can be a string, an i32 number, or a buffer.
// Fetch the chat history for the buffer.
Weechat::hook_signal_send("logger_backlog", &buffer);
// Signal that the input text changed.
Weechat::hook_signal_send("input_text_changed", "");Source§impl Weechat
impl Weechat
Sourcepub fn get_infolist(
&self,
infolist_name: &str,
arguments: Option<&str>,
) -> Result<Infolist<'_>, ()>
pub fn get_infolist( &self, infolist_name: &str, arguments: Option<&str>, ) -> Result<Infolist<'_>, ()>
Get the infolist with the given name.
§Arguments
-
infolist_name- The name of the infolist to fetch, valid values for this can be found in the Weechat documentation. -
arguments- Arguments that should be passed to Weechat while fetching the infolist, the format of this will depend on the infolist that is being fetched. A list of infolists and their accompanying arguments can be found in the Weechat documentation.
§Example
let infolist = weechat.get_infolist("logger_buffer", None).unwrap();
for item in infolist {
let info_buffer = if let Some(buffer) = item.get("buffer") {
buffer
} else {
continue;
};
if let InfolistVariable::Buffer(info_buffer) = info_buffer {
info_buffer.print("Hello world");
}
}