Struct ansi_gfx::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)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
fn main() {
	println!("Attributes:\n");

	let attrs = [
		("BOLD", ansi_gfx::BOLD),
		("DIM", ansi_gfx::DIM),
		("ITALIC", ansi_gfx::ITALIC),
		("UNDERLINE", ansi_gfx::UNDERLINE),
		("BLINK", ansi_gfx::BLINK),
		("INVERSE", ansi_gfx::INVERSE),
		("HIDDEN", ansi_gfx::HIDDEN),
		("STRIKE", ansi_gfx::STRIKE),
	];
	for &(text, attr) in &attrs {
		println!("{}{}{}", attr, text, ansi_gfx::RESET);
	}


	println!("\nColors:\n");

	let colors = [
		("BLACK", ansi_gfx::BLACK, ansi_gfx::BLACK_BG, ansi_gfx::BRIGHT_BLACK, ansi_gfx::BRIGHT_BLACK_BG),
		("RED", ansi_gfx::RED, ansi_gfx::RED_BG, ansi_gfx::BRIGHT_RED, ansi_gfx::BRIGHT_RED_BG),
		("GREEN", ansi_gfx::GREEN, ansi_gfx::GREEN_BG, ansi_gfx::BRIGHT_GREEN, ansi_gfx::BRIGHT_GREEN_BG),
		("YELLOW", ansi_gfx::YELLOW, ansi_gfx::YELLOW_BG, ansi_gfx::BRIGHT_YELLOW, ansi_gfx::BRIGHT_YELLOW_BG),
		("BLUE", ansi_gfx::BLUE, ansi_gfx::BLUE_BG, ansi_gfx::BRIGHT_BLUE, ansi_gfx::BRIGHT_BLUE_BG),
		("MAGENTA", ansi_gfx::MAGENTA, ansi_gfx::MAGENTA_BG, ansi_gfx::BRIGHT_MAGENTA, ansi_gfx::BRIGHT_MAGENTA_BG),
		("CYAN", ansi_gfx::CYAN, ansi_gfx::CYAN_BG, ansi_gfx::BRIGHT_CYAN, ansi_gfx::BRIGHT_CYAN_BG),
		("WHITE", ansi_gfx::WHITE, ansi_gfx::WHITE_BG, ansi_gfx::BRIGHT_WHITE, ansi_gfx::BRIGHT_WHITE_BG),
	];
	for &(text, fg, bg, fg_bright, bg_bright) in &colors {
		print!("{}{:<8}{} ", fg, text, ansi_gfx::RESET);
		print!("{}{:<8}{} ", fg_bright, text, ansi_gfx::RESET);
		print!("{}{:<8}{} ", bg, text, ansi_gfx::RESET);
		print!("{}{:<8}{} ", bg_bright, text, ansi_gfx::RESET);
		println!();
	}


	println!("\nPalette colors:\n");

	for i in 0..16 {
		if i == 8 {
			println!();
		}
		let fg = if i == 0 { ansi_gfx::WHITE } else { ansi_gfx::BLACK };
		let mode = ansi_gfx::mode!({fg}; BG PAL i);
		print!("{}{:>4} {}", mode.erase(), i, ansi_gfx::RESET);
	}
	println!("\n");

	let mut n = 0;
	for i in 16..232 {
		if n == 18 {
			n = 0;
			println!();
		}
		n += 1;
		let fg = if i < 34 { ansi_gfx::WHITE } else { ansi_gfx::BLACK };
		print!("{}{:>4} {}", ansi_gfx::mode!({fg}; BG PAL i), i, ansi_gfx::RESET);
	}

	println!("\n");
	for i in 232..244 {
		print!("{}{:>4} {}", ansi_gfx::mode!(WHITE; BG PAL i), i, ansi_gfx::RESET);
	}
	println!();
	for i in 244..256 {
		let i = i as u8;
		print!("{}{:>4} {}", ansi_gfx::mode!(BLACK; BG PAL i), i, ansi_gfx::RESET);
	}

	println!();
}

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> 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 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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.