Expand description
§Introduction
GLerminal is an OpenGL Terminal that is both easy to use and lightweight!
This crate consists of two major parts that are exposed to the user:
Also see Features list to see what other exciting features exist.
Starting with a simple example might be wise though;
After that you should browse through the rest of this guide and read about terminal and text_buffer documentations respectively
§Example
use glerminal::{TerminalBuilder, TextBuffer};
fn main() {
let terminal = TerminalBuilder::new()
.with_title("Hello GLerminal!")
.with_dimensions((1280, 720))
.build();
let mut text_buffer;
match TextBuffer::create(&terminal, (80, 24)) {
Ok(buffer) => text_buffer = buffer,
Err(error) => panic!(format!("Failed to initialize text buffer: {}", error)),
}
text_buffer.write("Hello, GLerminal!");
terminal.flush(&mut text_buffer);
while terminal.refresh() {
terminal.draw(&text_buffer);
}
}§terminal
Terminal (and TerminalBuilder) will be the first struct(s) that you’ll have to deal with:
TerminalBuilder is used to build the terminal, and Terminal is used as sort of a ‘window’ or ‘canvas’ for everything else, like the TextBuffer.
The Terminal is able to change the title of the screen with .set_title,
get events with .get_current_events, draw the latest flush with .draw
or (like mentioned earlier), flush the TextBuffer with .flush.
Examples can be found at Terminal struct.
§text_buffer
TextBuffer is the struct that will be used the most.
With this struct you will be writing, clearing and changing colors of the text you are writing, for example.
Another important struct that you might be using however, is the Parser.
With this struct you can simply pass a string that the parser will parse, and the TextBuffer will then change colors or shakiness of your text accordingly.
Examples can be found at TextBuffer struct.
§Features
There are two features for Glerminal that can be enabled (or disabled) to enable or disable wanted features.
| Feature name | What it enables |
|---|---|
| parser (on by default) | enables the Praser struct. |
| menu_systems | enables the menu_systems module. |
Modules§
- menu_
systems - Menu systems is a module that allows easy creation and usage of
Menus. Examples of what a menu can be, is ncurses. - text_
processing - Text Processor is a trait that can be used in places where processing text may be necessary,
for example if using a
parseris optional.
Macros§
- with_
base - If you’re creating a struct that has
InterfaceItemBase, callingwith_base!(Struct)within the impl-call can be useful. This will add two useful functions for setting initial values forInterfaceItemBase
Structs§
- Character
Data - Contains data of a single character in a Font
- Cursor
- Cursor has the ability to get the position in the text buffer where the cursor currently is.
- Events
- Represents all the events that happen in glerminal, such as keyboard events, mouse events, resize, and close events.
- Font
- The Font is used to load fonts that can be used in the
TextBuffer - Input
- Input contains the necessary infoamtions to satisfy all your binary input-gathering needs!
- Parser
- Represents a parser (A
TextProcessor), that is able to read given texts and useTextBufferaccordingly, to write text and styles matching to the text. - Term
Character - Represents a single character in a
TextBuffer - Term
Cursor - The cursor on the TextBuffer that you can move around and change it’s style.
Determines where and with what style the TextBuffer writes characters - Term
Limits - Represents the limits of the terminal.
- Terminal
- The Terminal acts as the window and “canvas” of the terminal, handling most behind-the-sceneries
- Terminal
Builder - A builder for the
Terminal. Includes some settings that can be set before building. - Text
Buffer - The
TextBufferacts as a “state machine” where you can set foreground color, background color and shakiness for the cursor, move the cursor around, clear the screen and write with the cursor (using the cursor’s styles) (throughTermCursor), put, get characters or write strings.
It’s often the most efficient way to write things, especially if you have a very structured way of displaying things, but for a more simple-to-use way of writing, that isn’t as structured ie. for a dialogue, you might want to use the Parser. - Text
Style - Represents a style that can be used to style text.
Enums§
- Font
Format - Specifies the type of file format which the font file uses.
- Mouse
Button - Describes a button of a mouse controller.
- Virtual
KeyCode - Symbolic name for a keyboard key.
Type Aliases§
- Color
- Represents a color with values from 0.0 to 1.0 (red, green, blue, alpha)