INNER CODE UNIT · Rust

normalize_stdout

sachaos/viddy · src/bytes.rs:5

pub fn normalize_stdout(s: &[u8]) -> Vec<u8> {
    // Naively replace tabs ('\t') with at most `TAB_SIZE` spaces (' ') while
    // maintaining the alignment / elasticity per line (see tests below).
    let str = String::from_utf8_lossy(s).to_string();
    let mut b = Vec::with_capacity(str.len() * TAB_SIZE);
    let mut chars = str.chars();
    let mut width = 0;
    while let Some(c) = chars.next() {
        let count = skip_ansi_escape_sequence(c, &mut chars.clone());
        if count > 0 {
            b.push(c);
            for _ in 0..count {
                b.push(chars.next().unwrap_or(' '));
            }
            continue;
        }

        if c == '\t' {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…