[][src]Struct glerminal::Parser

pub struct Parser { /* fields omitted */ }

Represents a parser, that is able to read given texts and use TextBuffer accordingly, to write text and styles matching to the text.

Note: This struct requires parser feature to be enabled.

See TextBuffer for examples and more detailed documentation.

Methods

impl Parser
[src]

pub fn new() -> Parser
[src]

Creates a new Parser to use.

pub fn add_color<T: Into<String>>(&mut self, color_str: T, color: [f32; 4])
[src]

Adds a color to the parser to use later.

pub fn write<T: Into<String>>(&self, text_buffer: &mut TextBuffer, text: T)
[src]

Parses the given text and makes it look according to the parsed text.

Example:

use glerminal::{TerminalBuilder, TextBuffer, Parser};

// Initialize a terminal to use
let terminal = TerminalBuilder::new()
    .with_title("Parser example!")
    .with_dimensions((1280, 720))
    .build();

// Initialize a TextBuffer for the Parser
let mut text_buffer;
match TextBuffer::new(&terminal, (80, 24)) {
  Ok(buffer) => text_buffer = buffer,
  Err(error) => panic!(format!("Failed to initialize text buffer: {}", error)),
}

// Test Parser
let mut parser = Parser::new();
parser.add_color("red", [1.0, 0.0, 0.0, 1.0]);
parser.write(&mut text_buffer, "Hello, [fg=red]this color is red![/fg], [bg=red]this text has a red background[/bg] and [shake=0.5]this text shakes[/shake]");
// Note: it is not necessary to close fg/bg/shake tags, parser will automatically revert colors in the TextBuffer.

// Flush to "apply changes"
terminal.flush(&mut text_buffer);

Auto Trait Implementations

impl Send for Parser

impl Sync for Parser

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]