#terminal-colors #ansi-term #terminal #ansi #ansi-colors #color #console

fwdansi

Forwards a byte string with ANSI escape code to a termcolor terminal

2 stable releases

Uses old Rust 2015

1.1.0 Nov 17, 2019
1.0.1 Jul 31, 2018

#1135 in Command-line interface

Download history 1603/week @ 2024-11-17 1690/week @ 2024-11-24 2006/week @ 2024-12-01 1882/week @ 2024-12-08 1837/week @ 2024-12-15 979/week @ 2024-12-22 1109/week @ 2024-12-29 1921/week @ 2025-01-05 2253/week @ 2025-01-12 2101/week @ 2025-01-19 1762/week @ 2025-01-26 1963/week @ 2025-02-02 1924/week @ 2025-02-09 1618/week @ 2025-02-16 2216/week @ 2025-02-23 1536/week @ 2025-03-02

7,551 downloads per month
Used in 117 crates (24 directly)

MIT license

9KB
190 lines

Write colored strings with ANSI escape code into a termcolor terminal.

This package provides a single function, write_ansi, which parses ANSI escape codes in the provided byte string and transforms them into the corresponding termcolor commands. The colors will be supported even on a Windows console.

The main purpose of this package is to forward colored output from a child process.

extern crate termcolor;
extern crate fwdansi;

use termcolor::*;
use std::io;
use std::process::Command;
use fwdansi::write_ansi;

fn main() -> io::Result<()> {
    let output = Command::new("rustc").args(&["--color", "always"]).output()?;

    let mut stderr = StandardStream::stderr(ColorChoice::Always);
    write_ansi(&mut stderr, &output.stderr)?;
    //^ should print "error: no input filename given" with appropriate color everywhere.

    Ok(())
}

Dependencies

~0.2–6.5MB
~36K SLoC