Skip to main content

ztty_plugin_api/
lib.rs

1#![no_std]
2
3//! Shared interface for independently built ztty text extensions.
4//!
5//! Native implementations are trusted code. They must not retain input/output
6//! references after a call. ztty validates the returned length and UTF-8 before
7//! committing a result. Change the interface version when changing signatures.
8
9/// The host accepts at most this many UTF-8 input or output bytes per action.
10pub const MAX_TEXT_BYTES: usize = 1024 * 1024;
11
12/// Transform a selected string or the currently visible terminal text.
13#[zplugin::interface(id = "dev.project-z.ztty.text", version = 1)]
14pub trait TextAction {
15    /// Write the result into `output` and return its byte length.
16    /// Return `BufferTooSmall` without exceeding the supplied buffer.
17    fn transform(&mut self, input: &str, output: &mut [u8]) -> Result<u64, zplugin::Error>;
18}