-
Notifications
You must be signed in to change notification settings - Fork 7
lib_panda
panda is a terminal emulator kernel module supporting ANSI escape codes.
The file /dev/panda exists to have basic terminal interaction without
using the panda library.
8-bit color codes are used to set the color of the text. The color codes are
not the same as the ones used in the ANSI escape codes but the VGA-text mode
codes. The color codes have 4 bits for the background (0x00-0xF0) and 4 bits
for the foreground (0x00-0x0F).
0x00 - Black
0x01 - Blue
0x02 - Green
0x03 - Cyan
0x04 - Red
0x05 - Magenta
0x06 - Orange
0x07 - Light Grey
0x08 - Dark Grey
0x09 - Light Blue
0x0A - Light Green
0x0B - Light Cyan
0x0C - Light Red
0x0D - Light Magenta
0x0E - Yellow
0x0F - White
Panda can load psf fonts with
0x864ab572 magic number using the panda_change_font function.
If the font has more than 256 characters, the other characters will be ignored.
Panda supports some ANSI escape codes. The following codes are supported:
-
\e[2J- Clear screen -
\e[0m- Reset color -
\e[1m- Set text bold (bright), (\e[22mto disable) -
\e[4m- Set text underline (\e[24mto disable) -
\e[3*m- Set text color (* is the color) -
\e[4*m- Set background (* is the color) -
\e[9*m- Set text bright color (* is the color) -
\e[10*m- Set background bright color (* is the color) -
\e[H- Move cursor to top left -
\e[*A- Move cursor up (* is lines count) -
\e[*B- Move cursor down (* is lines count) -
\e[*C- Move cursor right (* is columns count) -
\e[*D- Move cursor left (* is columns count) -
\e[*;*H- Move cursor to line * and column * -
\e[J- Clear screen from cursor to end -
\e[1J- Clear screen from start to cursor -
\e[2J- Clear entire screen -
\e[K- Clear line from cursor to end -
\e[1K- Clear line from start to cursor -
\e[2K- Clear entire line -
\e[?25l- Hide cursor -
\e[?25h- Show cursor -
\e[s- Save cursor position -
\e[u- Restore cursor position
Set a character at a specific position on the screen,
void panda_print_char (
uint32_t x,
uint32_t y,
uint8_t c,
uint8_t color
);-
x: X position -
y: Y position -
c: Character -
color: Color
Note
For large character amounts, or frequent refreshes, it is recommended to use panda_print_raw to update the entire screen at once for better performance.
Displays the characters in the buffer on the screen, starting from the top left, by horizontal line. If the given buffer is too small to fill the entire screen, the end of the screen will remain unchanged.
typedef struct {
uint16_t color;
char content;
} panda_char_t;
void panda_print_raw(
panda_char_t *buffer,
uint32_t length
);-
buffer: Buffer containing the characters to display -
length: Length of the buffer in characters
Note
The buffer must contain width * height characters to fill the entire screen.
You can get the screen size with panda_get_size.
Note
The cursor position is not changed by this function, but it can be erased if a character is printed at the cursor position.
Print a string at the current cursor position with ansi support.
If the length is less than 0, the function will print characters until it finds
a null character.
The temporary color is used to print the string with a different color than the
current one, if the color is -1, the current color will be used.
uint8_t panda_print_string (
const char *string,
int len,
int tmp_color,
uint8_t default_color
);-
string: String to print -
len: Length of the string -
tmp_color: Temporary color -
default_color: Color of\e[0m - Returns: The last color used
Function used at boot to avoid writing over the kernel messages. You probably don't need to use this function.
void panda_set_start (
int kernel_cursor
);-
kernel_cursor: Cursor position
Get the screen size or set to zero if panda is not initialized.
void panda_get_size (
uint32_t *x,
uint32_t *y
);-
x: Pointer to the x size -
y: Pointer to the y size
Save the current cursor position in tow variables.
void panda_get_cursor(
uint32_t *x,
uint32_t *y
);-
x: Pointer to the x position -
y: Pointer to the y position
Draw the cursor at given position, the old cursor will be erased.
void panda_draw_cursor (
uint32_t x,
uint32_t y
);-
x: X position -
y: Y position
Change the font of the terminal.
int panda_change_font (
const char *font
);-
font: Font path - Returns: 0 on success, 1 on failure
Generate a backup of the screen, the function will allocate memory for the backup and return a pointer to it. You need to free the memory with panda_screen_free.
void *panda_screen_backup (void);- Returns: Pointer to the backup
Restore the screen from a backup (does not free the backup).
void panda_screen_restore (
void *backup
);-
backup: Pointer to the backup
Free the memory allocated by panda_screen_backup.
void panda_screen_free (
void *backup
);-
backup: Pointer to the backup