mirror of
https://github.com/apple/pkl.git
synced 2026-03-26 02:51:13 +01:00
Add colours to Pkl errors in Cli output
To make error messages from Pkl eval easier to read, this change uses the Jansi library to colour the output, making it quicker and easier to scan error messages and understand what's happened. The Jansi library also detects if the CLI output is a terminal capable of handling colours, and will automatically strip out escape codes if the output won't support them (e.g. piping the output somewhere else).
This commit is contained in:
committed by
Philip K.F. Hölzenspies
parent
49aaf288cc
commit
0d7b95d3ff
@@ -17,6 +17,7 @@ package org.pkl.commons.cli
|
||||
|
||||
import java.io.PrintStream
|
||||
import kotlin.system.exitProcess
|
||||
import org.fusesource.jansi.AnsiConsole
|
||||
|
||||
/** Building block for CLIs. Intended to be called from a `main` method. */
|
||||
fun cliMain(block: () -> Unit) {
|
||||
@@ -27,6 +28,9 @@ fun cliMain(block: () -> Unit) {
|
||||
if (!message.endsWith('\n')) stream.println()
|
||||
}
|
||||
|
||||
// Setup AnsiConsole. This will automatically strip escape codes if
|
||||
// the target shell doesn't appear to support them.
|
||||
AnsiConsole.systemInstall()
|
||||
// Force `native-image` to use system proxies (which does not happen with `-D`).
|
||||
System.setProperty("java.net.useSystemProxies", "true")
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user