#ansi #windows #console #terminal #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

#105 in Command-line interface

Download history 3420/week @ 2020-12-24 4166/week @ 2020-12-31 4415/week @ 2021-01-07 4698/week @ 2021-01-14 4634/week @ 2021-01-21 4767/week @ 2021-01-28 4446/week @ 2021-02-04 4942/week @ 2021-02-11 5562/week @ 2021-02-18 4569/week @ 2021-02-25 4647/week @ 2021-03-04 4565/week @ 2021-03-11 3988/week @ 2021-03-18 4857/week @ 2021-03-25 5292/week @ 2021-04-01 4646/week @ 2021-04-08

19,257 downloads per month
Used in 86 crates (13 directly)

MIT license

9KB
190 lines


lib.rs:

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

~180KB