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

source

pub fn stdout() -> Result<Console>

Create a new Console to stdout.

If there was a problem creating the console, then an error is returned.

source

pub fn stderr() -> Result<Console>

Create a new Console to stderr.

If there was a problem creating the console, then an error is returned.

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl Debug for Console

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.