Function: eca-chat--context-bar-pixels
eca-chat--context-bar-pixels is a natively compiled function defined
in eca-chat.el.
Signature
(eca-chat--context-bar-pixels CATEGORIES BREAKDOWN WIDTH FRAC &optional MARKER-FRAC)
Documentation
Build the pixel-width thin-segment context bar for graphical frames.
CATEGORIES/BREAKDOWN carry the usage data; each category is a
:background-colored space whose pixel width is proportional to its
share, giving sub-character granularity so small percentages still
show as a thin sliver. WIDTH is the footprint in characters and FRAC
the used fraction (0..1). MARKER-FRAC, when non-nil, overlays the
auto-compaction threshold marker at that fraction of the bar.
Source Code
;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defun eca-chat--context-bar-pixels (categories breakdown width frac &optional marker-frac)
"Build the pixel-width thin-segment context bar for graphical frames.
CATEGORIES/BREAKDOWN carry the usage data; each category is a
`:background'-colored space whose pixel width is proportional to its
share, giving sub-character granularity so small percentages still
show as a thin sliver. WIDTH is the footprint in characters and FRAC
the used fraction (0..1). MARKER-FRAC, when non-nil, overlays the
auto-compaction threshold marker at that fraction of the bar."
(let* ((char-px (max 1 (frame-char-width)))
(total-px (* width char-px))
(used-px (min total-px (round (* total-px frac))))
(tokens (mapcar (lambda (c) (max 0 (or (plist-get c :tokens) 0))) categories))
(alloc (eca-chat--context-bar-allocate tokens used-px))
(segs nil)
(drawn 0))
(cl-loop for cat in categories for px in alloc
when (> px 0)
do (push (cons px (eca-chat--context-category-color cat)) segs)
(setq drawn (+ drawn px)))
(let ((free-px (- total-px drawn)))
(when (> free-px 0)
(push (cons free-px (eca-chat--context-free-color breakdown)) segs)))
(setq segs (nreverse segs))
(when (and marker-frac segs)
(setq segs (eca-chat--context-bar-pixels-insert-marker
segs (round (* total-px (min 1.0 (max 0.0 marker-frac)))))))
(mapconcat (lambda (s)
(propertize " "
'display (list 'space :width (list (car s)))
'face (list :background (cdr s))))
segs "")))