PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
terminal.h
Go to the documentation of this file.
1#pragma once
2
3#include "ansi.h"
4
6#include <stdint.h>
7#include <sys/io.h>
8#include <sys/kbd.h>
9#include <threads.h>
10
11/**
12 * @brief Terminal Program.
13 * @defgroup programs_terminal Terminal
14 * @ingroup programs
15 *
16 * A simple terminal emulator program.
17 *
18 * The terminal always acts in raw mode, meaning that it does not process any input itself, instead it just sends all
19 * input directly to the shell program running inside it.
20 *
21 * @see [Terminals OSDev Wiki](https://wiki.osdev.org/Terminals)
22 * @see [ANSI Escape Codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797)
23 *
24 * @{
25 */
26
27/**
28 * @brief Terminal blink rate.
29 */
30#define TERMINAL_BLINK_INTERVAL (CLOCKS_PER_SEC / 2)
31
32/**
33 * @brief Terminal columns.
34 */
35#define TERMINAL_COLUMNS 80
36
37/**
38 * @brief Terminal rows.
39 */
40#define TERMINAL_ROWS 30
41
42/**
43 * @brief Maximum size of the buffer used to batch data.
44 */
45#define TERMINAL_MAX_DATA (TERMINAL_COLUMNS * TERMINAL_ROWS)
46
47/**
48 * @brief Maximum terminal frames per second.
49 *
50 * The terminal will batch any data received within a "frame" and only actually flush the data at the end of the frame.
51 */
52#define TERMINAL_MAX_FPS 30
53
54/**
55 * @brief Terminal flags.
56 * @enum terminal_flags_t
57 *
58 * Used for the ANSI state machine and character attributes.
59 */
60typedef enum
61{
63 TERMINAL_BOLD = (1 << 0),
64 TERMINAL_DIM = (1 << 1),
65 TERMINAL_ITALIC = (1 << 2),
67 TERMINAL_BLINK = (1 << 4),
68 TERMINAL_INVERSE = (1 << 5),
69 TERMINAL_HIDDEN = (1 << 6),
70 TERMINAL_STRIKETHROUGH = (1 << 7)
72
73/**
74 * @brief Terminal character.
75 * @struct terminal_char_t
76 */
86
87/**
88 * @brief Terminal structure.
89 * @struct terminal_t
90 */
110
111/**
112 * @brief Terminal initialization context.
113 * @struct terminal_init_ctx_t
114 *
115 * Used while creating the window to pass in the font to use.
116 */
117typedef struct
118{
121
122/**
123 * @brief Create a new terminal window.
124 *
125 * @param disp The display to create the window on.
126 * @return On success, the terminal window. On failure, `NULL` and `errno` is set.
127 */
129
130/**
131 * @brief Terminal main loop.
132 *
133 * @param win The terminal window.
134 */
135void terminal_loop(window_t* win);
136
137/** @} */
__UINT64_TYPE__ fd_t
A file descriptor.
Definition fd_t.h:12
__UINT64_TYPE__ pid_t
Process Identifier.
Definition pid_t.h:11
void terminal_loop(window_t *win)
Terminal main loop.
Definition terminal.c:727
terminal_flags_t
Terminal flags.
Definition terminal.h:61
#define TERMINAL_COLUMNS
Terminal columns.
Definition terminal.h:35
window_t * terminal_new(display_t *disp)
Create a new terminal window.
Definition terminal.c:699
#define TERMINAL_ROWS
Terminal rows.
Definition terminal.h:40
@ TERMINAL_DIM
Definition terminal.h:64
@ TERMINAL_STRIKETHROUGH
Definition terminal.h:70
@ TERMINAL_BLINK
Definition terminal.h:67
@ TERMINAL_ITALIC
Definition terminal.h:65
@ TERMINAL_NONE
Definition terminal.h:62
@ TERMINAL_UNDERLINE
Definition terminal.h:66
@ TERMINAL_HIDDEN
Definition terminal.h:69
@ TERMINAL_INVERSE
Definition terminal.h:68
@ TERMINAL_BOLD
Definition terminal.h:63
static log_screen_t screen
Definition log_screen.c:12
uint32_t pixel_t
Definition pixel.h:11
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
FILE * stdout
Definition std_streams.c:18
FILE * stdin
Definition std_streams.c:17
ANSI sending structure.
Definition ansi.h:139
Opaque display structure.
Definition internal.h:61
Terminal character.
Definition terminal.h:78
pixel_t foreground
Definition terminal.h:80
pixel_t background
Definition terminal.h:81
uint16_t col
Definition terminal.h:83
uint16_t physicalRow
Definition terminal.h:84
terminal_flags_t flags
Definition terminal.h:82
Terminal initialization context.
Definition terminal.h:118
Terminal structure.
Definition terminal.h:92
pixel_t background
Definition terminal.h:100
terminal_char_t * savedCursor
Definition terminal.h:105
terminal_char_t * prevCursor
Definition terminal.h:106
terminal_flags_t flags
Definition terminal.h:101
font_t * font
Definition terminal.h:94
window_t * win
Definition terminal.h:93
pid_t shell
Definition terminal.h:108
bool isCursorVisible
Definition terminal.h:96
pixel_t foreground
Definition terminal.h:99
bool cursorBlink
Definition terminal.h:95
uint64_t firstRow
Definition terminal.h:104
ansi_sending_t ansi
Definition terminal.h:102
terminal_char_t * cursor
Definition terminal.h:107
Opaque window structure.
Definition internal.h:44