screen: implement cursorhome terminal command

This commit is contained in:
2025-08-22 17:43:41 +03:00
parent fffa4b7699
commit 9bb6d9d1a5
3 changed files with 39 additions and 17 deletions
+36 -11
View File
@@ -7,6 +7,12 @@ static size_t terminal_column;
static uint8_t terminal_color;
static uint16_t* terminal_buffer;
static enum {
STATE_NORMAL,
STATE_ESCAPE,
STATE_BRACKET,
} terminal_state = STATE_NORMAL;
inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg)
{
return fg | bg << 4;
@@ -66,24 +72,43 @@ void terminal_scroll(void)
void terminal_putchar(char c)
{
if(c != '\n')
if (terminal_state == STATE_ESCAPE) {
if (c == '[') {
terminal_state = STATE_BRACKET;
} else {
terminal_state = STATE_NORMAL;
}
return;
} else if (terminal_state == STATE_BRACKET) {
if (c == 'H') {
terminal_row = 0;
terminal_column = 0;
}
terminal_state = STATE_NORMAL;
return;
}
if (c == '\033') {//ESC
terminal_state = STATE_ESCAPE;
return;
}
if (c == '\n') {
terminal_column = 0;
terminal_row++;
} else {
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
if (++terminal_column >= VGA_WIDTH){
terminal_column = 0;
if (++terminal_row >= VGA_HEIGHT)
terminal_scroll();
}
if(terminal_row >= VGA_HEIGHT){
terminal_scroll();
terminal_column++;
}
if(c == '\n')
{
if (terminal_column > VGA_WIDTH) {
terminal_column = 0;
terminal_row++;
}
if (terminal_row >= VGA_HEIGHT) {
terminal_scroll();
}
}
void terminal_write(const char* data, size_t size)
-6
View File
@@ -4,21 +4,15 @@
#include <stddef.h>
#include "../include/string.h"
#ifdef __is_katauos
#include "../include/screen.h"
#endif
int puts(const char* string) {
return printf("%s\n", string);
}
int putchar(int ic) {
#if defined(__is_katauos)
char c = (char) ic;
terminal_write(&c, sizeof(c));
#else
// TODO: Implement stdio and the write system call.
#endif
return ic;
}