Kernel: Implement very basic escape sequences for TextRenderer
This commit is contained in:
parent
08c4dac2c2
commit
00f90246c8
@ -113,9 +113,14 @@ int command_match_builtins(command* cmd)
|
|||||||
{
|
{
|
||||||
if (command_matches(cmd, "exit ")) { exit(atoi(cmd->buffer + 5)); }
|
if (command_matches(cmd, "exit ")) { exit(atoi(cmd->buffer + 5)); }
|
||||||
if (command_matches_exactly(cmd, "exit")) { exit(0); }
|
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 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -30,7 +30,7 @@ void TextRenderer::reset()
|
|||||||
#pragma GCC optimize("O0")
|
#pragma GCC optimize("O0")
|
||||||
|
|
||||||
static void putchar_at_offset(
|
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.
|
[[maybe_unused]] Color& bg) // FIXME: Rewrite this function to actually work with foreground and background colors.
|
||||||
{
|
{
|
||||||
uint8_t* glyph = &font[c * 16];
|
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
|
#pragma GCC pop_options
|
||||||
|
|
||||||
void TextRenderer::putchar(char chr)
|
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)
|
switch (chr)
|
||||||
{
|
{
|
||||||
case '\n': {
|
case '\n': {
|
||||||
@ -72,6 +88,7 @@ void TextRenderer::putchar(char chr)
|
|||||||
framebuffer0.paint_rect(xpos, ypos, FONT_WIDTH, FONT_HEIGHT, Color::Black);
|
framebuffer0.paint_rect(xpos, ypos, FONT_WIDTH, FONT_HEIGHT, Color::Black);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case '\033': g_escape_sequence = true; break;
|
||||||
default: {
|
default: {
|
||||||
putchar_at_offset(chr, xpos, ypos, fgColor, bgColor);
|
putchar_at_offset(chr, xpos, ypos, fgColor, bgColor);
|
||||||
xpos += FONT_WIDTH;
|
xpos += FONT_WIDTH;
|
||||||
@ -90,6 +107,7 @@ void TextRenderer::putchar(char chr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer::write(const char* str, size_t size)
|
void TextRenderer::write(const char* str, size_t size)
|
||||||
|
Loading…
Reference in New Issue
Block a user