OS Terminal
A no_std
terminal library for embedded systems and OS kernels.
The environment should have initialized global_allocator
since alloc
crate is used for dynamic memory allocation.
Screenshot
This screenshot shows the result of running fastfetch
in the example terminal. You can try it by running cargo run --release --example terminal --features=truetype
(Linux only). It will execute bash
by default.
Features
- Embedded smooth noto sans mono font rendering
- Truetype font support
- VT100 and part of xterm escape sequence support
- Beautiful color scheme
- Cursor display and shape control
Usage
Create a display wrapper to wrap your framebuffer and implement the DrawTarget
trait for it.
use Box;
use ;
use BitmapFont;
Then you can create a terminal with a box-wrapped font manager.
let mut terminal = new;
terminal.set_font_manager;
Now you can redirect the keyboard events to the terminal in scancode format (currently only Scan Code Set1 and North American standard English keyboard layout are supported) to let the terminal process shortcuts or get escaped strings so you can pass it to your shell.
// LCtrl pressed, C pressed, C released, LCtrl released
let scancodes = ;
for scancode in scancodes.iter
And then you can advance the terminal state with the escaped string from the output of your shell.
terminal.advance_state;
terminal.write_fmt;
To use truetype font, enable truetype
feature and create a TrueTypeFont
instance from a font file with size.
let font_buffer = include_bytes!;
terminal.set_font_manager;
Notice that you are supposed to use a variable-font-supported ttf file otherwise font weight will not change.
Italic font support is also optional. If not provided, it will be rendered with default Roman font.
let font_buffer = include_bytes!;
let italic_buffer = include_bytes!;
let font_manager = new.with_italic_font;
terminal.set_font_manager;
If you want to get the logs from the terminal, you can set a logger that receives fmt::Arguments
.
;
set_logger
Default flush strategy is synchronous. If you need higher performance, you can disable the auto flush and flush manually when needed.
terminal.set_auto_flush;
terminal.flush;
The terminal comes with 8 built-in themes. You can switch to other themes manually by calling terminal.set_color_scheme(index)
.
Custom theme is also supported:
let palette = Palette
terminal.set_custom_color_scheme;
Note that this setting is temporary and you will need to re-execute
set_custom_color_scheme
if you switch to another theme.
Default history size is 200
lines. You can change it by calling terminal.set_history_size(size)
.
You can use terminal.set_bell_handler(handler)
to set the bell handler so that when you type unicode(7)
such as Ctrl + G
, the terminal will call the handler to play the bell.
Shortcuts
With handle_keyboard
, some shortcuts are supported:
Ctrl + Shift + F1-F8
: Switch to different built-in themesCtrl + Alt + ArrowUp/ArrowDown
: Scroll up/down historyCtrl + Alt + PageUp/PageDown
: Scroll up/down history by page
Features
bitmap
: Enable embedded noto sans mono bitmap font support. This feature is enabled by default.truetype
: Enable truetype font support. This feature is disabled by default.
Acknowledgement
- embedded-term: This project is a fork of it with some simplifications and improvements.
- alacritty: General reference for the terminal implementation.
- noto-sans-mono-bitmap-rs: Pre-rasterized smooth characters.
Thanks to the original author and contributors for their great work.