Skip to content

Commit 2a87647

Browse files
authored
Merge pull request #44 from lambdaisland/laurence/setup-customer-printer
Laurence/setup customer printer
2 parents c87d9db + d406b7a commit 2a87647

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,38 @@ code and results.
148148
(lambdaisland.deep-diff2.puget.color/document printer :keyword (str (.-unit value)))]))
149149
```
150150

151+
### Set up a custom print handler with different colors by utilizing Puget library
152+
153+
Sometimes, we need to tune the colors to:
154+
155+
- Ensure adequate contrast on a different background.
156+
- Ensure readability by people who are colorblind.
157+
- Match your editor or main diff tool's color scheme.
158+
159+
#### Config of Puget
160+
161+
Fortunately, the Puget library included in deep-diff2 already allows customization through a custom printer.
162+
163+
In the Puget libray, 8-bit scheme is expressed via `[:fg-256 5 n]` where n is between 0 and 255. We can combine foreground and background, for example, like so: `[:fg-256 5 226 :bg-256 5 56]`.
164+
165+
24-bit scheme is expressed via `[:fg-256 2 r g b]` where r g b are each between 0 and 255. Foreground and background can be combined, for example: `[:fg-256 2 205 236 255 :bg-256 2 110 22 188]`.
166+
167+
#### An example of customizing color
168+
169+
For example, if we change the `:lambdaisland.deep-diff2.printer-impl/deletion` from `[:red]` to `[:bg-256 5 13]`, the color code it outputs will change from `\u001b[31m` to `\u001b[48;5;13m`
170+
171+
```
172+
user=> (use 'lambdaisland.deep-diff2)
173+
nil
174+
user=> (def color-printer (printer {:color-scheme {:lambdaisland.deep-diff2.printer-impl/deletion [:bg-256 5 13]}}))
175+
#'user/color-printer
176+
user=> (pretty-print (diff {:a 1} {:b 2}) color-printer)
177+
{+:b 2, -:a 1}
178+
```
179+
180+
That results in the following highlighting:
181+
![screenshot showing color customization](color-scheme.png)
182+
151183
### Time, data literal
152184

153185
A common use case is diffing and printing Java date and time objects

color-scheme.png

169 KB
Loading

0 commit comments

Comments
 (0)