From 7d87cb870526e106cc4f9af5f3c90eb0071c84ea Mon Sep 17 00:00:00 2001 From: "Nikita.Ashihmin" Date: Tue, 20 May 2025 18:07:37 +0400 Subject: [PATCH] PY-81238 Packages: handle \b in outputs Signed-off-by: Nikita.Ashihmin GitOrigin-RevId: a243ab2bde91799d6499974a9dc8d5b16260edab --- .../execution/process/ProcessOutput.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/platform/platform-util-io/src/com/intellij/execution/process/ProcessOutput.java b/platform/platform-util-io/src/com/intellij/execution/process/ProcessOutput.java index 6ae2eb841894..1e2a8049d287 100644 --- a/platform/platform-util-io/src/com/intellij/execution/process/ProcessOutput.java +++ b/platform/platform-util-io/src/com/intellij/execution/process/ProcessOutput.java @@ -38,11 +38,11 @@ public class ProcessOutput { } public void appendStdout(@Nullable String text) { - myStdoutBuilder.append(text); + appendWithBackspaceHandling(myStdoutBuilder, text); } public void appendStderr(@Nullable String text) { - myStderrBuilder.append(text); + appendWithBackspaceHandling(myStderrBuilder, text); } public @NotNull @NlsSafe String getStdout() { @@ -137,4 +137,28 @@ public class ProcessOutput { ", stderr=" + myStderrBuilder + '}'; } + + private static void appendWithBackspaceHandling(@NotNull StringBuilder builder, @Nullable String text) { + if (text == null) { + return; + } + + if (text.contains("\b")) { + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + if (c == '\b') { + int length = builder.length(); + if (length > 0) { + builder.deleteCharAt(length - 1); + } + } + else { + builder.append(c); + } + } + } + else { + builder.append(text); + } + } } \ No newline at end of file