Rust Hexchat API
This library provides a Rust API to the Hexchat Plugin Interface with additional Rust friendly features such as:
- A thread-safe API.
- Simple
user_dataobjects. - Abstractions like
Contextthat make it simple to interact with specific tabs/windows in the UI. - Panic's are caught and displayed in the active Hexchat window.
- Debug builds include a full stack trace for panics.
- Hooked commands can be implemented as normal functions or closures.
- Typed preference values and easy plugin pref access.
Documentation
Documentation can be found here
Examples
A completed plugin offers the most examples to pull from. Here's a plugin that does automatic translations which enables chatting with people in different tongues (chat with subtitles).
Setting up and registering commands using the API is easy and syntactically clean.
Interaction between threads and Hexchat is facilitated by main_thread(), which
uses Hexchat's timer event loop to delegate tasks, such as printing output
to the active Hexchat window.
hexchat.hook_command;
Linking to hexchat_api
Simply include an entry in your Rust project's Cargo.toml file:
[]
= "0.2"
Template
The code below can be copied to start a new plugin project. The TOML file content is also included below.
// FILE: lib.rs
//! A starter project template that can be copied and modified.
use *;
use *;
// Register the entry points of the plugin.
//
dll_entry_points!;
/// Called when the plugin is loaded to register it with Hexchat.
///
/// Called when the plugin is loaded.
///
/// Called when the plugin is unloaded.
///
/// A command callback implemented as a function.
/// # Arguments
/// * `hc` - The Hexchat API object reference.
/// * `word` - A list of parameters passed to the command.
/// * `word_eol` - Like `word`, but catenates the word args decrementally.
/// * `user_data` - The user data to be passed back to the command when invoked
/// by Hexchat.
/// # Returns
/// * One of `Eat::All`, `Eat::Hexchat`, `Eat::Plugin`, `Eat::None`.
///
And the Cargo.toml file.
[]
= "hexchat_plugin_template"
= "0.1.0"
= ["you <your@email.com>"]
= "2021"
[]
= "hexchat_plugin_template"
= ["cdylib"]
[]
= "0.2"