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

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

#268 in Command-line interface

Download history 4144/week @ 2023-11-30 3693/week @ 2023-12-07 3312/week @ 2023-12-14 2737/week @ 2023-12-21 2526/week @ 2023-12-28 3231/week @ 2024-01-04 3054/week @ 2024-01-11 2971/week @ 2024-01-18 3139/week @ 2024-01-25 2574/week @ 2024-02-01 2678/week @ 2024-02-08 2590/week @ 2024-02-15 2676/week @ 2024-02-22 3114/week @ 2024-02-29 2806/week @ 2024-03-07 2170/week @ 2024-03-14

11,219 downloads per month
Used in 137 crates (26 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

~245–560KB