Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot
public class ConsoleConfig {

/**
* If test results and status should be displayed in the console.
*
* If this is false results can still be viewed in the dev console.
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;

/**
* Disables the ability to enter input on the console.
*
*/
@ConfigItem(defaultValue = "false")
public boolean disableInput;
/**
* Disable the testing status/prompt message at the bottom of the console
* and log these messages to STDOUT instead.
*
* Use this option if your terminal does not support ANSI escape sequences.
*/
@ConfigItem(defaultValue = "false")
public boolean basic;

/**
* Disable color in the testing status and prompt messages.
*
* Use this option if your terminal does not support color.
*/
@ConfigItem(defaultValue = "false")
public boolean disableColor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.deployment.dev;

import java.util.function.Consumer;

import io.quarkus.builder.item.SimpleBuildItem;

public final class BrowserOpenerBuildItem extends SimpleBuildItem {

private final Consumer<String> browserOpener;

public BrowserOpenerBuildItem(Consumer<String> browserOpener) {
this.browserOpener = browserOpener;
}

public Consumer<String> getBrowserOpener() {
return browserOpener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

import org.apache.maven.shared.utils.cli.CommandLineException;
import org.apache.maven.shared.utils.cli.CommandLineUtils;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.jboss.logging.Logger;

Expand All @@ -42,6 +44,7 @@
import io.quarkus.deployment.CodeGenerator;
import io.quarkus.deployment.builditem.ApplicationClassPredicateBuildItem;
import io.quarkus.deployment.codegen.CodeGenData;
import io.quarkus.deployment.dev.testing.MessageFormat;
import io.quarkus.deployment.dev.testing.TestSupport;
import io.quarkus.deployment.steps.ClassTransformingBuildStep;
import io.quarkus.deployment.util.FSWatchUtil;
Expand Down Expand Up @@ -96,22 +99,58 @@ public void accept(Integer integer) {
}
final CountDownLatch latch = new CountDownLatch(1);
QuarkusConsole.INSTANCE.pushInputHandler(new InputHandler() {
ConsoleStatus promptHandler;
StringBuilder reading;

@Override
public void handleInput(int[] keys) {

for (int i : keys) {
if (i == 'q') {
System.exit(0);
if (reading != null) {
if (i == '\n') {
try {
context.setArgs(
CommandLineUtils.translateCommandline(reading.toString()));
reading = null;
QuarkusConsole.INSTANCE.popInputHandler();
latch.countDown();
} catch (CommandLineException e) {
log.error("Failed to parse command line", e);
setRestartPrompt(promptHandler);
reading = null;
}
} else {
reading.append((char) i);
}
} else {
QuarkusConsole.INSTANCE.popInputHandler();
latch.countDown();
if (i == 'q') {
System.exit(0);
} else if (i == 'e') {
promptHandler.doReadLine();
reading = new StringBuilder();
break; //discard all further input
} else {
QuarkusConsole.INSTANCE.popInputHandler();
latch.countDown();
}
}
}
}

@Override
public void promptHandler(ConsoleStatus promptHandler) {
promptHandler.setPrompt("\u001B[91mQuarkus application exited with code " + integer
+ "\nPress [q] or Ctrl + C to quit, any other key to restart");
this.promptHandler = promptHandler;
promptHandler.setStatus("\u001B[91mQuarkus application exited with code " + integer
+ MessageFormat.RESET);
setRestartPrompt(promptHandler);
}

private void setRestartPrompt(ConsoleStatus promptHandler) {
promptHandler.setPrompt("Press [" + MessageFormat.BLUE + "q" + MessageFormat.RESET
+ "] or Ctrl + C to quit, [" + MessageFormat.BLUE + "e" + MessageFormat.RESET
+ "] to edit command line args (currently '" + MessageFormat.GREEN
+ String.join(" ", context.getArgs()) + MessageFormat.RESET
+ "'), or any other key to restart");
}
});
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.aesh.terminal.Attributes;
import org.aesh.terminal.Connection;
Expand All @@ -22,6 +24,8 @@ public class AeshConsole extends QuarkusConsole {
private String[] messages = new String[0];
private int totalStatusLines = 0;
private int lastWriteCursorX;
private String lastColorCode; //foreground color code, or reset
private volatile boolean doingReadline;
/**
* if the status area has gotten big then small again
* this tracks how many lines of blank space we have
Expand All @@ -45,6 +49,8 @@ protected Boolean initialValue() {
}
};

static final Pattern ESCAPE = Pattern.compile("\u001b\\[(\\d\\d?)[\\d;]*m");

public AeshConsole(Connection connection, boolean inputSupport) {
this.inputSupport = inputSupport;
INSTANCE = this;
Expand Down Expand Up @@ -179,6 +185,14 @@ public void run() {
if (handler != null) {
handler.handler.handleInput(keys);
}
if (doingReadline) {
for (var k : keys) {
if (k == '\n') {
doingReadline = false;
connection.enterRawMode();
}
}
}
});
}
conn.setCloseHandler(close -> end(conn));
Expand Down Expand Up @@ -235,7 +249,7 @@ private void printStatusAndPrompt(StringBuilder buffer) {
}

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

Expand Down Expand Up @@ -270,6 +284,19 @@ public void write(String s) {
if (IN_WRITE.get()) {
return;
}
if (lastColorCode != null) {
s = lastColorCode + s;
}
Matcher m = ESCAPE.matcher(s);
while (m.find()) {
int val = Integer.parseInt(m.group(1));
if (val == 0 || //reset
(val >= 30 && val <= 39) || //foreground colors
(val >= 90 && val <= 97)) { //bright foreground colors
lastColorCode = m.group(0);
}
}

StringBuilder buffer = new StringBuilder();
synchronized (this) {
if (outputFilter != null) {
Expand Down Expand Up @@ -320,7 +347,8 @@ public void write(String s) {
int appendLines = Math.max(Math.min(cursorPos > 1 ? lines - 1 : lines, totalStatusLines), 1);
appendLines -= usedBlankSpace;
clearStatusMessages(buffer);
buffer.append("\033[").append(size.getHeight() - totalStatusLines - originalBlank).append(";").append(0)
buffer.append("\033[").append(size.getHeight() - totalStatusLines - originalBlank).append(";")
.append(lastWriteCursorX)
.append("H");
buffer.append(s);
buffer.append("\033[").append(size.getHeight()).append(";").append(0).append("H");
Expand Down Expand Up @@ -367,8 +395,17 @@ protected void setCompileErrorMessage(String results) {
@Override
protected void setStatusMessage(String status) {
setMessage(2, status);

}

@Override
public void doReadLine() {
if (!inputSupport) {
return;
}
setPrompt("");
connection.setAttributes(attributes);
doingReadline = true;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,41 @@
import org.aesh.readline.tty.terminal.TerminalConnection;
import org.aesh.terminal.Connection;

import io.quarkus.deployment.ConsoleConfig;
import io.quarkus.deployment.dev.testing.TestConfig;
import io.quarkus.dev.console.BasicConsole;
import io.quarkus.dev.console.QuarkusConsole;
import io.quarkus.dev.console.RedirectPrintStream;

public class ConsoleHelper {

public static synchronized void installConsole(TestConfig config) {
public static synchronized void installConsole(TestConfig config, ConsoleConfig consoleConfig) {
if (QuarkusConsole.installed) {
return;
}
QuarkusConsole.installed = true;
if (config.basicConsole) {
QuarkusConsole.INSTANCE = new BasicConsole(config.disableColor, !config.disableConsoleInput, System.out);
if (config.basicConsole.orElse(consoleConfig.basic)) {
QuarkusConsole.INSTANCE = new BasicConsole(config.disableColor.orElse(consoleConfig.disableColor),
!config.disableConsoleInput.orElse(consoleConfig.disableInput), System.out);
} else {
try {
new TerminalConnection(new Consumer<Connection>() {
@Override
public void accept(Connection connection) {
if (connection.supportsAnsi()) {
QuarkusConsole.INSTANCE = new AeshConsole(connection, !config.disableConsoleInput);
QuarkusConsole.INSTANCE = new AeshConsole(connection,
!config.disableConsoleInput.orElse(consoleConfig.disableInput));
} else {
connection.close();
QuarkusConsole.INSTANCE = new BasicConsole(config.disableColor, !config.disableConsoleInput,
QuarkusConsole.INSTANCE = new BasicConsole(config.disableColor.orElse(consoleConfig.disableColor),
!config.disableConsoleInput.orElse(consoleConfig.disableInput),
System.out);
}
}
});
} catch (IOException e) {
QuarkusConsole.INSTANCE = new BasicConsole(config.disableColor, !config.disableConsoleInput, System.out);
QuarkusConsole.INSTANCE = new BasicConsole(config.disableColor.orElse(consoleConfig.disableColor),
!config.disableConsoleInput.orElse(consoleConfig.disableInput), System.out);
}
}
RedirectPrintStream ps = new RedirectPrintStream();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkus.deployment.dev.testing;

public class MessageFormat {

public static final String RED = "\u001B[91m";
public static final String GREEN = "\u001b[32m";
public static final String BLUE = "\u001b[34m";
public static final String RESET = "\u001b[39m";

private MessageFormat() {
}

public static String statusHeader(String header) {
return RESET + "==================== " + header + RESET + " ====================";
}

public static String statusFooter(String footer) {
return RESET + ">>>>>>>>>>>>>>>>>>>> " + footer + RESET + " <<<<<<<<<<<<<<<<<<<<";
}

public static String toggleStatus(boolean enabled) {
return " (" + (enabled ? GREEN + "enabled" + RESET + "" : RED + "disabled") + RESET + ")";
}

public static String helpOption(String key, String description) {
return "[" + BLUE + key + RESET + "] - " + description;
}

public static String helpOption(String key, String description, boolean enabled) {
return helpOption(key, description) + toggleStatus(enabled);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,49 @@ public class TestConfig {
*/
@ConfigItem(defaultValue = ".*\\.IT[^.]+|.*IT|.*ITCase")
public Optional<String> excludePattern;

/**
* Disable the testing status/prompt message at the bottom of the console
* and log these messages to STDOUT instead.
*
* Use this option if your terminal does not support ANSI escape sequences.
*
* This is deprecated, {@literal quarkus.console.basic} should be used instead.
*/
@ConfigItem(defaultValue = "false")
public boolean basicConsole;
@Deprecated
@ConfigItem
public Optional<Boolean> basicConsole;

/**
* Disable color in the testing status and prompt messages.
*
* Use this option if your terminal does not support color.
*
* This is deprecated, {@literal quarkus.console.disable-color} should be used instead.
*/
@ConfigItem(defaultValue = "false")
public boolean disableColor;
@ConfigItem
@Deprecated
public Optional<Boolean> disableColor;

/**
* If test results and status should be displayed in the console.
*
* If this is false results can still be viewed in the dev console.
*
* This is deprecated, {@literal quarkus.console.enabled} should be used instead.
*/
@ConfigItem(defaultValue = "true")
public boolean console;
@Deprecated
@ConfigItem
public Optional<Boolean> console;

/**
* Disables the ability to enter input on the console.
*
* This is deprecated, {@literal quarkus.console.disable-input} should be used instead.
*/
@ConfigItem(defaultValue = "false")
public boolean disableConsoleInput;
@ConfigItem
@Deprecated
public Optional<Boolean> disableConsoleInput;

/**
* Changes tests to use the 'flat' ClassPath used in Quarkus 1.x versions.
Expand Down
Loading