Struct winapi_util::console::Console
source · pub struct Console { /* private fields */ }
Expand description
A Windows console.
This represents a very limited set of functionality available to a Windows console. In particular, it can only change text attributes such as color and intensity. This may grow over time. If you need more routines, please file an issue and/or PR.
There is no way to “write” to this console. Simply write to stdout or stderr instead, while interleaving instructions to the console to change text attributes.
A common pitfall when using a console is to forget to flush writes to stdout before setting new text attributes.
§Example
use winapi_util::console::{Console, Color, Intense};
let mut con = Console::stdout().unwrap();
con.fg(Intense::Yes, Color::Cyan).unwrap();
println!("This text will be intense cyan.");
con.reset().unwrap();
println!("This text will be normal.");
Implementations§
source§impl Console
impl Console
sourcepub fn stdout() -> Result<Console>
pub fn stdout() -> Result<Console>
Create a new Console to stdout.
If there was a problem creating the console, then an error is returned.
sourcepub fn stderr() -> Result<Console>
pub fn stderr() -> Result<Console>
Create a new Console to stderr.
If there was a problem creating the console, then an error is returned.
sourcepub fn fg(&mut self, intense: Intense, color: Color) -> Result<()>
pub fn fg(&mut self, intense: Intense, color: Color) -> Result<()>
Apply the given intensity and color attributes to the console foreground.
If there was a problem setting attributes on the console, then an error is returned.
sourcepub fn bg(&mut self, intense: Intense, color: Color) -> Result<()>
pub fn bg(&mut self, intense: Intense, color: Color) -> Result<()>
Apply the given intensity and color attributes to the console background.
If there was a problem setting attributes on the console, then an error is returned.
sourcepub fn reset(&mut self) -> Result<()>
pub fn reset(&mut self) -> Result<()>
Reset the console text attributes to their original settings.
The original settings correspond to the text attributes on the console
when this Console
value was created.
If there was a problem setting attributes on the console, then an error is returned.
sourcepub fn set_virtual_terminal_processing(&mut self, yes: bool) -> Result<()>
pub fn set_virtual_terminal_processing(&mut self, yes: bool) -> Result<()>
Toggle virtual terminal processing.
This method attempts to toggle virtual terminal processing for this console. If there was a problem toggling it, then an error returned. On success, the caller may assume that toggling it was successful.
When virtual terminal processing is enabled, characters emitted to the console are parsed for VT100 and similar control character sequences that control color and other similar operations.