Shell: we now support left/right arrows

This commit is contained in:
Bananymous 2023-06-05 18:24:41 +03:00
parent 480842a203
commit 90e48970e6
1 changed files with 7 additions and 13 deletions

View File

@ -117,12 +117,6 @@ int main(int argc, char** argv)
char c; char c;
fread(&c, 1, sizeof(char), stdin); fread(&c, 1, sizeof(char), stdin);
if (got_csi)
{
continue;
}
switch (c) switch (c)
{ {
case '\e': case '\e':
@ -134,17 +128,17 @@ int main(int argc, char** argv)
{ {
case 'A': if (index > 0) { index--; col = buffers[index].size(); fprintf(stdout, "\e[%dG%s\e[K", prompt_length(prompt) + 1, buffers[index].data()); fflush(stdout); } break; case 'A': if (index > 0) { index--; col = buffers[index].size(); fprintf(stdout, "\e[%dG%s\e[K", prompt_length(prompt) + 1, buffers[index].data()); fflush(stdout); } break;
case 'B': if (index < buffers.size() - 1) { index++; col = buffers[index].size(); fprintf(stdout, "\e[%dG%s\e[K", prompt_length(prompt) + 1, buffers[index].data()); fflush(stdout); } break; case 'B': if (index < buffers.size() - 1) { index++; col = buffers[index].size(); fprintf(stdout, "\e[%dG%s\e[K", prompt_length(prompt) + 1, buffers[index].data()); fflush(stdout); } break;
case 'C': break; case 'C': if (col < buffers[index].size() - 1) { col++; fprintf(stdout, "\e[C"); fflush(stdout); } break;
case 'D': break; case 'D': if (col > 0) { col--; fprintf(stdout, "\e[D"); fflush(stdout); } break;
} }
break; break;
case '\b': case '\b':
if (col > 0) if (col > 0)
{ {
buffers[index].pop_back();
fprintf(stdout, "\b \b");
fflush(stdout);
col--; col--;
buffers[index].remove(col);
fprintf(stdout, "\b\e[s%s\e[K\e[u", buffers[index].data() + col);
fflush(stdout);
} }
break; break;
case '\n': case '\n':