HomeManualTopicsTypesSymbols

Terminal

Description

The terminal library offers an interface for using text-terminals in a comfortable way.

The base data type is the std_types::screen, a rectangular array of characters and associated fore- and background colors.

All coordinates are one-based.

Each colour supports 256 shades of red, green and blue.

To update the state of a std_types::screen or std_types::terminal) no I/O-acccess rights are necessary.

There are methods to set fore- and background colors, to draw text, lines or more complex shapes, to clear the screen or parts of it, to scroll the screen or copy arbitrary rectangular areas between screens ("blitting").

Horizontal and vertical lines are drawn using the appropriate unicode graphics characters.

Screens and terminals also support Unicode Emojis.

The terminal library is somewhat similar to the curses library. It tries to update the contents of a terminal in a smart way.

To start using the functions of this library one must first create a std_types::terminal object (see std::create_terminal) supplying the terminal's width and height. The current terminal size can be retrieved via the I/O-function std::get_terminal_size.

As an alternative one can use the high-level function std::initialize_terminal. When using this function one gets automatic cleanup "for free".

For more details about colour handling see Colours.

Example

<require basic/stdlib> <require terminal/terminal> get_terminal_size! STDIN_FILENO $width $height create_terminal $terminal width height draw_text &terminal 10 5 "Hello, world!" update_terminal &terminal $output # create output character stream print! output # print the generated character stream

Example

<require basic/stdlib> <require terminal/terminal> initialize_terminal!: (terminal) draw_text &terminal 10 5 "Hello, world!" update_terminal &terminal $output # create output character stream print! output # print the generated character stream

Topic

Terminal

See also

Input-Output
Colours
std::BACKGROUND_COLOUR the background colour option used in and
std::LINE_HEIGHT the line height option used in and
std::TEXT_COLOUR the text colour option used in and
std::VISIBLE_CURSOR the option to make the cursor visible in
std::background_colour_at returns the background colour at the specified position of the screen
std::character_at returns the character at the specified position of the screen
std::clear_screen clears the terminal screen and moves the cursor to the top-left position
std::colour_mixture constructs a colour (character) from a mixture of the specified colours
std::create_screen creates a logical screen
std::create_terminal must be called before any other terminal function
std::cursor_home moves the cursor to the top-left position
std::cursor_off turns the terminal cursor off
std::cursor_on turns the terminal cursor on
std::define_window defines a rectangular area as the current drawing area
std::draw_attributed_text draws text with given fore- and background colours
std::draw_character draws a character at the given position
std::draw_line draws a horizontal or vertical line
std::draw_rectangle draws a rectangle
std::draw_text draws text at the given position
std::get_terminal_size retrieves the current width and height of the specified terminal
std::initialize_terminal creates a terminal object for the given input file descriptor
std::resize resizes a screen or terminal
std::restore_colours set default colours for text and background
std::rgb_character constructs a colour (character) from its primary colours
std::rows_and_columns returns the number of rows and the width of the longest row in the text
std::set_background_colour_at sets the background colour at the given position
std::set_character_at sets the character at the given position
std::set_text_colour_at sets the foreground color at the given position
std::text_colour_at returns the text colour at the specified position of the screen
std::update_terminal create a command sequence to update the terminal
std_types::character/std::blue_component_of returns the blue component of the colour (character)
std_types::character/std::green_component_of returns the green component of the colour (character)
std_types::character/std::red_component_of returns the red component of the colour (character)
std_types::screen the prototype objects for all screens
std_types::screen.std::serialization_fields_of the serialized fields of a object
std_types::screen.std::serialization_tag_of the tag used to serialize a object
std_types::screen/std::clear clears the specified rectangular area
std_types::screen/std::copy copies a rectangular area from one screen to another
std_types::screen/std::define_window defines a rectangular drawing area
std_types::screen/std::draw_attributed_text draw the specified attributed text at the current screen position
std_types::screen/std::draw_character draws a character at the current screen position
std_types::screen/std::draw_line draws a horizontal or vertical line
std_types::screen/std::draw_rectangle draws a rectangle
std_types::screen/std::draw_text draw the specified text at the current screen position
std_types::screen/std::fill_trapezoid draws a filled trapezoid (without borders)
std_types::screen/std::plot plots a half character block
std_types::screen/std::plot_line plots a line consisting of half character blocks
std_types::screen/std::resize resizes a screen
std_types::screen/std::scroll_down scrolls the contents of the *screen* downwards
std_types::screen/std::scroll_left scrolls the contents of the *screen* leftwards
std_types::screen/std::scroll_right scrolls the contents of the *screen* rightwards
std_types::screen/std::scroll_up scrolls the contents of the *screen* upwards
std_types::screen/std::set_background_colour sets the background colour to be used
std_types::screen/std::set_text_colour sets the colour to be used for drawing text or lines
std_types::terminal the prototype objects for all terminals
std_types::terminal.std::serialization_fields_of the serialized fields of a object
std_types::terminal.std::serialization_tag_of the tag used to serialize a object
std_types::terminal/std::resize resizes the terminal