Function: eca-chat--context-bar-chars

eca-chat--context-bar-chars is a natively compiled function defined in eca-chat.el.

Signature

(eca-chat--context-bar-chars CATEGORIES BREAKDOWN WIDTH FRAC &optional MARKER-FRAC)

Documentation

Build the block-character context bar string for terminal frames.

CATEGORIES/BREAKDOWN carry the usage data, WIDTH is the cell count and FRAC the used fraction (0..1). The used/free edge uses a fractional block for sub-cell precision. MARKER-FRAC, when non-nil, draws the auto-compaction threshold marker on the matching cell.

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-chars (categories breakdown width frac &optional marker-frac)
  "Build the block-character context bar string for terminal frames.
CATEGORIES/BREAKDOWN carry the usage data, WIDTH is the cell count and
FRAC the used fraction (0..1).  The used/free edge uses a fractional
block for sub-cell precision.  MARKER-FRAC, when non-nil, draws the
auto-compaction threshold marker on the matching cell."
  (let* ((colored-exact (* width frac))
         (colored-cells (min width (floor colored-exact)))
         (edge-eighths (if (< colored-cells width)
                           (min 7 (max 0 (round (* 8 (- colored-exact colored-cells)))))
                         0))
         (tokens (mapcar (lambda (c) (max 0 (or (plist-get c :tokens) 0))) categories))
         (alloc (eca-chat--context-bar-allocate tokens colored-cells))
         (bar ""))
    (cl-loop for cat in categories for n in alloc
             when (> n 0)
             do (setq bar (concat bar (propertize (make-string n ?█)
                                                  'face (eca-chat--context-category-face-spec cat)))))
    (when (> edge-eighths 0)
      (setq bar (concat bar (propertize (aref eca-chat--context-bar-eighths edge-eighths)
                                        'face (eca-chat--context-bar-edge-spec categories alloc)))))
    (let ((free-cells (- width (length bar))))
      (when (> free-cells 0)
        (setq bar (concat bar (propertize (make-string free-cells ?█)
                                          'face (eca-chat--context-free-face-spec breakdown))))))
    (when (and marker-frac (> (length bar) 0))
      (let ((idx (min (1- (length bar))
                      (max 0 (floor (* width (min 1.0 (max 0.0 marker-frac))))))))
        (setq bar (concat (substring bar 0 idx)
                          (propertize "│" 'face 'eca-chat-context-compaction-marker-face)
                          (substring bar (1+ idx))))))
    bar))