From 5af77dcfb9e68f719b5cf183c9c7baaf97a3773c 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 ff59c5ee59..4fe6366528 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':