File tree 1 file changed +14
-5
lines changed
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 37
37
" Strip out the colors in a colorstr and return a plain string."
38
38
(.join " " (gfor c x c.char)))
39
39
40
+ (setv color-cache {})
41
+ ; We cache color functions because they can be slow to compute in
42
+ ; 256-color mode, in which case `blessed` needs to find an
43
+ ; approximation for each color.
40
44
(defn bless-colorstr [B x]
41
45
" Render a colorstr `x` into terminal sequences via the
42
46
`blessed.Terminal` object `B`."
43
47
(.join " " (gfor
44
48
c x
45
- :setv fg (B.color-rgb #* (get color.by-name
46
- (or c.fg color.default-fg)))
47
- :setv bg (B.on-color-rgb #* (get color.by-name
48
- (or c.bg color.default-bg)))
49
- (fg (bg c.char)))))
49
+ :setv k #(c.fg c.bg)
50
+ :do (unless (in k color-cache)
51
+ (setv
52
+ fg (B.color-rgb #* (get color.by-name
53
+ (or c.fg color.default-fg)))
54
+ bg (B.on-color-rgb #* (get color.by-name
55
+ (or c.bg color.default-bg)))
56
+ (get color-cache k) (fn [x [fg fg] [bg bg]] (fg (bg x)))))
57
+ ((get color-cache k) c.char))))
58
+
50
59
51
60
(defn colorstr-to-width [x width]
52
61
(cut (+ x (colorstr (* " " (max 0 (- width (len x)))))) width))
You can’t perform that action at this time.
0 commit comments