[PR #552] [MERGED] Add colours to Pkl errors in Cli output #618

Closed
opened 2025-12-30 01:25:41 +01:00 by adam · 0 comments
Owner

📋 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: mainHead: add-color


📝 Commits (2)

  • 65c9ce3 Add colours to Pkl errors in Cli output
  • 6ffc739 Add 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.

image
image
image


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/apple/pkl/pull/552 **Author:** [@thomaspurchas](https://github.com/thomaspurchas) **Created:** 6/27/2024 **Status:** ✅ Merged **Merged:** 7/1/2024 **Merged by:** [@holzensp](https://github.com/holzensp) **Base:** `main` ← **Head:** `add-color` --- ### 📝 Commits (2) - [`65c9ce3`](https://github.com/apple/pkl/commit/65c9ce30840479368cd05f3ac9418eccc60568ba) Add colours to Pkl errors in Cli output - [`6ffc739`](https://github.com/apple/pkl/commit/6ffc739731e3a6e31b4abb013e72bd9d21aa101e) Add test for colour outputs ### 📊 Changes **28 files changed** (+147 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `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_ </details> ### 📄 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](https://ajalt.github.io/mordant/) to really supercharge the output formatting. ![image](https://github.com/apple/pkl/assets/782311/3381e7df-ef4e-4d56-9a87-468008dbd0f0) <img width="1050" alt="image" src="https://github.com/apple/pkl/assets/782311/6711e87a-9e1d-47b7-b60e-a949bda98990"> <img width="1282" alt="image" src="https://github.com/apple/pkl/assets/782311/c9198942-4a12-421b-9042-adf7afcaccf5"> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 01:25:41 +01:00
adam closed this issue 2025-12-30 01:25:41 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#618