pub fn cleanup_captured_buffer(
buffer: &[u8],
drop_n_last_lines: usize,
) -> Vec<u8> ⓘExpand description
Process a pane captured buffer.
- All lines are trimmed after capture because tmux does not allow capturing escape codes and trimming lines.
- If
drop_n_last_linesis greater than 0, the n last lines are not captured. This is used only for panes with a zsh prompt, in order to avoid polluting the history with new prompts on restore. - In addition, the last line has an additional ascii reset escape code because tmux does not capture it.
use tmux_lib::utils::cleanup_captured_buffer;
let buffer = b"line1 \nline2\t\n\n\n";
let result = cleanup_captured_buffer(buffer, 0);
let output = String::from_utf8(result).unwrap();
// trailing whitespace trimmed, empty trailing lines dropped, reset code appended
assert_eq!(output, "line1\nline2\x1b[0m\n");