-
Notifications
You must be signed in to change notification settings - Fork 3
Rewrite Terminal formatter with Prettyprinter #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
pbrisbin
wants to merge
8
commits into
main
Choose a base branch
from
pb/pretty
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This change removes the manual `Text`-building of our current terminal formatter and instead uses `Prettyprinter`. This is a much better tool for the job and produces very nice output in less code. The actual resulting terminal output was improved in a few small ways: 1. The colors of attributes is improved, because `Prettyprinter`'s annotations system makes it easier to do fancier things 2. Long messages that themselves span the breakpoint are wrapped in a hanging-indent style, since that too is easier to do with `Prettyprinter`. It may have been possible to do this in a way opaque to end-users, except for one thing: colors. The best-practice way to ansi-escape `Prettyprinter` output is to use its annotations feature. Elements within a `Doc` are annotated with the bits that should be colored at render timer. It's also a best-practice to annotate your `Doc`, not directly with color escapes, but with semantic annotations (see our `Ann` type). Those can then be mapped centrally to color escapes, again as part of rendering (see our `annToAnsi` function). This approach comes with a number of nice properties for our use-case in Blammo: it means the choice of colors-or-not, and what those colors are, need not be known and passed around at the time log messages are _built_. Rather, it is centralized at the place where the log messages are rendered. Therefore, I decided to lean into this and entirely replace our `Color` module with the `Terminal.Doc.Ann` type. For example, there is no longer a feature like `getLoggerColors`, which was meant to provide end-users colors-or-not as appropriate. Instead, such users can use `Ann` all the time and the colors-or-not concern is handled later. Most users, those who are not actually building and pushing messages directly to `Logger`, are not affected by this, but those that are will require pretty big changes with this new version.
pbrisbin
commented
Dec 8, 2025
| getLoggerReformat = lReformat | ||
|
|
||
| setLoggerReformat | ||
| :: (LogSettings -> Colors -> LogLevel -> LoggedMessage -> ByteString) |
Member
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example simplification: the "reformat" concern doesn't need the settings or colors because those are now only necessary for layout, which happens in the rendering step (where those things were already available).
- Add lts21, 22, and 24 - Symlink stack.yaml to latest (lts24)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change removes the manual
Text-building of our current terminalformatter and instead uses
Prettyprinter. This is a much better toolfor the job and produces very nice output in less code.
The actual resulting terminal output was improved in a few small ways:
Prettyprinter'sannotations system makes it easier to do fancier things
hanging-indent style, since that too is easier to do with
Prettyprinter.It may have been possible to do this in a way opaque to end-users,
except for one thing: colors.
The best-practice way to ansi-escape
Prettyprinteroutput is to useits annotations feature. Elements within a
Docare annotated with thebits that should be colored at render time. It's also a best-practice
to annotate your
Doc, not directly with color escapes, but withsemantic annotations (see our
Anntype). Those can then be mappedcentrally to color escapes, again as part of rendering (see our
annToAnsifunction).This approach comes with a number of nice properties for our use-case in
Blammo: it means the choice of colors-or-not, and what those colors are,
need not be known and passed around at the time log messages are
built. Rather, it is centralized at the place where the log messages
are rendered.
Therefore, I decided to lean into this and entirely replace our
Colormodule with the
Terminal.Doc.Anntype. For example, there is no longera feature like
getLoggerColors, which was meant to provide end-userscolors-or-not as appropriate. Instead, such users can use
Annall thetime and the colors-or-not concern is handled later.
Most users, those who are not actually building and pushing messages
directly to
Logger, are not affected by this, but those that are willrequire pretty big changes with this new version.