Struct Terminal

Source
pub struct Terminal {
    pub window: PistonWindow,
    pub bg_color: Color,
    pub fg_color: Color,
    pub scanlines: bool,
    pub font_size: FontSize,
    pub art_font_size: FontSize,
    /* private fields */
}
Expand description

A terminal stores a PistonWindow, background and foreground colors, a font, fontsize, and glyph cache, and the current message and input strings.

Fields§

§window: PistonWindow

The window that displays our terminal.

§bg_color: Color

The background color of our terminal.

§fg_color: Color

The foreground color of our terminal.

§scanlines: bool

Whether or not to use scanlines

§font_size: FontSize

The font size of normal text in our terminal.

§art_font_size: FontSize

The font size of art in our terminal.

Implementations§

Source§

impl Terminal

Source

pub fn new( title: &str, size: (u32, u32), bg: Color, fg: Color, font: &str, font_size: u32, ) -> Terminal

Creates a new window with the given title, colors, and font info

let mut term: Terminal = Terminal::new("simpleterm test", (800, 600), DARK_GREY, GOLD, "LeagueSpartan-Regular.ttf", 32);
Source

pub fn ask(&mut self, message: &str) -> Option<String>

Types out the given message, then waits for the user to type something and returns Some(input string). If the window is closed before input can be returned, returns None.

let user_input: String = term.ask("This will wait for the user enter input!").unwrap();
Source

pub fn display_art(&mut self, art: &str, time: Duration)

Displays an ascii art string centered on the terminal. This uses 10pt font and a monospace font.

term.display_art(GEO, Duration::from_secs(2));
Source

pub fn show(&mut self, message: &str, time: Duration)

Types out the given message, then waits for the given amount of time to continue.

term.show("This will wait for 1 second!", Duration::from_secs(1));
Source

pub fn tell(&mut self, message: &str)

Types out the given message, then waits for the user to press Enter to continue.

term.tell("This will wait for the user to hit enter!");
Source

pub fn resize(&mut self, new_size: Size)

Closes the current window and creates a new one with the given (x, y) Size.

term.resize((800, 600).into());
Source

pub fn set_font(&mut self, font: &str, size: FontSize)

Loads a new font from the given font filename and sets the given font size

term.set_font("LeagueSpartan-Regular.ttf", 24);
Source

pub fn set_art_font(&mut self, font: &str, size: FontSize)

Loads a new art font from the given font filename and sets the given font size. You probably want to use a mono-space font here, and a small size.

The default is LeagueMono-Regular.ttf at 10pt.

term.set_art_font("LeagueMono-Regular.ttf", 10);
Source

pub fn set_colors(&mut self, bgc: Color, fgc: Color)

Changes the terminal’s background and foreground to the given colors. The change will be apparent in the next text command.

term.set_colors(DARK_GREY, CRIMSON);

Auto Trait Implementations§

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> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
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.