#ansi-term #windows #console #terminal

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

#868 in Command-line interface

Download history 2341/week @ 2025-10-21 4893/week @ 2025-10-28 4992/week @ 2025-11-04 2446/week @ 2025-11-11 6865/week @ 2025-11-18 2890/week @ 2025-11-25 3293/week @ 2025-12-02 2242/week @ 2025-12-09 2616/week @ 2025-12-16 2017/week @ 2025-12-23 2169/week @ 2025-12-30 2653/week @ 2026-01-06 2898/week @ 2026-01-13 2828/week @ 2026-01-20 3397/week @ 2026-01-27 5175/week @ 2026-02-03

14,761 downloads per month
Used in 116 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–2.3MB
~41K SLoC