Crates.io | setup-console |
lib.rs | setup-console |
version | 0.2.1 |
source | src |
created_at | 2023-07-31 17:57:56.788716 |
updated_at | 2023-08-06 11:04:40.104496 |
description | A library that provides a function to fix ANSI escaping problem in Command Prompt on Windows. |
homepage | |
repository | https://github.com/yuto0214w/setup-console |
max_upload_size | |
id | 931091 |
size | 6,174 |
A library that provides a function to fix ANSI escaping problem in Command Prompt on Windows.
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
}
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
program 1>nul
)GetConsoleMode()
SetConsoleMode()
If this is not your desired behavior, you can use setup_console::try_init()
which returns Result
.