mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
[PR #552] [MERGED] Add colours to Pkl errors in Cli output #618
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/552
Author: @thomaspurchas
Created: 6/27/2024
Status: ✅ Merged
Merged: 7/1/2024
Merged by: @holzensp
Base:
main← Head:add-color📝 Commits (2)
65c9ce3Add colours to Pkl errors in Cli output6ffc739Add test for colour outputs📊 Changes
28 files changed (+147 additions, -28 deletions)
View changed files
📝
bench/gradle.lockfile(+1 -0)📝
buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts(+3 -0)📝
docs/gradle.lockfile(+1 -0)📝
pkl-cli/gradle.lockfile(+1 -1)📝
pkl-cli/pkl-cli.gradle.kts(+3 -2)📝
pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt(+1 -0)📝
pkl-codegen-java/gradle.lockfile(+1 -0)📝
pkl-codegen-kotlin/gradle.lockfile(+1 -0)📝
pkl-commons-cli/gradle.lockfile(+1 -0)📝
pkl-commons-cli/pkl-commons-cli.gradle.kts(+1 -1)📝
pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliMain.kt(+4 -0)📝
pkl-commons-test/gradle.lockfile(+1 -0)📝
pkl-commons-test/pkl-commons-test.gradle.kts(+1 -0)📝
pkl-config-java/gradle.lockfile(+1 -0)📝
pkl-config-kotlin/gradle.lockfile(+1 -0)📝
pkl-core/gradle.lockfile(+1 -0)📝
pkl-core/pkl-core.gradle.kts(+2 -0)📝
pkl-core/src/main/java/org/pkl/core/runtime/StackTraceRenderer.java(+45 -17)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmExceptionRenderer.java(+9 -2)➕
pkl-core/src/test/kotlin/org/pkl/core/ErrorColoringTest.kt(+54 -0)...and 8 more files
📄 Description
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).
The implementation is a little crude, but think acceptable given a better approach would probably require rewriting how errors are handled completely, so that the output composition happens near the frontend of the CLI, rather than down in the bowls of Pkl. The CLI frontend is in a much better position to determine terminal capabilities, and adjust outputs as needed, and would allow us to use a much more expressive library like Mordant to really supercharge the output formatting.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.