Skip to content

Pretty view mode #335

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

Merged
merged 14 commits into from
Apr 18, 2025
Prev Previous commit
Next Next commit
Use a boolean for the pretty print option
  • Loading branch information
r0man committed Apr 17, 2025
commit 43b43476e0e56cd9e3164385358f6d5a003c7011
14 changes: 7 additions & 7 deletions src/orchard/inspect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"Print or pretty print the string `value`, depending on the view mode
of the inspector."
[{:keys [indentation pretty-print]} value]
(if (= "true" pretty-print)
(if pretty-print
(print/pprint-str value {:indentation (or indentation 0)})
(print/print-str value)))

Expand Down Expand Up @@ -229,7 +229,7 @@
(when (some? max-nested-depth) (pre-ex (pos-int? max-nested-depth)))
(when (some? display-analytics-hint) (pre-ex (= display-analytics-hint "true")))
(when (some? analytics-size-cutoff) (pre-ex (pos-int? analytics-size-cutoff)))
(when (some? pretty-print) (pre-ex (#{"true" "false"} pretty-print)))
(when (some? pretty-print) (pre-ex (#{true false} pretty-print)))
(select-keys config (keys default-inspector-config)))

(defn refresh
Expand Down Expand Up @@ -356,7 +356,7 @@

(defn render-labeled-value [{:keys [pretty-print] :as inspector} label value & [value-opts]]
(let [formatted-label (str label ": ")
indentation (if (= "true" pretty-print) (count formatted-label) 0)]
indentation (if pretty-print (count formatted-label) 0)]
(-> inspector
(render-indent formatted-label)
(indent indentation)
Expand Down Expand Up @@ -402,7 +402,7 @@
`rendered-key` is long or contains newlines the key and value will
be rendered on separate lines."
[{:keys [pretty-print] :as inspector} long-key?]
(if (and (= "true" pretty-print) long-key?)
(if (and pretty-print long-key?)
(-> (render-ln inspector)
(render-indent "=")
(render-ln))
Expand All @@ -412,7 +412,7 @@
"Render a map value. If `mark-values?` is true, attach the keys to the
values in the index."
[{:keys [pretty-print] :as inspector} key val mark-values? rendered-key long-key?]
(if (= "true" pretty-print)
(if pretty-print
(let [indentation (if long-key? 0 (+ 3 (count rendered-key)))]
(-> (indent inspector indentation)
(render (if (zero? indentation) " " ""))
Expand Down Expand Up @@ -503,7 +503,7 @@
(loop [ins inspector, chunk (seq chunk), idx idx-starts-from]
(if chunk
(let [header (str (format idx-fmt idx) ". ")
indentation (if (= "true" pretty-print) (count header) 0)]
indentation (if pretty-print (count header) 0)]
(recur (-> ins
(render-indent header)
(indent indentation)
Expand Down Expand Up @@ -1006,7 +1006,7 @@
;; render a ton of # characters when
;; there is still enough screen estate
;; in most cases.
(and (= "true" pretty-print) (number? max-nested-depth))
(and pretty-print (number? max-nested-depth))
(* 2))]
(-> inspector
(reset-render-state)
Expand Down
10 changes: 5 additions & 5 deletions test/orchard/inspect_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@
{:a -1 :bb "111" :ccc [1]}
{:a 2 :bb "222" :ccc [1 2]}]}
(inspect/start)
(set-pretty-print "true")
(set-pretty-print true)
render)]
(is+ ["--- Contents:" [:newline] " "
[:value ":a" 1] " = " [:value "0" 2]
Expand All @@ -1604,7 +1604,7 @@
{:a 2 :bb "222" :ccc [1 2]}]}
(inspect/start)
(inspect/set-view-mode :object)
(set-pretty-print "true")
(set-pretty-print true)
render)]
(is+ ["Value: "
[:value (str "{:a 0,\n"
Expand All @@ -1629,7 +1629,7 @@
:bb (str i i i)
:ccc (range i 0 -1)})})
(inspect/start)
(set-pretty-print "true")
(set-pretty-print true)
render)]
(is+ ["--- Contents:" [:newline]
" 0. "
Expand Down Expand Up @@ -1670,7 +1670,7 @@
{:a -3 :bb "333" :ccc [3 2 1]}
{:a -4 :bb "444" :ccc [4 3 2 1]}]}}
(inspect/start)
(set-pretty-print "true")
(set-pretty-print true)
render)]
(is+ ["--- Contents:" [:newline] " "
[:value (str "{:a 0,\n :bb \"000\",\n :ccc [],\n :d\n "
Expand Down Expand Up @@ -1704,7 +1704,7 @@
{:a -1 :bb "111" :ccc [1]}
{:a 2 :bb "222" :ccc [1 2]}]}}
(inspect/start)
(set-pretty-print "true")
(set-pretty-print true)
render)]
(is+ ["--- Contents:" [:newline] " "
[:value (str "[{:a 0,\n :bb \"000\",\n :ccc [],\n :d\n "
Expand Down