forked from Bananymous/banan-os
Shell: Clenup code and fix some bugs
Don't list tab completion multiple times, allow `clear` to work even when ANSI CSI 3K is not supported, reset buffer index when cancelling command with ctrl+c
This commit is contained in:
parent
1824988b9a
commit
264d1798dc
|
@ -401,10 +401,10 @@ static CommandList parse_command_list(BAN::StringView command_view)
|
||||||
case '"':
|
case '"':
|
||||||
while (++i < command_view.size())
|
while (++i < command_view.size())
|
||||||
{
|
{
|
||||||
|
if (command_view[i] == current)
|
||||||
|
break;
|
||||||
if (command_view[i] == '\\')
|
if (command_view[i] == '\\')
|
||||||
i++;
|
i++;
|
||||||
else if (command_view[i] == current)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ';':
|
case ';':
|
||||||
|
@ -486,7 +486,7 @@ static void install_builtin_commands()
|
||||||
MUST(s_builtin_commands.emplace("clear"_sv,
|
MUST(s_builtin_commands.emplace("clear"_sv,
|
||||||
[](const SingleCommand&, FILE* fout, int, int) -> int
|
[](const SingleCommand&, FILE* fout, int, int) -> int
|
||||||
{
|
{
|
||||||
fprintf(fout, "\e[H\e[3J");
|
fprintf(fout, "\e[H\e[3J\e[2J");
|
||||||
fflush(fout);
|
fflush(fout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1334,6 +1334,7 @@ int main(int argc, char** argv)
|
||||||
clearerr(stdin);
|
clearerr(stdin);
|
||||||
buffers = history;
|
buffers = history;
|
||||||
MUST(buffers.emplace_back(""_sv));
|
MUST(buffers.emplace_back(""_sv));
|
||||||
|
index = buffers.size() - 1;
|
||||||
col = 0;
|
col = 0;
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
print_prompt();
|
print_prompt();
|
||||||
|
@ -1500,6 +1501,22 @@ int main(int argc, char** argv)
|
||||||
tab_completion_keep = col;
|
tab_completion_keep = col;
|
||||||
auto [should_escape_spaces, prefix, completions] = list_tab_completion_entries(buffers[index].sv().substring(0, tab_completion_keep));
|
auto [should_escape_spaces, prefix, completions] = list_tab_completion_entries(buffers[index].sv().substring(0, tab_completion_keep));
|
||||||
|
|
||||||
|
BAN::sort::sort(completions.begin(), completions.end(),
|
||||||
|
[](const BAN::String& a, const BAN::String& b) {
|
||||||
|
if (auto cmp = strcmp(a.data(), b.data()))
|
||||||
|
return cmp < 0;
|
||||||
|
return a.size() < b.size();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < completions.size() - 1; i++)
|
||||||
|
{
|
||||||
|
if (completions[i] != completions[i + 1])
|
||||||
|
continue;
|
||||||
|
completions.remove(i + 1);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
if (completions.empty())
|
if (completions.empty())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1539,14 +1556,6 @@ int main(int argc, char** argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::sort::sort(completions.begin(), completions.end(),
|
|
||||||
[](const BAN::String& a, const BAN::String& b) {
|
|
||||||
if (auto cmp = strcmp(a.data(), b.data()))
|
|
||||||
return cmp < 0;
|
|
||||||
return a.size() < b.size();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
for (size_t i = 0; i < completions.size(); i++)
|
for (size_t i = 0; i < completions.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue