ANSI+GitHub Workflow

This commit is contained in:
2026-04-14 20:46:26 +08:00
parent 91a975ad6c
commit f18c221159
3 changed files with 677 additions and 91 deletions

56
.github/workflows/build-os.yml vendored Normal file
View File

@@ -0,0 +1,56 @@
name: Build CLeonOS
on:
push:
pull_request:
permissions:
contents: read
jobs:
build-os:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
git \
tar \
xorriso \
clang \
lld \
llvm \
autoconf \
automake \
libtool \
pkg-config \
nasm
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Configure
run: |
cmake -S . -B build-cmake \
-DCMAKE_BUILD_TYPE=Release \
-DNO_COLOR=1 \
-DLIMINE_REPO=https://github.com/limine-bootloader/limine.git
- name: Build ISO
run: cmake --build build-cmake --target iso -- -j"$(nproc)"
- name: Upload ISO Artifact
uses: actions/upload-artifact@v4
with:
name: cleonos-iso
path: build/CLeonOS-x86_64.iso
if-no-files-found: error

View File

@@ -116,6 +116,7 @@ static int ush_cmd_help(void) {
ush_writeln(" cd [dir]"); ush_writeln(" cd [dir]");
ush_writeln(" exec|run <path|name>"); ush_writeln(" exec|run <path|name>");
ush_writeln(" clear"); ush_writeln(" clear");
ush_writeln(" ansi / ansitest / color");
ush_writeln(" memstat / fsstat / taskstat / userstat / shstat / stats"); ush_writeln(" memstat / fsstat / taskstat / userstat / shstat / stats");
ush_writeln(" tty [index]"); ush_writeln(" tty [index]");
ush_writeln(" dmesg [n]"); ush_writeln(" dmesg [n]");
@@ -677,6 +678,128 @@ static int ush_cmd_ansi(void) {
return 1; return 1;
} }
static u64 ush_ansitest_u64_to_dec(char *out, u64 out_size, u64 value) {
char rev[10];
u64 digits = 0ULL;
u64 i;
if (out == (char *)0 || out_size == 0ULL) {
return 0ULL;
}
if (value == 0U) {
if (out_size < 2ULL) {
return 0ULL;
}
out[0] = '0';
out[1] = '\0';
return 1ULL;
}
while (value > 0U && digits < (u64)sizeof(rev)) {
rev[digits++] = (char)('0' + (value % 10U));
value /= 10U;
}
if (digits + 1ULL > out_size) {
out[0] = '\0';
return 0ULL;
}
for (i = 0ULL; i < digits; i++) {
out[i] = rev[digits - 1ULL - i];
}
out[digits] = '\0';
return digits;
}
static void ush_ansitest_emit_bg256(u64 index) {
char num[4];
char seq[24];
u64 digits;
u64 p = 0ULL;
u64 i;
if (index > 255U) {
index = 255U;
}
digits = ush_ansitest_u64_to_dec(num, (u64)sizeof(num), index);
if (digits == 0ULL) {
return;
}
seq[p++] = '\x1B';
seq[p++] = '[';
seq[p++] = '4';
seq[p++] = '8';
seq[p++] = ';';
seq[p++] = '5';
seq[p++] = ';';
for (i = 0ULL; i < digits && p + 1ULL < (u64)sizeof(seq); i++) {
seq[p++] = num[i];
}
if (p + 7ULL >= (u64)sizeof(seq)) {
return;
}
seq[p++] = 'm';
seq[p++] = ' ';
seq[p++] = ' ';
seq[p++] = '\x1B';
seq[p++] = '[';
seq[p++] = '0';
seq[p++] = 'm';
seq[p] = '\0';
ush_write(seq);
}
static int ush_cmd_ansitest(void) {
u64 i;
ush_writeln("\x1B[1;96mANSI test suite\x1B[0m");
ush_writeln("styles: \x1B[1mbold\x1B[0m \x1B[7minverse\x1B[0m \x1B[4munderline\x1B[0m");
ush_writeln("16-color demo:");
(void)ush_cmd_ansi();
ush_writeln("256-color palette (0..255):");
for (i = 0ULL; i < 256ULL; i++) {
ush_ansitest_emit_bg256(i);
if ((i % 32ULL) == 31ULL) {
ush_write_char('\n');
}
}
ush_write_char('\n');
ush_writeln("truecolor demo:");
ush_writeln(" \x1B[38;2;255;64;64mRGB(255,64,64)\x1B[0m \x1B[38;2;64;255;64mRGB(64,255,64)\x1B[0m \x1B[38;2;64;128;255mRGB(64,128,255)\x1B[0m");
ush_writeln("cursor control demo:");
ush_write(" 0123456789");
ush_write("\x1B[5D");
ush_write("\x1B[93m<OK>\x1B[0m");
ush_write_char('\n');
ush_write(" save");
ush_write("\x1B[s");
ush_write("....");
ush_write("\x1B[u");
ush_write("\x1B[92m<restore>\x1B[0m");
ush_write_char('\n');
ush_writeln("erase-line demo:");
ush_write(" left|right-to-clear");
ush_write("\x1B[14D\x1B[K");
ush_write_char('\n');
ush_writeln("ansitest done");
return 1;
}
static int ush_cmd_kbdstat(void) { static int ush_cmd_kbdstat(void) {
ush_writeln("kbdstat:"); ush_writeln("kbdstat:");
ush_print_kv_hex(" BUFFERED", cleonos_sys_kbd_buffered()); ush_print_kv_hex(" BUFFERED", cleonos_sys_kbd_buffered());
@@ -1154,6 +1277,8 @@ void ush_execute_line(ush_state *sh, const char *line) {
success = ush_cmd_clear(); success = ush_cmd_clear();
} else if (ush_streq(cmd, "ansi") != 0 || ush_streq(cmd, "color") != 0) { } else if (ush_streq(cmd, "ansi") != 0 || ush_streq(cmd, "color") != 0) {
success = ush_cmd_ansi(); success = ush_cmd_ansi();
} else if (ush_streq(cmd, "ansitest") != 0) {
success = ush_cmd_ansitest();
} else if (ush_streq(cmd, "memstat") != 0) { } else if (ush_streq(cmd, "memstat") != 0) {
success = ush_cmd_memstat(); success = ush_cmd_memstat();
} else if (ush_streq(cmd, "fsstat") != 0) { } else if (ush_streq(cmd, "fsstat") != 0) {
@@ -1208,3 +1333,5 @@ finalize_stats:
} }
} }

