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,38 +46,29 @@ 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)
|
||||||
{
|
{
|
||||||
switch (chr)
|
if (g_escape_sequence)
|
||||||
{
|
{
|
||||||
case '\n': {
|
g_escape_sequence = false;
|
||||||
ypos += FONT_HEIGHT;
|
switch (chr)
|
||||||
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
|
||||||
{
|
{
|
||||||
memcpy((void*)bootboot.fb_ptr, (char*)bootboot.fb_ptr + (bootboot.fb_scanline * FONT_HEIGHT),
|
case '@':
|
||||||
bootboot.fb_size - (bootboot.fb_scanline * FONT_HEIGHT));
|
reset();
|
||||||
ypos -= FONT_HEIGHT;
|
framebuffer0.clear(Color::Black);
|
||||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
xpos = 0;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case '\r': xpos = 0; break;
|
else
|
||||||
case '\b':
|
{
|
||||||
if (xpos != 0)
|
switch (chr)
|
||||||
{
|
{
|
||||||
xpos -= FONT_WIDTH;
|
case '\n': {
|
||||||
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;
|
|
||||||
ypos += FONT_HEIGHT;
|
ypos += FONT_HEIGHT;
|
||||||
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
||||||
{
|
{
|
||||||
@ -86,9 +77,36 @@ void TextRenderer::putchar(char chr)
|
|||||||
ypos -= FONT_HEIGHT;
|
ypos -= FONT_HEIGHT;
|
||||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
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