Struct Print

Source
pub struct Print<T: AsRef<[u8]>> { /* private fields */ }
Expand description

Format graphics codes as an ANSI escape sequence.

Create an instance using the mode! macro.

Implementations§

Source§

impl<T: AsRef<[u8]>> Print<T>

Source

pub fn erase<'a>(&'a self) -> Print<&'a [u8]>

Normalizes the generic type to &[u8].

Examples found in repository?
examples/test-support.rs (line 49)
2fn main() {
3	println!("Attributes:\n");
4
5	let attrs = [
6		("BOLD", ansi_gfx::BOLD),
7		("DIM", ansi_gfx::DIM),
8		("ITALIC", ansi_gfx::ITALIC),
9		("UNDERLINE", ansi_gfx::UNDERLINE),
10		("BLINK", ansi_gfx::BLINK),
11		("INVERSE", ansi_gfx::INVERSE),
12		("HIDDEN", ansi_gfx::HIDDEN),
13		("STRIKE", ansi_gfx::STRIKE),
14	];
15	for &(text, attr) in &attrs {
16		println!("{}{}{}", attr, text, ansi_gfx::RESET);
17	}
18
19
20	println!("\nColors:\n");
21
22	let colors = [
23		("BLACK", ansi_gfx::BLACK, ansi_gfx::BLACK_BG, ansi_gfx::BRIGHT_BLACK, ansi_gfx::BRIGHT_BLACK_BG),
24		("RED", ansi_gfx::RED, ansi_gfx::RED_BG, ansi_gfx::BRIGHT_RED, ansi_gfx::BRIGHT_RED_BG),
25		("GREEN", ansi_gfx::GREEN, ansi_gfx::GREEN_BG, ansi_gfx::BRIGHT_GREEN, ansi_gfx::BRIGHT_GREEN_BG),
26		("YELLOW", ansi_gfx::YELLOW, ansi_gfx::YELLOW_BG, ansi_gfx::BRIGHT_YELLOW, ansi_gfx::BRIGHT_YELLOW_BG),
27		("BLUE", ansi_gfx::BLUE, ansi_gfx::BLUE_BG, ansi_gfx::BRIGHT_BLUE, ansi_gfx::BRIGHT_BLUE_BG),
28		("MAGENTA", ansi_gfx::MAGENTA, ansi_gfx::MAGENTA_BG, ansi_gfx::BRIGHT_MAGENTA, ansi_gfx::BRIGHT_MAGENTA_BG),
29		("CYAN", ansi_gfx::CYAN, ansi_gfx::CYAN_BG, ansi_gfx::BRIGHT_CYAN, ansi_gfx::BRIGHT_CYAN_BG),
30		("WHITE", ansi_gfx::WHITE, ansi_gfx::WHITE_BG, ansi_gfx::BRIGHT_WHITE, ansi_gfx::BRIGHT_WHITE_BG),
31	];
32	for &(text, fg, bg, fg_bright, bg_bright) in &colors {
33		print!("{}{:<8}{} ", fg, text, ansi_gfx::RESET);
34		print!("{}{:<8}{} ", fg_bright, text, ansi_gfx::RESET);
35		print!("{}{:<8}{} ", bg, text, ansi_gfx::RESET);
36		print!("{}{:<8}{} ", bg_bright, text, ansi_gfx::RESET);
37		println!();
38	}
39
40
41	println!("\nPalette colors:\n");
42
43	for i in 0..16 {
44		if i == 8 {
45			println!();
46		}
47		let fg = if i == 0 { ansi_gfx::WHITE } else { ansi_gfx::BLACK };
48		let mode = ansi_gfx::mode!({fg}; BG PAL i);
49		print!("{}{:>4} {}", mode.erase(), i, ansi_gfx::RESET);
50	}
51	println!("\n");
52
53	let mut n = 0;
54	for i in 16..232 {
55		if n == 18 {
56			n = 0;
57			println!();
58		}
59		n += 1;
60		let fg = if i < 34 { ansi_gfx::WHITE } else { ansi_gfx::BLACK };
61		print!("{}{:>4} {}", ansi_gfx::mode!({fg}; BG PAL i), i, ansi_gfx::RESET);
62	}
63
64	println!("\n");
65	for i in 232..244 {
66		print!("{}{:>4} {}", ansi_gfx::mode!(WHITE; BG PAL i), i, ansi_gfx::RESET);
67	}
68	println!();
69	for i in 244..256 {
70		let i = i as u8;
71		print!("{}{:>4} {}", ansi_gfx::mode!(BLACK; BG PAL i), i, ansi_gfx::RESET);
72	}
73
74	println!();
75}

Trait Implementations§

Source§

impl<T: AsRef<[u8]>> Debug for Print<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: AsRef<[u8]>> Display for Print<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Print<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Print<T>
where T: RefUnwindSafe,

§

impl<T> Send for Print<T>
where T: Send,

§

impl<T> Sync for Print<T>
where T: Sync,

§

impl<T> Unpin for Print<T>
where T: Unpin,

§

impl<T> UnwindSafe for Print<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.