Skip to content

Commit

Permalink
Merge pull request #17157 from stuartwdouglas/console-fix
Browse files Browse the repository at this point in the history
Fix large blank space in stack traces
  • Loading branch information
gsmet committed May 12, 2021
2 parents 9175e8e + 3e00851 commit c89bd20
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,46 +266,52 @@ public void write(String s) {
return;
}
}
clearStatusMessages(buffer);
int cursorPos = lastWriteCursorX;
gotoLine(buffer, size.getHeight());
String stripped = stripAnsiCodes(s);
int lines = countLines(s, cursorPos);
int trailing = 0;
int index = stripped.lastIndexOf("\n");
if (index == -1) {
trailing = stripped.length();
if (totalStatusLines == 0) {
writeQueue.add(s);
} else {
trailing = stripped.length() - index - 1;
}
clearStatusMessages(buffer);
int cursorPos = lastWriteCursorX;
gotoLine(buffer, size.getHeight());
String stripped = stripAnsiCodes(s);
int lines = countLines(s, cursorPos);
int trailing = 0;
int index = stripped.lastIndexOf("\n");
if (index == -1) {
trailing = stripped.length();
} else {
trailing = stripped.length() - index - 1;
}

int newCursorPos;
if (lines == 0) {
newCursorPos = trailing + cursorPos;
} else {
newCursorPos = trailing;
}
int newCursorPos;
if (lines == 0) {
newCursorPos = trailing + cursorPos;
} else {
newCursorPos = trailing;
}

if (cursorPos > 1 && lines == 0) {
if (cursorPos > 1 && lines == 0) {
buffer.append(s);
lastWriteCursorX = newCursorPos;
//partial line, just write it
connection.write(buffer.toString());
return;
}
if (lines == 0) {
lines++;
}
//move the existing content up by the number of lines
int appendLines = Math.max(Math.min(cursorPos > 1 ? lines - 1 : lines, totalStatusLines), 1);
clearStatusMessages(buffer);
buffer.append("\033[").append(size.getHeight() - totalStatusLines).append(";").append(0).append("H");
buffer.append(s);
buffer.append("\033[").append(size.getHeight()).append(";").append(0).append("H");
for (int i = 0; i < appendLines; ++i) {
buffer.append("\n");
}
lastWriteCursorX = newCursorPos;
//partial line, just write it
connection.write(buffer.toString());
return;
}
if (lines == 0) {
lines++;
printStatusAndPrompt(buffer);
writeQueue.add(buffer.toString());
}
//move the existing content up by the number of lines
int appendLines = cursorPos > 1 ? lines - 1 : lines;
for (int i = 0; i < appendLines; ++i) {
buffer.append("\n");
}
buffer.append("\033[").append(size.getHeight() - totalStatusLines - lines).append(";").append(0).append("H");
buffer.append(s);
lastWriteCursorX = newCursorPos;
printStatusAndPrompt(buffer);
writeQueue.add(buffer.toString());
}
deadlockSafeWrite();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void promptHandler(InputHandler.ConsoleStatus promptHandler) {
@Override
public void listenerRegistered(TestController testController) {
this.testController = testController;
promptHandler.setStatus(PAUSED_PROMPT);
promptHandler.setPrompt(PAUSED_PROMPT);
}

public void printUsage() {
Expand Down

0 comments on commit c89bd20

Please sign in to comment.