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

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

#882 in Command-line interface

Download history 2798/week @ 2024-06-09 3019/week @ 2024-06-16 2976/week @ 2024-06-23 2452/week @ 2024-06-30 2708/week @ 2024-07-07 2843/week @ 2024-07-14 3143/week @ 2024-07-21 3445/week @ 2024-07-28 2928/week @ 2024-08-04 4937/week @ 2024-08-11 4710/week @ 2024-08-18 5730/week @ 2024-08-25 5905/week @ 2024-09-01 5829/week @ 2024-09-08 4777/week @ 2024-09-15 3493/week @ 2024-09-22

20,529 downloads per month
Used in 118 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–7MB
~40K SLoC