#escaping #ansi #prompt #console #command #problem #setup

setup-console

A library that provides a function to fix ANSI escaping problem in Command Prompt on Windows

4 releases

0.2.1 Aug 6, 2023
0.2.0 Aug 6, 2023
0.1.1 Aug 2, 2023
0.1.0 Jul 31, 2023

#87 in #setup

MIT license

6KB
68 lines

setup-console

A library that provides a function to fix ANSI escaping problem in Command Prompt on Windows.

Latest version

Usage

Simply run setup_console::init() (or setup_console::try_init()) in the main function before printing anything.

fn main() {
    println!("\x1b[31mRed \x1b[32mGreen \x1b[34mBlue\x1b[39m");
    // ・[31mRed ・[32mGreen ・[34mBlue・[39m
    setup_console::init();
    println!("\x1b[31mRed \x1b[32mGreen \x1b[34mBlue\x1b[39m");
    // Red Green Blue
}

Panics

This only applies to Windows.

setup_console::init() doesn't panic, but shows message and terminates program with error code obtained from GetLastError() instead.

The situations that would lead program to terminate would be

If this is not your desired behavior, you can use setup_console::try_init() which returns Result.

Dependencies

~0–11MB
~69K SLoC