Buffers and decodes raw process/PTY byte streams into valid UTF-8 text, detecting fallback encodings like Windows-1252 or IBM866 across chunk boundaries.
// Source: https://github.com/GCWing/OpenBitFun | License: MIT | Copyright 2026 CWing
// Provided via justclaw.it.com; keep this notice with the code.
//! Decode each process stream before merging or retaining its output.
use chardetng::EncodingDetector;
use encoding_rs::{Decoder, Encoding, IBM866, WINDOWS_1252};
/// Pipe reads and PTY frames need not end at a character boundary. Keep the
/// unfinished suffix across reads (and tool polls), rather than guessing a new
/// encoding for an otherwise valid UTF-8 chunk.
#[derive(Default)]
pub(super) struct OutputDecoder {
pending: Vec<u8>,
fallback: Option<Decoder>,
}
impl OutputDecoder {
pub(super) fn push(&mut self, bytes: &[u8]) -> String {
if let Some(decoder) = self.fallback.as_mut() {
return decode_fallb
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key