|
127 | 127 | [type handler] |
128 | 128 | (swap! print-handlers assoc type handler)) |
129 | 129 |
|
| 130 | +(defn- color-scheme-mapping |
| 131 | + "Translates user-friendly keys to internal namespaced keys." |
| 132 | + [colors] |
| 133 | + (let [mapping {:lambdaisland.deep-diff2/deletion ::deletion |
| 134 | + :lambdaisland.deep-diff2/insertion ::insertion |
| 135 | + :lambdaisland.deep-diff2/other ::other}] |
| 136 | + (reduce-kv (fn [m k v] |
| 137 | + (assoc m (get mapping k k) v)) ;; Fallback to original key if not in mapping |
| 138 | + {} |
| 139 | + colors))) |
| 140 | + |
130 | 141 | (defn puget-printer |
131 | 142 | ([] |
132 | 143 | (puget-printer {})) |
133 | 144 | ([opts] |
134 | | - (let [extra-handlers (:extra-handlers opts)] |
135 | | - (puget-printer/pretty-printer (merge {:width (or *print-length* 100) |
136 | | - :print-color true |
137 | | - :color-scheme {::deletion [:red] |
138 | | - ::insertion [:green] |
139 | | - ::other [:yellow] |
| 145 | + (let [opts (update opts :color-scheme color-scheme-mapping) |
| 146 | + extra-handlers (:extra-handlers opts)] |
| 147 | + (puget-printer/pretty-printer (puget-printer/merge-options {:width (or *print-length* 100) |
| 148 | + :print-color true |
| 149 | + :color-scheme {::deletion [:red] |
| 150 | + ::insertion [:green] |
| 151 | + ::other [:yellow] |
140 | 152 | ;; lambdaisland.deep-diff2.puget uses green and red for |
141 | 153 | ;; boolean/tag, but we want to reserve |
142 | 154 | ;; those for diffed values. |
143 | | - :boolean [:bold :cyan] |
144 | | - :tag [:magenta]} |
145 | | - :print-handlers (dispatch/chained-lookup |
146 | | - (print-handler-resolver extra-handlers) |
147 | | - puget-printer/common-handlers)} |
148 | | - (dissoc opts :extra-handlers)))))) |
| 155 | + :boolean [:bold :cyan] |
| 156 | + :tag [:magenta]} |
| 157 | + :print-handlers (dispatch/chained-lookup |
| 158 | + (print-handler-resolver extra-handlers) |
| 159 | + puget-printer/common-handlers)} |
| 160 | + (dissoc opts :extra-handlers)))))) |
149 | 161 |
|
150 | 162 | (defn format-doc [expr printer] |
151 | 163 | (puget-printer/format-doc printer expr)) |
|
0 commit comments