From 90e48970e65b8210ad8e94e89b35910a456681cf Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 5 Jun 2023 18:24:41 +0300 Subject: [PATCH] Shell: we now support left/right arrows --- userspace/Shell/main.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/userspace/Shell/main.cpp b/userspace/Shell/main.cpp index ff59c5ee5..4fe636652 100644 --- a/userspace/Shell/main.cpp +++ b/userspace/Shell/main.cpp @@ -117,12 +117,6 @@ int main(int argc, char** argv) char c; fread(&c, 1, sizeof(char), stdin); - if (got_csi) - { - - continue; - } - switch (c) { case '\e': @@ -132,19 +126,19 @@ int main(int argc, char** argv) fread(&c, 1, sizeof(char), stdin); switch (c) { - 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 'C': break; - case 'D': 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 'C': if (col < buffers[index].size() - 1) { col++; fprintf(stdout, "\e[C"); fflush(stdout); } break; + case 'D': if (col > 0) { col--; fprintf(stdout, "\e[D"); fflush(stdout); } break; } break; case '\b': if (col > 0) { - buffers[index].pop_back(); - fprintf(stdout, "\b \b"); - fflush(stdout); col--; + buffers[index].remove(col); + fprintf(stdout, "\b\e[s%s\e[K\e[u", buffers[index].data() + col); + fflush(stdout); } break; case '\n':