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_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;
|
||||
|
@ -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,38 +46,29 @@ static void putchar_at_offset(
|
||||
}
|
||||
}
|
||||
|
||||
static bool g_escape_sequence = false;
|
||||
|
||||
#pragma GCC pop_options
|
||||
|
||||
void TextRenderer::putchar(char chr)
|
||||
{
|
||||
switch (chr)
|
||||
if (g_escape_sequence)
|
||||
{
|
||||
case '\n': {
|
||||
ypos += FONT_HEIGHT;
|
||||
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
||||
g_escape_sequence = false;
|
||||
switch (chr)
|
||||
{
|
||||
memcpy((void*)bootboot.fb_ptr, (char*)bootboot.fb_ptr + (bootboot.fb_scanline * FONT_HEIGHT),
|
||||
bootboot.fb_size - (bootboot.fb_scanline * FONT_HEIGHT));
|
||||
ypos -= FONT_HEIGHT;
|
||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
||||
case '@':
|
||||
reset();
|
||||
framebuffer0.clear(Color::Black);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
xpos = 0;
|
||||
break;
|
||||
}
|
||||
case '\r': xpos = 0; break;
|
||||
case '\b':
|
||||
if (xpos != 0)
|
||||
else
|
||||
{
|
||||
switch (chr)
|
||||
{
|
||||
xpos -= FONT_WIDTH;
|
||||
framebuffer0.paint_rect(xpos, ypos, FONT_WIDTH, FONT_HEIGHT, Color::Black);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
putchar_at_offset(chr, xpos, ypos, fgColor, bgColor);
|
||||
xpos += FONT_WIDTH;
|
||||
if ((xpos + FONT_WIDTH) > bootboot.fb_width)
|
||||
{
|
||||
xpos = 0;
|
||||
case '\n': {
|
||||
ypos += FONT_HEIGHT;
|
||||
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
||||
{
|
||||
@ -86,9 +77,36 @@ void TextRenderer::putchar(char chr)
|
||||
ypos -= FONT_HEIGHT;
|
||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
||||
}
|
||||
xpos = 0;
|
||||
break;
|
||||
}
|
||||
case '\r': xpos = 0; break;
|
||||
case '\b':
|
||||
if (xpos != 0)
|
||||
{
|
||||
xpos -= FONT_WIDTH;
|
||||
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;
|
||||
if ((xpos + FONT_WIDTH) > bootboot.fb_width)
|
||||
{
|
||||
xpos = 0;
|
||||
ypos += FONT_HEIGHT;
|
||||
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
||||
{
|
||||
memcpy((void*)bootboot.fb_ptr, (char*)bootboot.fb_ptr + (bootboot.fb_scanline * FONT_HEIGHT),
|
||||
bootboot.fb_size - (bootboot.fb_scanline * FONT_HEIGHT));
|
||||
ypos -= FONT_HEIGHT;
|
||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user