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