1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:15:07 +00:00

Shell: Implement support for terminal clearing with ^L.

Make LineEditor::get_line() responsible for printing the prompt. That way
we can re-prompt after clearing the screen on ^L.

This makes the Serenity Terminal feel a little bit more like home :^)
This commit is contained in:
Andreas Kling 2019-07-19 20:01:46 +02:00
parent 2d4d465206
commit 253e391bfc
3 changed files with 23 additions and 11 deletions

View file

@ -25,15 +25,15 @@
GlobalState g;
static LineEditor editor;
static void prompt()
static String prompt()
{
if (g.uid == 0)
printf("# ");
else {
printf("\033]0;%s@%s:%s\007", g.username.characters(), g.hostname, g.cwd.characters());
printf("\033[31;1m%s\033[0m@\033[37;1m%s\033[0m:\033[32;1m%s\033[0m$> ", g.username.characters(), g.hostname, g.cwd.characters());
}
fflush(stdout);
return "# ";
StringBuilder builder;
builder.appendf("\033]0;%s@%s:%s\007", g.username.characters(), g.hostname, g.cwd.characters());
builder.appendf("\033[31;1m%s\033[0m@\033[37;1m%s\033[0m:\033[32;1m%s\033[0m$> ", g.username.characters(), g.hostname, g.cwd.characters());
return builder.to_string();
}
static int sh_pwd(int, char**)
@ -602,8 +602,7 @@ int main(int argc, char** argv)
atexit(save_history);
for (;;) {
prompt();
auto line = editor.get_line();
auto line = editor.get_line(prompt());
if (line.is_empty())
continue;
run_command(line);