Skip to content

Commit

Permalink
consolidate fixed-width into shimmers.common.string
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Nov 8, 2024
1 parent e39b358 commit 8594dee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/shimmers/common/edn.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[fipp.ednize :refer [edn IEdn record->tagged]]
[fipp.engine :refer [pprint-document]]
[fipp.visit :refer [visit visit*]]
[shimmers.common.format :refer [fixed-width]]
[shimmers.common.string :refer [fixed-width]]
[thi.ng.geom.types
:refer [Circle2 Line2 LineStrip2 Polygon2 Rect2 Triangle2]]
[thi.ng.geom.vector :refer [Vec2 Vec3]]))
Expand Down
18 changes: 0 additions & 18 deletions src/shimmers/common/format.cljc

This file was deleted.

17 changes: 17 additions & 0 deletions src/shimmers/common/string.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@
;; https://gigamonkeys.com/book/a-few-format-recipes.html
(defn cl-format [fmt & args]
(apply pp/cl-format nil fmt args))

;; See https://github.com/brandonbloom/fipp/issues/83 for symbol hack, basically
;; it's forcing EdnPrinter to believe it's a symbol and not a float so it
;; doesn't wrap it in a string.
(defn fixed-width
"Format float `v` to `width` decimal places as long as it's not infinite."
[v width]
#?(:cljs
(if (or (integer? v) (infinite? v))
v
(symbol (.toFixed v width)))
:clj
(if (or (integer? v)
(= v Double/POSITIVE_INFINITY)
(= v Double/NEGATIVE_INFINITY))
v
(symbol (format (str "%." width "f") v)))))
2 changes: 1 addition & 1 deletion src/shimmers/common/ui/debug.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns shimmers.common.ui.debug
(:require
[shimmers.common.format :as sc-format]
[shimmers.common.string :as sc-format]
#?@(:cljs
[[shimmers.common.edn :as sc-edn]
[shimmers.common.ui.controls :as ctrl]])))
Expand Down

0 comments on commit 8594dee

Please sign in to comment.