Kernel: Implement very basic escape sequences for TextRenderer

This commit is contained in:
apio 2022-10-30 18:34:40 +01:00
parent 08c4dac2c2
commit 00f90246c8
2 changed files with 51 additions and 28 deletions

View File

@ -113,9 +113,14 @@ int command_match_builtins(command* cmd)
{
if (command_matches(cmd, "exit ")) { exit(atoi(cmd->buffer + 5)); }
if (command_matches_exactly(cmd, "exit")) { exit(0); }
if (command_matches_exactly(cmd, "pid"))
if (command_matches_exactly(cmd, "id"))
{
printf("pid %ld, ppid %ld\n", getpid(), getppid());
printf("pid %ld, ppid %ld, uid %d (%s), gid %d\n", getpid(), getppid(), getuid(), username, getgid());
return 1;
}
if (command_matches_exactly(cmd, "clear"))
{
fputs("\033@", stdout); // clear screen. for now, escape sequences in luna are non-standard.
return 1;
}
return 0;

View File

@ -30,7 +30,7 @@ void TextRenderer::reset()
#pragma GCC optimize("O0")
static void putchar_at_offset(
char c, [[maybe_unused]] uint32_t cx, [[maybe_unused]] uint32_t cy, [[maybe_unused]] Color& fg,
char c, uint32_t cx, uint32_t cy, [[maybe_unused]] Color& fg,
[[maybe_unused]] Color& bg) // FIXME: Rewrite this function to actually work with foreground and background colors.
{
uint8_t* glyph = &font[c * 16];
@ -46,10 +46,26 @@ static void putchar_at_offset(
}
}
static bool g_escape_sequence = false;
#pragma GCC pop_options
void TextRenderer::putchar(char chr)
{
if (g_escape_sequence)
{
g_escape_sequence = false;
switch (chr)
{
case '@':
reset();
framebuffer0.clear(Color::Black);
break;
default: break;
}
}
else
{
switch (chr)
{
case '\n': {
@ -72,6 +88,7 @@ void TextRenderer::putchar(char chr)
framebuffer0.paint_rect(xpos, ypos, FONT_WIDTH, FONT_HEIGHT, Color::Black);
}
break;
case '\033': g_escape_sequence = true; break;
default: {
putchar_at_offset(chr, xpos, ypos, fgColor, bgColor);
xpos += FONT_WIDTH;
@ -90,6 +107,7 @@ void TextRenderer::putchar(char chr)
break;
}
}
}
}
void TextRenderer::write(const char* str, size_t size)