Skip to content

Commit

Permalink
Add merge-options and with-options helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
greglook committed Jun 24, 2014
1 parent 246e823 commit f7f3c0e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/puget/printer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,36 @@
:class-name [:bold :blue]}})


(defn merge-options
"Merges a map of options into the current option map, taking care to combine
the color scheme correctly."
[opts]
(let [colors (merge (:color-scheme *options*)
(:color-scheme opts))]
(-> *options*
(merge opts)
(assoc :color-scheme colors))))


(defmacro with-options
"Executes the given expressions with a set of options merged into the current
option map."
[opts & body]
`(binding [*options* (merge-options ~opts)]
~@body))


(defmacro with-color
"Executes the given expressions with colored output enabled."
[& body]
`(binding [*options* (assoc *options* :print-color true)]
`(with-options {:print-color true}
~@body))


(defmacro with-strict-mode
"Executes the given expressions with strict mode enabled."
[& body]
`(binding [*options* (assoc *options* :strict true)]
`(with-options {:strict true}
~@body))


Expand Down

0 comments on commit f7f3c0e

Please sign in to comment.