122 point_t srcPoint = {contentRect.
left, contentRect.
top + rowHeight};
169 backspaceChar->
chr =
' ';
179 for (
uint16_t i = 0; i < spacesToNextTabStop; i++)
188 currentChar->
chr = chr;
230 writefiles(
F(
"/proc/%llu/notegroup", term->
shell),
"interrupt due to ctrl+c");
244 switch (
ansi->command)
247 if (
ansi->parameters[0] == 25)
254 if (
ansi->parameters[0] == 25)
267 switch (
ansi->command)
270 if (
ansi->paramCount >= 2)
285 uint16_t startPos = cursorRow < moveBy ? 0 : cursorRow - moveBy;
313 if (
ansi->parameters[0] != 6)
322 int responseLen =
snprintf(response,
sizeof(response),
"\033[%d;%dR", cursorRow, cursorCol);
342 switch (
ansi->parameters[0])
345 startRow = cursorRow;
346 startCol = cursorCol;
366 for (
uint16_t row = startRow; row <= endRow; row++)
368 uint16_t colStart = (row == startRow) ? startCol : 0;
370 for (
uint16_t col = colStart; col <= colEnd; col++)
373 screenChar->
chr =
' ';
387 switch (
ansi->parameters[0])
405 for (
uint16_t col = startCol; col <= endCol; col++)
418 if (
ansi->paramCount != 1)
425 switch (
ansi->parameters[0])
463 term->
flags &= ~TERMINAL_ITALIC;
466 term->
flags &= ~TERMINAL_UNDERLINE;
469 term->
flags &= ~TERMINAL_BLINK;
472 term->
flags &= ~TERMINAL_INVERSE;
475 term->
flags &= ~TERMINAL_HIDDEN;
478 term->
flags &= ~TERMINAL_STRIKETHROUGH;
481 if (
ansi->parameters[0] >= 30 &&
ansi->parameters[0] <= 37)
485 else if (
ansi->parameters[0] == 39)
489 else if (
ansi->parameters[0] >= 90 &&
ansi->parameters[0] <= 97)
493 else if (
ansi->parameters[0] >= 40 &&
ansi->parameters[0] <= 47)
497 else if (
ansi->parameters[0] == 49)
501 else if (
ansi->parameters[0] >= 100 &&
ansi->parameters[0] <= 107)
522 int paramLen =
snprintf(paramStr,
sizeof(paramStr),
"%d",
ansi->parameters[i]);
523 for (
int j = 0; j < paramLen; j++)
534 for (
uint64_t i = 0; i < length; i++)
597 const char* argv[] = {
"/base/bin/shell",
NULL};
611 F(
"dup2 %d 0 && dup2 %d 1 && dup2 %d 2 && close 3 -1 && start", term->
stdin[0], term->
stdout[1],
641 writefiles(
F(
"/proc/%d/notegroup", term->
shell),
"terminate due to terminal close");
757 timeout = nextFrameTime - currentTime;
790 if (fds[0].revents &
POLLIN)
793 if (readCount ==
ERR || readCount == 0)
800 currentTime =
clock();
801 if (currentTime >= nextFrameTime)
#define MAX_NAME
Maximum length of names.
EFI_PHYSICAL_ADDRESS buffer
uint64_t font_width(const font_t *font, const char *string, uint64_t length)
void font_free(font_t *font)
font_t * font_new(display_t *disp, const char *family, const char *weight, uint64_t size)
uint64_t font_height(const font_t *font)
void display_disconnect(display_t *disp)
Disconnect the display connection.
uint64_t display_poll(display_t *disp, pollfd_t *fds, uint64_t nfds, clock_t timeout)
Poll the display connection for events together with other file descriptors.
uint64_t display_next(display_t *disp, event_t *event, clock_t timeout)
Retrieve the next event from the display connection.
void display_cmds_flush(display_t *disp)
Flush the display's command buffer.
uint64_t display_dispatch(display_t *disp, const event_t *event)
Dispatch an event to the appropriate surface.
void draw_string(drawable_t *draw, const font_t *font, const point_t *point, pixel_t pixel, const char *string, uint64_t length)
Draw a string.
void draw_rect(drawable_t *draw, const rect_t *rect, pixel_t pixel)
Draw a filled rectangle.
void draw_transfer(drawable_t *dest, drawable_t *src, const rect_t *destRect, const point_t *srcPoint)
Transfer pixels from one drawable to another.
theme_t * element_get_theme(element_t *elem)
Get the theme of an element.
void element_draw_end(element_t *elem, drawable_t *draw)
End drawing to an element.
rect_t element_get_content_rect(element_t *elem)
Get the element's rectangle in local coordinates.
void element_draw_begin(element_t *elem, drawable_t *draw)
Begin drawing to an element.
void element_set_private(element_t *elem, void *data)
Set private data for an element.
void * element_get_private(element_t *elem)
Get private data for an element.
@ KBD_PRESS
Key press event.
theme_t * theme_global_get(void)
Get the global theme.
uint64_t window_set_visible(window_t *win, bool isVisible)
Set the visibility of the window.
uint64_t window_invalidate_flush(window_t *win)
Flush invalidated rectangles to the DWM.
uint64_t window_set_timer(window_t *win, timer_flags_t flags, clock_t timeout)
Set the window timer.
window_t * window_new(display_t *disp, const char *name, const rect_t *rect, surface_type_t type, window_flags_t flags, procedure_t procedure, void *data)
Allocate and initialize a new window.
element_t * window_get_client_element(window_t *win)
Get the client element of the window.
void window_free(window_t *win)
Free a window.
display_t * window_get_display(window_t *win)
Get the display associated with the window.
@ WINDOW_DECO
Enable decorations (titlebar, close/minimize buttons, etc).
#define UNUSED(x)
Mark a variable as unused.
#define PIPE_READ
Pipe read end.
size_t writefiles(const char *path, const char *string)
Wrapper for writing a null-terminated string directly to a file using a path.
uint64_t close(fd_t fd)
System call for closing files.
#define F(format,...)
Allocates a formatted string on the stack.
size_t write(fd_t fd, const void *buffer, size_t count)
System call for writing to files.
size_t read(fd_t fd, void *buffer, size_t count)
System call for reading from files.
#define PIPE_WRITE
Pipe write end.
uint64_t open2(const char *path, fd_t fd[2])
System call for opening 2 file descriptors from one file.
@ POLLIN
File descriptor is ready to read.
pid_t spawn(const char **argv, spawn_flags_t flags)
System call for spawning new processes.
@ SPAWN_EMPTY_GROUP
Don't inherit the parent's process group, instead create a new group.
@ SPAWN_COPY_NS
Don't share the parent's namespace, instead create a new copy of it.
#define NULL
Pointer error value.
#define ERR
Integer error value.
__UINT64_TYPE__ clock_t
A nanosecond time.
static bool ansi_sending_parse(ansi_sending_t *ansi, char chr)
Parse a character for ANSI sending.
static void ansi_sending_init(ansi_sending_t *ansi)
Initialize an ANSI sending structure.
static void ansi_kbd_to_receiving(ansi_receiving_t *ansi, const event_kbd_t *kbd)
Convert a keycode to an ANSI receiving sequence.
void terminal_loop(window_t *win)
Terminal main loop.
#define TERMINAL_BLINK_INTERVAL
Terminal blink rate.
#define TERMINAL_COLUMNS
Terminal columns.
#define TERMINAL_MAX_DATA
Maximum size of the buffer used to batch data.
#define TERMINAL_MAX_FPS
Maximum terminal frames per second.
window_t * terminal_new(display_t *disp)
Create a new terminal window.
#define TERMINAL_ROWS
Terminal rows.
#define RECT_SHRINK(rect, margin)
#define RECT_INIT_DIM(x, y, width, height)
#define RECT_HEIGHT(rect)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
ANSI receiving structure.
char buffer[ANSI_MAX_LENGTH]
Opaque display structure.
Opaque element structure.
Poll file descriptor structure.
fd_t fd
The file descriptor to poll.
Terminal initialization context.
terminal_char_t * savedCursor
terminal_char_t * prevCursor
terminal_char_t screen[TERMINAL_ROWS][TERMINAL_COLUMNS]
pixel_t bright[THEME_ANSI_COLOR_COUNT]
pixel_t normal[THEME_ANSI_COLOR_COUNT]
static void terminal_put(terminal_t *term, element_t *elem, drawable_t *draw, char chr)
static void terminal_clear(terminal_t *term, element_t *elem, drawable_t *draw)
static rect_t terminal_char_rect(terminal_t *term, element_t *elem, terminal_char_t *termChar)
static terminal_char_t * terminal_get_char(terminal_t *term, uint16_t row, uint16_t col)
static uint64_t terminal_procedure(window_t *win, element_t *elem, const event_t *event)
static void terminal_char_draw(terminal_t *term, element_t *elem, drawable_t *draw, terminal_char_t *termChar)
static uint64_t terminal_pixel_width(font_t *font)
static void terminal_cursor_update(terminal_t *term, element_t *elem, drawable_t *draw)
static void terminal_scroll(terminal_t *term, element_t *elem, drawable_t *draw)
static void terminal_handle_input(terminal_t *term, element_t *elem, drawable_t *draw, const event_kbd_t *kbd)
static uint64_t terminal_pixel_height(font_t *font)
static void terminal_handle_output(terminal_t *term, element_t *elem, drawable_t *draw, const char *buffer, uint64_t length)
static point_t terminal_char_pos(terminal_t *term, element_t *elem, terminal_char_t *termChar)
static terminal_char_t terminal_char_create(char chr, pixel_t foreground, pixel_t background, uint16_t row, uint16_t col)
static void terminal_execute_ansi(terminal_t *term, element_t *elem, drawable_t *draw, ansi_sending_t *ansi)
static uint16_t terminal_char_row(terminal_t *term, terminal_char_t *termChar)
_PUBLIC clock_t clock(void)