Function: eca-chat--context-bar

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

Signature

(eca-chat--context-bar)

Documentation

Return the propertized context-usage bar string, or nil.

Renders nothing until the server has sent a context breakdown. In graphical frames it draws pixel-width thin segments for high granularity; terminals fall back to block characters. The bar maps the whole window (colored = used, dim = free); percentages and per-category tokens are in the tooltip.

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 ()
  "Return the propertized context-usage bar string, or nil.
Renders nothing until the server has sent a context breakdown.  In
graphical frames it draws pixel-width thin segments for high
granularity; terminals fall back to block characters.  The bar maps
the whole window (colored = used, dim = free); percentages and
per-category tokens are in the tooltip."
  (when-let* ((breakdown eca-chat--context-breakdown)
              (categories (append (plist-get breakdown :categories) nil)))
    (let* ((used (or (plist-get breakdown :usedTokens) 0))
           (free (plist-get breakdown :freeTokens))
           (limit (plist-get breakdown :contextLimit))
           (width (max 1 eca-chat-context-bar-width))
           (graphic? (display-graphic-p))
           (compact-pct (when (and eca-chat-context-bar-show-compaction-marker
                                   (numberp eca-chat--session-auto-compact-percentage)
                                   (> eca-chat--session-auto-compact-percentage 0))
                          eca-chat--session-auto-compact-percentage))
           (key (eca-chat--context-bar-make-cache-key
                 breakdown categories width graphic? compact-pct)))
      (if (equal key eca-chat--context-bar-cache-key)
          eca-chat--context-bar-cache-value
        (let* ((frac (if (and limit (> limit 0))
                         (min 1.0 (/ (float used) limit))
                       1.0))
               (marker-frac (when compact-pct
                              (min 1.0 (/ (float compact-pct) 100.0))))
               (help (eca-chat--context-bar-help
                      breakdown used free limit compact-pct))
               (bar (if graphic?
                        (eca-chat--context-bar-pixels
                         categories breakdown width frac marker-frac)
                      (eca-chat--context-bar-chars
                       categories breakdown width frac marker-frac)))
               (result (propertize
                        bar
                        'help-echo help
                        'local-map eca-chat--context-bar-mode-line-map)))
          (setq-local eca-chat--context-bar-cache-key key)
          (setq-local eca-chat--context-bar-cache-value result))))))