Color theming

This commit is contained in:
Arthur Barraux
2026-01-22 14:00:47 +01:00
parent fa7f8d39d8
commit f3bd5dd1c9
15 changed files with 472 additions and 207 deletions
+16 -27
View File
@@ -1,13 +1,13 @@
/**
* @file output.c
* @brief Screen rendering and output module for the Beluga text editor
* @details Handles all screen updates, cursor positioning, status bar rendering,
* and display synchronization using ANSI escape sequences
* @details Handles all screen updates, cursor positioning, status bar
* rendering, and display synchronization using ANSI escape sequences
*/
#include "../include/output.h"
#include "../include/append_buffer.h"
#include "../include/syntax_highlighter.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -34,6 +34,7 @@ void editorDrawRows(struct abuf *ab) {
int file_row;
for (y = 0; y < E.screenrows; ++y) {
file_row = y + E.row_offset;
abAppend(ab, E.theme.BACKGROUND_COLOR, strlen(E.theme.BACKGROUND_COLOR));
if (file_row >= E.numrows) {
if (E.numrows == 0 && y == E.screenrows / 3) {
welcome_len =
@@ -60,10 +61,13 @@ void editorDrawRows(struct abuf *ab) {
len = 0;
if (len > E.screencols)
len = E.screencols;
char * highlighted = highlight_line(&E.row[file_row].render[E.col_offset], &E.row[file_row].rsize);
char *highlighted = highlight_line(&E.row[file_row].render[E.col_offset],
&E.row[file_row].rsize);
abAppend(ab, highlighted, E.row[file_row].rsize);
free(highlighted);
}
abAppend(ab, E.theme.BACKGROUND_COLOR, strlen(E.theme.BACKGROUND_COLOR));
abAppend(ab, ERASE_END_LINE, 3);
abAppend(ab, "\r\n", 2);
}
@@ -98,8 +102,9 @@ void editorScroll() {
/**
* @brief Renders the status bar at the bottom of the screen
* @details Displays filename, line count, dirty flag, and current cursor position
* in an inverted color bar. Right-aligns the cursor position indicator.
* @details Displays filename, line count, dirty flag, and current cursor
* position in an inverted color bar. Right-aligns the cursor position
* indicator.
* @param ab Pointer to append buffer structure for accumulating output
* @note Uses ANSI escape codes for color inversion
*/
@@ -150,9 +155,9 @@ void editorDrawMessageBar(struct abuf *ab) {
/**
* @brief Performs complete screen refresh and buffer synchronization
* @details Clears screen, redraws all visible content (rows, status bar, message bar),
* positions cursor, and writes accumulated buffer to stdout. This is the main
* rendering function called each frame.
* @details Clears screen, redraws all visible content (rows, status bar,
* message bar), positions cursor, and writes accumulated buffer to stdout. This
* is the main rendering function called each frame.
* @note Updates global editor state E (via editorScroll())
* @see editorDrawRows()
* @see editorDrawStatusBar()
@@ -163,9 +168,11 @@ void editorRefreshScreen() {
struct abuf ab = ABUF_INIT;
char buf[32];
abAppend(&ab, HIDE_CURSOR, 6);
abAppend(&ab, CURSOR_TOP_LEFT, 3);
editorDrawRows(&ab);
editorDrawStatusBar(&ab);
editorDrawMessageBar(&ab);
@@ -178,21 +185,3 @@ void editorRefreshScreen() {
write(STDOUT_FILENO, ab.b, ab.len);
abFree(&ab);
}
/**
* @brief Sets a temporary status message for display
* @details Formats and stores a message that will be displayed in the message bar
* for 5 seconds. Uses printf-style variable argument formatting.
* @param fmt Printf-style format string
* @param ... Variable arguments for format string
* @note Updates global editor state E (status_msg, status_msg_time)
* @see editorDrawMessageBar()
*/
void editorSetStatusMessage(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsnprintf(E.status_msg, sizeof(E.status_msg), fmt, ap);
va_end(ap);
E.status_msg_time = time(NULL);
}