Skip to content

Commit 1de1234

Browse files
Fix some rich console bugs:
- Large stack traces would loose color - Large stack traces can loose some output - Use 'default forground' instead of 'reset all'
1 parent ae27223 commit 1de1234

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

core/deployment/src/main/java/io/quarkus/deployment/dev/console/AeshConsole.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.concurrent.LinkedBlockingDeque;
44
import java.util.concurrent.locks.Lock;
55
import java.util.concurrent.locks.ReentrantLock;
6+
import java.util.regex.Matcher;
7+
import java.util.regex.Pattern;
68

79
import org.aesh.terminal.Attributes;
810
import org.aesh.terminal.Connection;
@@ -22,6 +24,7 @@ public class AeshConsole extends QuarkusConsole {
2224
private String[] messages = new String[0];
2325
private int totalStatusLines = 0;
2426
private int lastWriteCursorX;
27+
private String lastColorCode; //foreground color code, or reset
2528
private volatile boolean doingReadline;
2629
/**
2730
* if the status area has gotten big then small again
@@ -46,6 +49,8 @@ protected Boolean initialValue() {
4649
}
4750
};
4851

52+
static final Pattern ESCAPE = Pattern.compile("\u001b\\[(\\d\\d?)[\\d;]*m");
53+
4954
public AeshConsole(Connection connection, boolean inputSupport) {
5055
this.inputSupport = inputSupport;
5156
INSTANCE = this;
@@ -244,7 +249,7 @@ private void printStatusAndPrompt(StringBuilder buffer) {
244249
}
245250

246251
private void clearStatusMessages(StringBuilder buffer) {
247-
gotoLine(buffer, size.getHeight() - totalStatusLines);
252+
gotoLine(buffer, size.getHeight() - totalStatusLines + 1);
248253
buffer.append("\033[J");
249254
}
250255

@@ -279,6 +284,19 @@ public void write(String s) {
279284
if (IN_WRITE.get()) {
280285
return;
281286
}
287+
if (lastColorCode != null) {
288+
s = lastColorCode + s;
289+
}
290+
Matcher m = ESCAPE.matcher(s);
291+
while (m.find()) {
292+
int val = Integer.parseInt(m.group(1));
293+
if (val == 0 || //reset
294+
(val >= 30 && val <= 39) || //foreground colors
295+
(val >= 90 && val <= 97)) { //bright foreground colors
296+
lastColorCode = m.group(0);
297+
}
298+
}
299+
282300
StringBuilder buffer = new StringBuilder();
283301
synchronized (this) {
284302
if (outputFilter != null) {
@@ -329,7 +347,8 @@ public void write(String s) {
329347
int appendLines = Math.max(Math.min(cursorPos > 1 ? lines - 1 : lines, totalStatusLines), 1);
330348
appendLines -= usedBlankSpace;
331349
clearStatusMessages(buffer);
332-
buffer.append("\033[").append(size.getHeight() - totalStatusLines - originalBlank).append(";").append(0)
350+
buffer.append("\033[").append(size.getHeight() - totalStatusLines - originalBlank).append(";")
351+
.append(lastWriteCursorX)
333352
.append("H");
334353
buffer.append(s);
335354
buffer.append("\033[").append(size.getHeight()).append(";").append(0).append("H");

core/deployment/src/main/java/io/quarkus/deployment/dev/testing/MessageFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class MessageFormat {
55
public static final String RED = "\u001B[91m";
66
public static final String GREEN = "\u001b[32m";
77
public static final String BLUE = "\u001b[34m";
8-
public static final String RESET = "\u001b[0m";
8+
public static final String RESET = "\u001b[39m";
99

1010
private MessageFormat() {
1111
}

core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConsoleHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class TestConsoleHandler implements TestListener {
3434

3535
private static final Logger log = Logger.getLogger("io.quarkus.test");
3636

37-
public static final String PAUSED_PROMPT = "Tests paused, press [" + BLUE + "r" + RESET + "] to resume, [" + BLUE + "h"
37+
public static final String PAUSED_PROMPT = "Tests paused, press [" + BLUE + "r" + RESET + "] to resume, [" + BLUE + "w"
38+
+ RESET + "] to open the browser, " + RESET + " [" + BLUE + "h"
3839
+ RESET + "] for more options>" + RESET;
3940
public static final String PAUSED_PROMPT_NO_HTTP = "Tests paused, press [" + BLUE + "r" + RESET + "] to resume, [" + BLUE
4041
+ "s" + RESET + "] to restart with changes, [" + BLUE + "h"
@@ -89,7 +90,7 @@ public void handleInput(int[] keys) {
8990
for (int k : keys) {
9091
if (k == 'h') {
9192
printUsage();
92-
} else if (k == 'b' && devModeType != DevModeType.TEST_ONLY) {
93+
} else if (k == 'w' && devModeType != DevModeType.TEST_ONLY) {
9394
browserOpener.accept("/");
9495
} else if (k == 'd' && devModeType != DevModeType.TEST_ONLY) {
9596
browserOpener.accept("/q/dev");
@@ -166,9 +167,9 @@ public void printUsage() {
166167
System.out
167168
.println(helpOption("i", "Toggle instrumentation based reload", testController.isInstrumentationEnabled()));
168169
System.out.println(helpOption("l", "Toggle live reload", testController.isLiveReloadEnabled()));
169-
System.out.println(helpOption("s", "Force restart with any changes"));
170+
System.out.println(helpOption("s", "Force restart"));
170171
if (hasHttp) {
171-
System.out.println(helpOption("b", "Open the application in a browser"));
172+
System.out.println(helpOption("w", "Open the application in a browser"));
172173
System.out.println(helpOption("d", "Open the Dev UI in a browser"));
173174
}
174175
}

docs/src/main/asciidoc/continuous-testing.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ The following commands are available:
100100
[o] - Toggle test output (disabled)
101101
[i] - Toggle instrumentation based reload (disabled)
102102
[l] - Toggle live reload (enabled)
103-
[s] - Force restart with any changes
103+
[s] - Force restart
104104
[h] - Display this help
105105
[q] - Quit
106106
----
@@ -138,9 +138,9 @@ state.
138138
[l] - Toggle live reload::
139139
This is not directly related to testing, but allows you to turn live reload on and off.
140140

141-
[s] - Force restart with any changes::
142-
This will force a scan for changed file, and will perform a live reload if anything has changed. This will still work even
143-
if live reload is disabled.
141+
[s] - Force restart::
142+
This will force a scan for changed files, and will perform a live reload with and changes. Note that even if there are no
143+
changes the application will still restart. This will still work even if live reload is disabled.
144144

145145
== Continuous Testing Without Dev Mode
146146

extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.quarkus.vertx.http.deployment.devmode.console;
22

3-
import java.awt.*;
43
import java.io.File;
54
import java.io.IOException;
65
import java.io.Reader;

0 commit comments

Comments
 (0)