From 9775e83374433837c5c1932a60846708026ed3f9 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 7 Oct 2024 04:19:36 +0300 Subject: [PATCH] Shell: Fix tab space escaping in tab completion --- userspace/programs/Shell/main.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/userspace/programs/Shell/main.cpp b/userspace/programs/Shell/main.cpp index 179fb80ac9..1c679c6ef4 100644 --- a/userspace/programs/Shell/main.cpp +++ b/userspace/programs/Shell/main.cpp @@ -1543,9 +1543,28 @@ int main(int argc, char** argv) if (all_match_len) { - col += all_match_len; - MUST(buffers[index].append(completions.front().sv().substring(0, all_match_len))); - printf("%.*s", (int)all_match_len, completions.front().data()); + auto completion = completions.front().sv().substring(0, all_match_len); + + BAN::String temp_escaped; + if (should_escape_spaces) + { + MUST(temp_escaped.append(completion)); + for (size_t i = 0; i < temp_escaped.size(); i++) + { + if (!isspace(temp_escaped[i])) + continue; + MUST(temp_escaped.insert('\\', i)); + i++; + } + completion = temp_escaped.sv(); + + if (!buffers[index].empty() && buffers[index].back() == '\\' && completion.front() == '\\') + completion = completion.substring(1); + } + + col += completion.size(); + MUST(buffers[index].append(completion)); + printf("%.*s", (int)completion.size(), completion.data()); fflush(stdout); break; }