View File

@@ -12,13 +12,16 @@
#define CLKS_TTY_CURSOR_BLINK_INTERVAL_TICKS 5ULL #define CLKS_TTY_CURSOR_BLINK_INTERVAL_TICKS 5ULL
#define CLKS_TTY_BLINK_TICK_UNSET 0xFFFFFFFFFFFFFFFFULL #define CLKS_TTY_BLINK_TICK_UNSET 0xFFFFFFFFFFFFFFFFULL
#define CLKS_TTY_DESKTOP_INDEX 1U #define CLKS_TTY_DESKTOP_INDEX 1U
#define CLKS_TTY_ANSI_MAX_LEN 31U #define CLKS_TTY_ANSI_MAX_LEN 95U
#define CLKS_TTY_SCROLLBACK_LINES 256U #define CLKS_TTY_SCROLLBACK_LINES 256U
typedef struct clks_tty_ansi_state { typedef struct clks_tty_ansi_state {
clks_bool in_escape; clks_bool in_escape;
clks_bool saw_csi; clks_bool saw_csi;
clks_bool bold; clks_bool bold;
clks_bool inverse;
u32 saved_row;
u32 saved_col;
u32 len; u32 len;
char params[CLKS_TTY_ANSI_MAX_LEN + 1U]; char params[CLKS_TTY_ANSI_MAX_LEN + 1U];
} clks_tty_ansi_state; } clks_tty_ansi_state;
@@ -140,6 +143,7 @@ static void clks_tty_reset_color_state(u32 tty_index) {
clks_tty_current_fg[tty_index] = CLKS_TTY_FG; clks_tty_current_fg[tty_index] = CLKS_TTY_FG;
clks_tty_current_bg[tty_index] = CLKS_TTY_BG; clks_tty_current_bg[tty_index] = CLKS_TTY_BG;
clks_tty_ansi[tty_index].bold = CLKS_FALSE; clks_tty_ansi[tty_index].bold = CLKS_FALSE;
clks_tty_ansi[tty_index].inverse = CLKS_FALSE;
} }
static void clks_tty_reset_ansi_state(u32 tty_index) { static void clks_tty_reset_ansi_state(u32 tty_index) {
@@ -322,9 +326,18 @@ static void clks_tty_scroll_up(u32 tty_index) {
} }
} }
static void clks_tty_put_visible(u32 tty_index, u32 row, u32 col, char ch) { static void clks_tty_put_visible(u32 tty_index, u32 row, u32 col, char ch) {
u32 fg = clks_tty_current_fg[tty_index];
u32 bg = clks_tty_current_bg[tty_index];
if (clks_tty_ansi[tty_index].inverse == CLKS_TRUE) {
u32 swap = fg;
fg = bg;
bg = swap;
}
clks_tty_cells[tty_index][row][col] = ch; clks_tty_cells[tty_index][row][col] = ch;
clks_tty_cell_fg[tty_index][row][col] = clks_tty_current_fg[tty_index]; clks_tty_cell_fg[tty_index][row][col] = fg;
clks_tty_cell_bg[tty_index][row][col] = clks_tty_current_bg[tty_index]; clks_tty_cell_bg[tty_index][row][col] = bg;
if (tty_index == clks_tty_active_index) { if (tty_index == clks_tty_active_index) {
clks_tty_draw_cell(tty_index, row, col); clks_tty_draw_cell(tty_index, row, col);
@@ -392,67 +405,46 @@ static void clks_tty_put_char_raw(u32 tty_index, char ch) {
} }
} }
static void clks_tty_ansi_apply_sgr_code(u32 tty_index, u32 code) { static u32 clks_tty_ansi_clamp_255(u32 value) {
if (code == 0U) { return (value > 255U) ? 255U : value;
clks_tty_reset_color_state(tty_index);
return;
} }
if (code == 1U) { static u32 clks_tty_ansi_color_from_256(u32 index) {
clks_tty_ansi[tty_index].bold = CLKS_TRUE; if (index < 16U) {
return; return clks_tty_ansi_palette(index);
} }
if (code == 22U) { if (index >= 16U && index <= 231U) {
clks_tty_ansi[tty_index].bold = CLKS_FALSE; static const u32 steps[6] = {0U, 95U, 135U, 175U, 215U, 255U};
return; u32 n = index - 16U;
u32 r = n / 36U;
u32 g = (n / 6U) % 6U;
u32 b = n % 6U;
return (steps[r] << 16U) | (steps[g] << 8U) | steps[b];
} }
if (code == 39U) { if (index >= 232U && index <= 255U) {
clks_tty_current_fg[tty_index] = CLKS_TTY_FG; u32 gray = 8U + ((index - 232U) * 10U);
return; return (gray << 16U) | (gray << 8U) | gray;
} }
if (code == 49U) { return CLKS_TTY_FG;
clks_tty_current_bg[tty_index] = CLKS_TTY_BG;
return;
} }
if (code >= 30U && code <= 37U) { static u32 clks_tty_ansi_parse_params(const char *params, u32 len, u32 *out_values, u32 max_values) {
u32 idx = code - 30U; u32 count = 0U;
if (clks_tty_ansi[tty_index].bold == CLKS_TRUE) {
idx += 8U;
}
clks_tty_current_fg[tty_index] = clks_tty_ansi_palette(idx);
return;
}
if (code >= 90U && code <= 97U) {
clks_tty_current_fg[tty_index] = clks_tty_ansi_palette((code - 90U) + 8U);
return;
}
if (code >= 40U && code <= 47U) {
clks_tty_current_bg[tty_index] = clks_tty_ansi_palette(code - 40U);
return;
}
if (code >= 100U && code <= 107U) {
clks_tty_current_bg[tty_index] = clks_tty_ansi_palette((code - 100U) + 8U);
return;
}
}
static void clks_tty_ansi_apply_sgr_params(u32 tty_index, const char *params, u32 len) {
u32 i;
u32 value = 0U; u32 value = 0U;
clks_bool has_digit = CLKS_FALSE; clks_bool has_digit = CLKS_FALSE;
u32 i;
if (out_values == CLKS_NULL || max_values == 0U) {
return 0U;
}
if (len == 0U) { if (len == 0U) {
clks_tty_ansi_apply_sgr_code(tty_index, 0U); out_values[0] = 0U;
return; return 1U;
} }
for (i = 0U; i <= len; i++) { for (i = 0U; i <= len; i++) {
@@ -465,16 +457,427 @@ static void clks_tty_ansi_apply_sgr_params(u32 tty_index, const char *params, u3
} }
if (ch == ';') { if (ch == ';') {
if (has_digit == CLKS_TRUE) { if (count < max_values) {
clks_tty_ansi_apply_sgr_code(tty_index, value); out_values[count++] = (has_digit == CLKS_TRUE) ? value : 0U;
} else {
clks_tty_ansi_apply_sgr_code(tty_index, 0U);
} }
value = 0U; value = 0U;
has_digit = CLKS_FALSE; has_digit = CLKS_FALSE;
continue; continue;
} }
}
if (count == 0U) {
out_values[0] = 0U;
return 1U;
}
return count;
}
static u32 clks_tty_ansi_param_or_default(const u32 *params, u32 count, u32 index, u32 default_value) {
if (params == CLKS_NULL || index >= count || params[index] == 0U) {
return default_value;
}
return params[index];
}
static void clks_tty_ansi_clear_line_mode(u32 tty_index, u32 mode) {
u32 row = clks_tty_cursor_row[tty_index];
u32 start = 0U;
u32 end = 0U;
u32 col;
if (row >= clks_tty_rows) {
return;
}
if (mode == 0U) {
start = clks_tty_cursor_col[tty_index];
end = clks_tty_cols;
} else if (mode == 1U) {
start = 0U;
end = clks_tty_cursor_col[tty_index] + 1U;
} else {
start = 0U;
end = clks_tty_cols;
}
if (start >= clks_tty_cols) {
start = clks_tty_cols;
}
if (end > clks_tty_cols) {
end = clks_tty_cols;
}
for (col = start; col < end; col++) {
clks_tty_cells[tty_index][row][col] = ' ';
clks_tty_cell_fg[tty_index][row][col] = CLKS_TTY_FG;
clks_tty_cell_bg[tty_index][row][col] = CLKS_TTY_BG;
}
if (tty_index == clks_tty_active_index) {
for (col = start; col < end; col++) {
clks_tty_draw_cell(tty_index, row, col);
}
}
}
static void clks_tty_ansi_clear_screen_mode(u32 tty_index, u32 mode) {
u32 row;
u32 col;
u32 cursor_row = clks_tty_cursor_row[tty_index];
u32 cursor_col = clks_tty_cursor_col[tty_index];
if (cursor_row >= clks_tty_rows) {
cursor_row = clks_tty_rows - 1U;
}
if (cursor_col >= clks_tty_cols) {
cursor_col = clks_tty_cols - 1U;
}
if (mode == 0U) {
for (row = cursor_row; row < clks_tty_rows; row++) {
u32 start_col = (row == cursor_row) ? cursor_col : 0U;
for (col = start_col; col < clks_tty_cols; col++) {
clks_tty_cells[tty_index][row][col] = ' ';
clks_tty_cell_fg[tty_index][row][col] = CLKS_TTY_FG;
clks_tty_cell_bg[tty_index][row][col] = CLKS_TTY_BG;
}
}
} else if (mode == 1U) {
for (row = 0U; row <= cursor_row; row++) {
u32 end_col = (row == cursor_row) ? (cursor_col + 1U) : clks_tty_cols;
for (col = 0U; col < end_col; col++) {
clks_tty_cells[tty_index][row][col] = ' ';
clks_tty_cell_fg[tty_index][row][col] = CLKS_TTY_FG;
clks_tty_cell_bg[tty_index][row][col] = CLKS_TTY_BG;
}
}
} else {
for (row = 0U; row < clks_tty_rows; row++) {
for (col = 0U; col < clks_tty_cols; col++) {
clks_tty_cells[tty_index][row][col] = ' ';
clks_tty_cell_fg[tty_index][row][col] = CLKS_TTY_FG;
clks_tty_cell_bg[tty_index][row][col] = CLKS_TTY_BG;
}
}
}
if (mode == 3U) {
clks_tty_scrollback_head[tty_index] = 0U;
clks_tty_scrollback_count[tty_index] = 0U;
clks_tty_scrollback_offset[tty_index] = 0U;
}
if (tty_index == clks_tty_active_index) {
clks_tty_redraw_active();
}
}
static void clks_tty_ansi_apply_sgr_params(u32 tty_index, const char *params, u32 len) {
u32 values[16];
u32 count = clks_tty_ansi_parse_params(params, len, values, 16U);
u32 i;
if (count == 0U) {
return;
}
for (i = 0U; i < count; i++) {
u32 code = values[i];
if (code == 0U) {
clks_tty_reset_color_state(tty_index);
continue;
}
if (code == 1U) {
clks_tty_ansi[tty_index].bold = CLKS_TRUE;
continue;
}
if (code == 7U) {
clks_tty_ansi[tty_index].inverse = CLKS_TRUE;
continue;
}
if (code == 22U) {
clks_tty_ansi[tty_index].bold = CLKS_FALSE;
continue;
}
if (code == 27U) {
clks_tty_ansi[tty_index].inverse = CLKS_FALSE;
continue;
}
if (code == 39U) {
clks_tty_current_fg[tty_index] = CLKS_TTY_FG;
continue;
}
if (code == 49U) {
clks_tty_current_bg[tty_index] = CLKS_TTY_BG;
continue;
}
if (code >= 30U && code <= 37U) {
u32 idx = code - 30U;
if (clks_tty_ansi[tty_index].bold == CLKS_TRUE) {
idx += 8U;
}
clks_tty_current_fg[tty_index] = clks_tty_ansi_palette(idx);
continue;
}
if (code >= 90U && code <= 97U) {
clks_tty_current_fg[tty_index] = clks_tty_ansi_palette((code - 90U) + 8U);
continue;
}
if (code >= 40U && code <= 47U) {
clks_tty_current_bg[tty_index] = clks_tty_ansi_palette(code - 40U);
continue;
}
if (code >= 100U && code <= 107U) {
clks_tty_current_bg[tty_index] = clks_tty_ansi_palette((code - 100U) + 8U);
continue;
}
if ((code == 38U || code == 48U) && (i + 1U) < count) {
u32 mode = values[i + 1U];
u32 color;
if (mode == 5U && (i + 2U) < count) {
color = clks_tty_ansi_color_from_256(values[i + 2U]);
if (code == 38U) {
clks_tty_current_fg[tty_index] = color;
} else {
clks_tty_current_bg[tty_index] = color;
}
i += 2U;
continue;
}
if (mode == 2U && (i + 4U) < count) {
u32 r = clks_tty_ansi_clamp_255(values[i + 2U]);
u32 g = clks_tty_ansi_clamp_255(values[i + 3U]);
u32 b = clks_tty_ansi_clamp_255(values[i + 4U]);
color = (r << 16U) | (g << 8U) | b;
if (code == 38U) {
clks_tty_current_fg[tty_index] = color;
} else {
clks_tty_current_bg[tty_index] = color;
}
i += 4U;
continue;
}
}
}
}
static void clks_tty_ansi_process_csi_final(u32 tty_index, const char *params, u32 len, char final) {
u32 values[16];
u32 count = clks_tty_ansi_parse_params(params, len, values, 16U);
clks_bool private_mode = (len > 0U && params[0] == '?') ? CLKS_TRUE : CLKS_FALSE;
if (final == 'm') {
clks_tty_ansi_apply_sgr_params(tty_index, params, len);
return;
}
if (final == 'J') {
u32 mode = (count == 0U) ? 0U : values[0];
clks_tty_ansi_clear_screen_mode(tty_index, mode);
return;
}
if (final == 'K') {
u32 mode = (count == 0U) ? 0U : values[0];
clks_tty_ansi_clear_line_mode(tty_index, mode);
return;
}
if (final == 'H' || final == 'f') {
u32 row = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
u32 col = clks_tty_ansi_param_or_default(values, count, 1U, 1U);
if (row > 0U) {
row--;
}
if (col > 0U) {
col--;
}
if (row >= clks_tty_rows) {
row = clks_tty_rows - 1U;
}
if (col >= clks_tty_cols) {
col = clks_tty_cols - 1U;
}
clks_tty_cursor_row[tty_index] = row;
clks_tty_cursor_col[tty_index] = col;
return;
}
if (final == 'A') {
u32 n = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
if (n > clks_tty_cursor_row[tty_index]) {
clks_tty_cursor_row[tty_index] = 0U;
} else {
clks_tty_cursor_row[tty_index] -= n;
}
return;
}
if (final == 'B') {
u32 n = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
u32 max_row = clks_tty_rows - 1U;
if (clks_tty_cursor_row[tty_index] + n > max_row) {
clks_tty_cursor_row[tty_index] = max_row;
} else {
clks_tty_cursor_row[tty_index] += n;
}
return;
}
if (final == 'C') {
u32 n = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
u32 max_col = clks_tty_cols - 1U;
if (clks_tty_cursor_col[tty_index] + n > max_col) {
clks_tty_cursor_col[tty_index] = max_col;
} else {
clks_tty_cursor_col[tty_index] += n;
}
return;
}
if (final == 'D') {
u32 n = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
if (n > clks_tty_cursor_col[tty_index]) {
clks_tty_cursor_col[tty_index] = 0U;
} else {
clks_tty_cursor_col[tty_index] -= n;
}
return;
}
if (final == 'E' || final == 'F') {
u32 n = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
if (final == 'E') {
u32 max_row = clks_tty_rows - 1U;
if (clks_tty_cursor_row[tty_index] + n > max_row) {
clks_tty_cursor_row[tty_index] = max_row;
} else {
clks_tty_cursor_row[tty_index] += n;
}
} else {
if (n > clks_tty_cursor_row[tty_index]) {
clks_tty_cursor_row[tty_index] = 0U;
} else {
clks_tty_cursor_row[tty_index] -= n;
}
}
clks_tty_cursor_col[tty_index] = 0U;
return;
}
if (final == 'G') {
u32 col = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
if (col > 0U) {
col--;
}
if (col >= clks_tty_cols) {
col = clks_tty_cols - 1U;
}
clks_tty_cursor_col[tty_index] = col;
return;
}
if (final == 'd') {
u32 row = clks_tty_ansi_param_or_default(values, count, 0U, 1U);
if (row > 0U) {
row--;
}
if (row >= clks_tty_rows) {
row = clks_tty_rows - 1U;
}
clks_tty_cursor_row[tty_index] = row;
return;
}
if (final == 's') {
clks_tty_ansi[tty_index].saved_row = clks_tty_cursor_row[tty_index];
clks_tty_ansi[tty_index].saved_col = clks_tty_cursor_col[tty_index];
return;
}
if (final == 'u') {
u32 row = clks_tty_ansi[tty_index].saved_row;
u32 col = clks_tty_ansi[tty_index].saved_col;
if (row >= clks_tty_rows) {
row = clks_tty_rows - 1U;
}
if (col >= clks_tty_cols) {
col = clks_tty_cols - 1U;
}
clks_tty_cursor_row[tty_index] = row;
clks_tty_cursor_col[tty_index] = col;
return;
}
if ((final == 'h' || final == 'l') && private_mode == CLKS_TRUE) {
u32 mode = (count == 0U) ? 0U : values[0];
if (mode == 25U) {
if (final == 'h') {
clks_tty_blink_enabled = CLKS_TRUE;
if (tty_index == clks_tty_active_index) {
clks_tty_draw_cursor();
}
} else {
clks_tty_blink_enabled = CLKS_FALSE;
if (tty_index == clks_tty_active_index) {
clks_tty_hide_cursor();
}
}
}
return; return;
} }
@@ -501,11 +904,36 @@ static clks_bool clks_tty_ansi_process_byte(u32 tty_index, char ch) {
return CLKS_TRUE; return CLKS_TRUE;
} }
if (ch == '7') {
state->saved_row = clks_tty_cursor_row[tty_index];
state->saved_col = clks_tty_cursor_col[tty_index];
clks_tty_reset_ansi_state(tty_index); clks_tty_reset_ansi_state(tty_index);
return CLKS_FALSE; return CLKS_TRUE;
} }
if ((ch >= '0' && ch <= '9') || ch == ';') { if (ch == '8') {
u32 row = state->saved_row;
u32 col = state->saved_col;
if (row >= clks_tty_rows) {
row = clks_tty_rows - 1U;
}
if (col >= clks_tty_cols) {
col = clks_tty_cols - 1U;
}
clks_tty_cursor_row[tty_index] = row;
clks_tty_cursor_col[tty_index] = col;
clks_tty_reset_ansi_state(tty_index);
return CLKS_TRUE;
}
clks_tty_reset_ansi_state(tty_index);
return CLKS_TRUE;
}
if ((ch >= '0' && ch <= '9') || ch == ';' || ch == '?') {
if (state->len < CLKS_TTY_ANSI_MAX_LEN) { if (state->len < CLKS_TTY_ANSI_MAX_LEN) {
state->params[state->len++] = ch; state->params[state->len++] = ch;
state->params[state->len] = '\0'; state->params[state->len] = '\0';
@@ -516,36 +944,10 @@ static clks_bool clks_tty_ansi_process_byte(u32 tty_index, char ch) {
return CLKS_TRUE; return CLKS_TRUE;
} }
if (ch == 'm') { clks_tty_ansi_process_csi_final(tty_index, state->params, state->len, ch);
clks_tty_ansi_apply_sgr_params(tty_index, state->params, state->len);
clks_tty_reset_ansi_state(tty_index); clks_tty_reset_ansi_state(tty_index);
return CLKS_TRUE; return CLKS_TRUE;
} }
if (ch == 'J') {
if (state->len == 0U || (state->len == 1U && state->params[0] == '2')) {
clks_tty_clear_tty(tty_index);
if (tty_index == clks_tty_active_index) {
clks_tty_redraw_active();
}
}
clks_tty_reset_ansi_state(tty_index);
return CLKS_TRUE;
}
if (ch == 'H') {
clks_tty_cursor_row[tty_index] = 0U;
clks_tty_cursor_col[tty_index] = 0U;
clks_tty_reset_ansi_state(tty_index);
return CLKS_TRUE;
}
clks_tty_reset_ansi_state(tty_index);
return CLKS_TRUE;
}
void clks_tty_init(void) { void clks_tty_init(void) {
struct clks_framebuffer_info info; struct clks_framebuffer_info info;
u32 tty; u32 tty;
@@ -793,3 +1195,4 @@ u32 clks_tty_count(void) {
clks_bool clks_tty_ready(void) { clks_bool clks_tty_ready(void) {
return clks_tty_is_ready; return clks_tty_is_ready;
} }