Function: claude-code-ide--vterm-smart-renderer
claude-code-ide--vterm-smart-renderer is a natively compiled function
defined in claude-code-ide.el.
Signature
(claude-code-ide--vterm-smart-renderer ORIG-FUN PROCESS INPUT)
Documentation
Smart rendering filter for optimized vterm display updates.
This advanced filter analyzes terminal output patterns to identify rapid update sequences that benefit from batched processing. It significantly improves visual quality during complex operations.
ORIG-FUN is the underlying filter to enhance. PROCESS is the terminal process being optimized. INPUT contains the terminal output stream.
Source Code
;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide.el
(defun claude-code-ide--vterm-smart-renderer (orig-fun process input)
"Smart rendering filter for optimized vterm display updates.
This advanced filter analyzes terminal output patterns to identify
rapid update sequences that benefit from batched processing.
It significantly improves visual quality during complex operations.
ORIG-FUN is the underlying filter to enhance.
PROCESS is the terminal process being optimized.
INPUT contains the terminal output stream."
(if (or (not claude-code-ide-vterm-anti-flicker)
(not (claude-code-ide--session-buffer-p (process-buffer process))))
;; Feature disabled or not a Claude buffer, pass through normally
(funcall orig-fun process input)
(with-current-buffer (process-buffer process)
;; Fast path: plain text with no active queue skips all pattern detection
;; This optimizes the common case of typing in the prompt
(if (and (not claude-code-ide--vterm-render-queue)
(not (string-search "\033" input)))
(funcall orig-fun process input)
;; Detect rapid terminal redraw sequences
;; Pattern analysis for complex terminal updates:
;; - Vertical cursor movements (ESC[<n>A)
;; - Line clearing operations (ESC[K)
;; - High escape sequence density
(let* ((complex-redraw-detected
;; Pattern: vertical movement + clear, repeated
(string-match-p "\033\\[[0-9]*A.*\033\\[K.*\033\\[[0-9]*A.*\033\\[K" input))
(clear-count (claude-code-ide--count-escape-sequence "\033[K" input))
(escape-count (cl-count ?\033 input))
(input-length (length input))
;; High escape density indicates redrawing, not normal output
(escape-density (if (> input-length 0)
(/ (float escape-count) input-length)
0)))
;; Optimize rendering for detected patterns:
;; 1. Complex redraw sequence detected, OR
;; 2. Escape sequence density exceeds threshold with line operations
;; 3. OR already queuing (to complete the sequence)
(if (or complex-redraw-detected
(and (> escape-density 0.3)
(>= clear-count 2))
claude-code-ide--vterm-render-queue)
(progn
;; Add to queue (list for O(1) push, joined at flush time)
(push input claude-code-ide--vterm-render-queue)
;; Reset existing render timer
(when claude-code-ide--vterm-render-timer
(cancel-timer claude-code-ide--vterm-render-timer))
;; Schedule optimized rendering
;; Timing calibrated for visual quality
(setq claude-code-ide--vterm-render-timer
(run-at-time claude-code-ide-vterm-render-delay nil
(lambda (buf)
(when (buffer-live-p buf)
(with-current-buffer buf
(when claude-code-ide--vterm-render-queue
(let* ((inhibit-redisplay t)
(queue claude-code-ide--vterm-render-queue)
;; Join list in correct order
(data (apply #'concat (nreverse queue))))
;; Clear queue first to prevent recursion
(setq claude-code-ide--vterm-render-queue nil
claude-code-ide--vterm-render-timer nil)
;; Execute queued rendering
(funcall orig-fun
(get-buffer-process buf)
data))))))
(current-buffer))))
;; Standard processing for regular output
(funcall orig-fun process input)))))))