BEEP-8 Helper Lib 1.0.0
|
Module for decoding and handling ANSI escape sequences. More...
#include <b8/type.h>
Go to the source code of this file.
Classes | |
struct | EscapeOut |
class | CEscapeSeqDecoder |
Enumerations | |
enum | EscapePAL { PAL_0 , PAL_1 , PAL_2 , PAL_3 } |
Enumeration for selecting a palette in the terminal. More... | |
enum | EscapeSeqOpe { ESO_ONE_CHAR , ESO_UP , ESO_DOWN , ESO_RIGHT , ESO_LEFT , ESO_DEL , ESO_MOVE_CURSOR , ESO_SEL_PAL , ESO_SET_COLOR , ESO_CLEAR_SCREEN_FROM_CURSOR_DOWN , ESO_CLEAR_SCREEN_FROM_CURSOR_UP , ESO_CLEAR_ENTIRE_SCREEN , ESO_CLEAR_LINE_FROM_CURSOR_RIGHT , ESO_CLEAR_LINE_FROM_CURSOR_LEFT , ESO_CLEAR_ENTIRE_LINE , ESO_ENABLE_SHADOW , ESO_DISABLE_SHADOW , ESO_SET_Z , ESO_NONE } |
Enumeration for escape sequence operations. More... | |
enum | AnsiColor { ANSI_NULL = 0 , ANSI_COLOR_BLACK = 30 , ANSI_COLOR_RED , ANSI_COLOR_GREEN , ANSI_COLOR_YELLOW , ANSI_COLOR_BLUE , ANSI_COLOR_MAGENTA , ANSI_COLOR_CYAN , ANSI_COLOR_WHITE , ANSI_COLOR_BLACK_BG = 40 , ANSI_COLOR_RED_BG , ANSI_COLOR_GREEN_BG , ANSI_COLOR_YELLOW_BG , ANSI_COLOR_BLUE_BG , ANSI_COLOR_MAGENTA_BG , ANSI_COLOR_CYAN_BG , ANSI_COLOR_WHITE_BG , ANSI_COLOR_B8_BLACK = 50 , ANSI_COLOR_B8_DARK_BLUE , ANSI_COLOR_B8_DARK_PURPLE , ANSI_COLOR_B8_DARK_GREEN , ANSI_COLOR_B8_BROWN , ANSI_COLOR_B8_DARK_GREY , ANSI_COLOR_B8_LIGHT_GREY , ANSI_COLOR_B8_WHITE , ANSI_COLOR_B8_RED , ANSI_COLOR_B8_ORANGE , ANSI_COLOR_B8_YELLOW , ANSI_COLOR_B8_GREEN , ANSI_COLOR_B8_BLUE , ANSI_COLOR_B8_LAVENDER , ANSI_COLOR_B8_PINK , ANSI_COLOR_B8_LIGHT_PEACH , ANSI_COLOR_B8_BLACK_BG = 70 , ANSI_COLOR_B8_DARK_BLUE_BG , ANSI_COLOR_B8_DARK_PURPLE_BG , ANSI_COLOR_B8_DARK_GREEN_BG , ANSI_COLOR_B8_BROWN_BG , ANSI_COLOR_B8_DARK_GREY_BG , ANSI_COLOR_B8_LIGHT_GREY_BG , ANSI_COLOR_B8_WHITE_BG , ANSI_COLOR_B8_RED_BG , ANSI_COLOR_B8_ORANGE_BG , ANSI_COLOR_B8_YELLOW_BG , ANSI_COLOR_B8_GREEN_BG , ANSI_COLOR_B8_BLUE_BG , ANSI_COLOR_B8_LAVENDER_BG , ANSI_COLOR_B8_PINK_BG , ANSI_COLOR_B8_LIGHT_PEACH_BG , ANSI_COLOR_BRIGHT_BLACK = 90 , ANSI_COLOR_BRIGHT_RED , ANSI_COLOR_BRIGHT_GREEN , ANSI_COLOR_BRIGHT_YELLOW , ANSI_COLOR_BRIGHT_BLUE , ANSI_COLOR_BRIGHT_MAGENTA , ANSI_COLOR_BRIGHT_CYAN , ANSI_COLOR_BRIGHT_WHITE , ANSI_COLOR_BRIGHT_BLACK_BG = 100 , ANSI_COLOR_BRIGHT_RED_BG , ANSI_COLOR_BRIGHT_GREEN_BG , ANSI_COLOR_BRIGHT_YELLOW_BG , ANSI_COLOR_BRIGHT_BLUE_BG , ANSI_COLOR_BRIGHT_MAGENTA_BG , ANSI_COLOR_BRIGHT_CYAN_BG , ANSI_COLOR_BRIGHT_WHITE_BG } |
Enumeration for ANSI color codes. More... | |
Functions | |
void | EscClearEntireScreen (FILE *fp) |
Clears the entire screen. | |
void | EscMoveCursor (FILE *fp, s32 x_, s32 y_) |
Moves the cursor to a specific position. | |
Module for decoding and handling ANSI escape sequences.
This module is intended for device driver developers and is not meant to be used directly by general users.
This module provides functionality for decoding escape sequences using the CEscapeSeqDecoder
class and associated functions. Escape sequences are special strings used primarily for terminal display control, such as moving the cursor, clearing the screen, or modifying text appearance.
CEscapeSeqDecoder
ClassThe CEscapeSeqDecoder
class contains an internal state machine that decodes escape sequences and outputs the resulting operation and parameters using the EscapeOut
structure.
Here is a comprehensive set of examples demonstrating the use of various escape sequences supported by this module:
(x, y)
.J
and K
commands control clearing of the screen or lines.m
command modifies text attributes and colors (bold, foreground, background).CEscapeSeqDecoder
ClassThe CEscapeSeqDecoder
class manages the decoding process through a state machine defined by the EscState
enumeration. It tracks the current state of the decoder and processes each character in the escape sequence to determine the appropriate action. The parsed operations are stored in the EscapeOut
structure.
Stream
method processes each character and handles transition between states such as ES_0x1b
(Escape), ES_0x5b
(CSI), and other custom states for handling sequences like palette selection.\e[attr;fg;bgm
where:attr
: Text attributes (e.g., 0=Reset
, 1=Bold
).fg
: Foreground color (e.g., 37=White
).bg
: Background color (e.g., 44=Blue
).\e[x;yH
for moving the cursor to a specific position.EscapeOut
)The EscapeOut
structure stores the result of decoding an escape sequence:
_code
: The last processed character._Ope
: The operation determined by the escape sequence._fg
: The foreground color._bg
: The background color._x
, _y
: Cursor positions for movement commands._EscapePAL
: The selected palette for custom palette handling.EscClearEntireScreen
: Clears the entire screen.EscMoveCursor
: Moves the cursor to a specific position (x, y)
.This module provides a robust system for decoding and handling ANSI escape sequences in terminal environments. It supports cursor movement, text color and attribute manipulation, screen and line clearing, and custom palette selection. The state machine-based parser efficiently processes complex sequences and outputs the necessary operations in a structured format.
enum AnsiColor |
Enumeration for ANSI color codes.
The AnsiColor
enumeration defines the standard and high-intensity colors used in ANSI escape sequences. The values correspond to the codes used to set foreground and background colors in terminal environments.
enum EscapePAL |
Enumeration for selecting a palette in the terminal.
The EscapePAL
enumeration represents the available palettes that can be selected using escape sequences. The values range from PAL_0
to PAL_3
, corresponding to different palettes in the system.
Enumerator | |
---|---|
PAL_0 | Palette 0. |
PAL_1 | Palette 1. |
PAL_2 | Palette 2. |
PAL_3 | Palette 3. |
enum EscapeSeqOpe |
Enumeration for escape sequence operations.
The EscapeSeqOpe
enumeration defines the various operations that can be parsed and executed from escape sequences, such as moving the cursor, clearing the screen, or setting text colors and attributes.
|
extern |
Clears the entire screen.
This function sends an escape sequence to clear the entire screen in the terminal. It uses the \033[2J
escape sequence to perform this operation.
fp | A pointer to a FILE stream (typically stdout). |
|
extern |
Moves the cursor to a specific position.
This function sends an escape sequence to move the cursor to a specific position in the terminal. It uses the \033[y;xH
escape sequence where y and x are the row and column coordinates, respectively.
fp | A pointer to a FILE stream (typically stdout). |
x_ | The column number (1-based). |
y_ | The row number (1-based). |