#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

#1106 in Command-line interface

Download history 4748/week @ 2024-08-19 5994/week @ 2024-08-26 5640/week @ 2024-09-02 5836/week @ 2024-09-09 4765/week @ 2024-09-16 3864/week @ 2024-09-23 3046/week @ 2024-09-30 2472/week @ 2024-10-07 2945/week @ 2024-10-14 2966/week @ 2024-10-21 2052/week @ 2024-10-28 1367/week @ 2024-11-04 1434/week @ 2024-11-11 1569/week @ 2024-11-18 1749/week @ 2024-11-25 1767/week @ 2024-12-02

6,626 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–6.5MB
~39K SLoC