Weechat

Struct Weechat 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn color(color_name: &str) -> &str

Return a string color code for display.

§Arguments

color_name - name of the color

§Panics

Panics if the method is not called from the main Weechat thread.

Source

pub fn color_pair(foreground_color: &str, background_color: &str) -> String

Return a string color pair for display.

§Arguments

foreground_color - Name of the color that should be used for the foreground.

background_color - Name of the color that should be used for the background.

§Panics

Panics if the method is not called from the main Weechat thread.

Source

pub fn prefix(prefix: &str) -> &str

Retrieve a prefix value

§Arguments:

prefix - The name of the prefix.

Valid prefixes are:

  • error
  • network
  • action
  • join
  • quit

An empty string will be returned if the prefix is not found

§Panics

Panics if the method is not called from the main Weechat thread.

Source

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

Source

pub fn remove_color(string: &str) -> String

Remove WeeChat colors from a string.

§Arguments
  • string - The string that should be stripped from Weechat colors.
§Panics

Panics if the method is not called from the main Weechat thread.

Source

pub fn eval_string_expression(expression: &str) -> Result<String, ()>

Evaluate a Weechat expression and return the result.

§Arguments
  • expression - The expression that should be evaluated.
§Panics

Panics if the method is not called from the main Weechat thread.

Source

pub fn home_dir() -> PathBuf

Get the Weechat homedir.

Source

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.

Source

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.
Source

pub fn spawn<F>(future: F) -> Task<F::Output>
where F: Future + 'static, F::Output: 'static,

Available on 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()));
Source

pub fn spawn_from_thread<F>(future: F)
where F: Future<Output = ()> + Send + 'static,

Available on 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

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.

Source

pub fn current_buffer(&self) -> Buffer<'_>

Get the currently open buffer

Source§

impl Weechat

Source

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”).
Source

pub fn get_plugin_option(&self, option: &str) -> Option<Cow<'_, str>>

Get value of a plugin option

Source

pub fn set_plugin_option(&self, option: &str, value: &str) -> OptionChanged

Set the value of a plugin option

Source§

impl Weechat

Source

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

Source

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");
    }
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.