pub fn encode(data: &mut [u8], bracketed: bool, buf: &mut [u8]) -> Result<usize>Expand description
Encode paste data for writing to the terminal pty.
This function prepares paste data for terminal input by:
- Stripping unsafe control bytes (NUL, ESC, DEL, etc.) by replacing them with spaces
- Wrapping the data in bracketed paste sequences if
bracketedis true - Replacing newlines with carriage returns if
bracketedis false
The input data buffer is modified in place during encoding. The encoded
result (potentially with bracketed paste prefix/suffix) is written to the
output buffer.
If the output buffer is too small, the function returns
Err(Error::OutOfSpace { required }) where required is the required
The caller can then retry with a sufficiently sized buffer.