Skip to content

Commit 3305a7a

Browse files
committed
Add eat backend anti-flicker support
Implement anti-flicker rendering optimization for eat terminal backend, mirroring the existing vterm smart renderer functionality: - Add eat-render-queue and timer variables for batched rendering - Add eat-smart-renderer function with same pattern detection as vterm - Add configure-eat-buffer function with display optimizations - Call configure-eat-buffer from eat session creation - Update vterm-anti-flicker docstring to note it applies to both backends - Rename section from "Vterm Rendering Optimization" to "Terminal Rendering Optimization" This brings feature parity between vterm and eat backends for flicker reduction during Claude's output generation.
1 parent 896aa3b commit 3305a7a

2 files changed

Lines changed: 85 additions & 12 deletions

File tree

README.org

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ This allows you to refine Claude's suggestions before they're applied, ensuring
191191
| ~claude-code-ide-cli-extra-flags~ | Additional CLI flags (e.g. "--model") | ~""~ |
192192
| ~claude-code-ide-debug~ | Enable debug logging | ~nil~ |
193193
| ~claude-code-ide-terminal-backend~ | Terminal backend (vterm or eat) | ~'vterm~ |
194-
| ~claude-code-ide-vterm-anti-flicker~ | Enable vterm flicker reduction | ~t~ |
194+
| ~claude-code-ide-vterm-anti-flicker~ | Enable flicker reduction (vterm and eat) | ~t~ |
195195
| ~claude-code-ide-vterm-render-delay~ | vterm render batching delay (seconds) | ~0.016~ |
196196
| ~claude-code-ide-fix-char-widths~ | Fix Unicode char widths to prevent flicker | ~t~ |
197197
| ~claude-code-ide-terminal-initialization-delay~ | Initialization delay for terminals | ~0.1~ |
@@ -263,12 +263,12 @@ Claude Code IDE supports both =vterm= and =eat= as terminal backends. By default
263263

264264
The =eat= backend is a pure Elisp terminal emulator that may work better in some environments where =vterm= compilation is problematic. Both backends provide full terminal functionality including color support and special key handling.
265265

266-
**** vterm Rendering Optimization
266+
**** Terminal Rendering Optimization
267267

268-
Claude Code IDE includes intelligent flicker reduction for vterm terminals to provide smoother visual output:
268+
Claude Code IDE includes intelligent flicker reduction for both vterm and eat terminals to provide smoother visual output:
269269

270270
#+begin_src emacs-lisp
271-
;; Enable/disable vterm anti-flicker optimization (enabled by default)
271+
;; Enable/disable anti-flicker optimization for vterm and eat (enabled by default)
272272
(setq claude-code-ide-vterm-anti-flicker t)
273273

274274
;; Adjust the render delay for batching updates (default is 0.016 seconds)

claude-code-ide.el

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ This setting should be removed once the upstream bug is fixed."
225225
:group 'claude-code-ide)
226226

227227
(defcustom claude-code-ide-vterm-anti-flicker t
228-
"Enable intelligent flicker reduction for vterm display.
228+
"Enable intelligent flicker reduction for terminal display.
229229
When enabled, this feature optimizes terminal rendering by detecting
230230
and batching rapid update sequences. This provides smoother visual
231231
output during complex terminal operations such as expanding text areas
232232
and rapid screen updates.
233233
234-
This optimization applies only to vterm and uses advanced pattern
235-
matching to maintain responsiveness while improving visual quality."
234+
This optimization applies to both vterm and eat backends, using advanced
235+
pattern matching to maintain responsiveness while improving visual quality."
236236
:type 'boolean
237237
:group 'claude-code-ide)
238238

@@ -300,13 +300,19 @@ single-width in Claude session buffers."
300300
(defvar claude-code-ide--last-accessed-buffer nil
301301
"The most recently accessed Claude Code buffer.")
302302

303-
;;; Vterm Rendering Optimization
303+
;;; Terminal Rendering Optimization
304304

305305
(defvar-local claude-code-ide--vterm-render-queue nil
306-
"Queue for optimizing terminal rendering sequences.")
306+
"Queue for optimizing vterm rendering sequences.")
307307

308308
(defvar-local claude-code-ide--vterm-render-timer nil
309-
"Timer for executing queued rendering operations.")
309+
"Timer for executing queued vterm rendering operations.")
310+
311+
(defvar-local claude-code-ide--eat-render-queue nil
312+
"Queue for optimizing eat terminal rendering sequences.")
313+
314+
(defvar-local claude-code-ide--eat-render-timer nil
315+
"Timer for executing queued eat rendering operations.")
310316

311317
(defun claude-code-ide--fix-char-widths ()
312318
"Set character widths for Claude's Unicode symbols to prevent flickering.
@@ -385,6 +391,52 @@ INPUT contains the terminal output stream."
385391
;; Standard processing for regular output
386392
(funcall orig-fun process input))))))
387393

394+
(defun claude-code-ide--eat-smart-renderer (orig-fun process input)
395+
"Smart rendering filter for optimized eat display updates.
396+
Similar to vterm smart renderer - detects rapid redraw sequences
397+
and batches them for smoother visual output.
398+
399+
ORIG-FUN is the underlying filter to enhance.
400+
PROCESS is the terminal process being optimized.
401+
INPUT contains the terminal output stream."
402+
(if (or (not claude-code-ide-vterm-anti-flicker)
403+
(not (claude-code-ide--session-buffer-p (process-buffer process))))
404+
(funcall orig-fun process input)
405+
(with-current-buffer (process-buffer process)
406+
;; Same pattern detection as vterm: escape density, clear count
407+
(let* ((complex-redraw-detected
408+
(string-match-p "\033\\[[0-9]*A.*\033\\[K.*\033\\[[0-9]*A.*\033\\[K" input))
409+
(clear-count (cl-count-if (lambda (s) (string= s "\033[K"))
410+
(split-string input "\033\\[K" t)))
411+
(escape-count (cl-count ?\033 input))
412+
(input-length (length input))
413+
(escape-density (if (> input-length 0)
414+
(/ (float escape-count) input-length)
415+
0)))
416+
(if (or complex-redraw-detected
417+
(and (> escape-density 0.3) (>= clear-count 2))
418+
claude-code-ide--eat-render-queue)
419+
(progn
420+
(setq claude-code-ide--eat-render-queue
421+
(concat claude-code-ide--eat-render-queue input))
422+
(when claude-code-ide--eat-render-timer
423+
(cancel-timer claude-code-ide--eat-render-timer))
424+
(setq claude-code-ide--eat-render-timer
425+
(run-at-time claude-code-ide-vterm-render-delay nil
426+
(lambda (buf)
427+
(when (buffer-live-p buf)
428+
(with-current-buffer buf
429+
(when claude-code-ide--eat-render-queue
430+
(let ((inhibit-redisplay t)
431+
(data claude-code-ide--eat-render-queue))
432+
(setq claude-code-ide--eat-render-queue nil
433+
claude-code-ide--eat-render-timer nil)
434+
(funcall orig-fun
435+
(get-buffer-process buf)
436+
data))))))
437+
(current-buffer))))
438+
(funcall orig-fun process input))))))
439+
388440
(defvar-local claude-code-ide--saved-cursor-type nil
389441
"Saved cursor-type before entering vterm-copy-mode.")
390442

@@ -436,6 +488,25 @@ cursor management, and process buffering for superior user experience."
436488
(when claude-code-ide-vterm-anti-flicker
437489
(advice-add 'vterm--filter :around #'claude-code-ide--vterm-smart-renderer)))
438490

491+
(defun claude-code-ide--configure-eat-buffer ()
492+
"Configure eat for enhanced performance and visual quality.
493+
Establishes optimal terminal settings including rendering optimizations
494+
and display fixes for superior user experience."
495+
;; Try to prevent cursor flickering by disabling Emacs' own cursor management
496+
(setq-local cursor-in-non-selected-windows nil)
497+
(setq-local blink-cursor-mode nil)
498+
;; disable hl-line-mode, eliminates another source of flicker
499+
(when (featurep 'hl-line)
500+
(hl-line-mode -1))
501+
;; make sure the non-breaking space in the prompt isn't themed
502+
(face-remap-add-relative 'nobreak-space :inherit 'default)
503+
;; Fix character widths for Claude's Unicode symbols
504+
(when claude-code-ide-fix-char-widths
505+
(claude-code-ide--fix-char-widths))
506+
;; Set up rendering optimization
507+
(when claude-code-ide-vterm-anti-flicker
508+
(advice-add 'eat--filter :around #'claude-code-ide--eat-smart-renderer)))
509+
439510

440511
;;; Terminal Backend Abstraction
441512

@@ -813,11 +884,11 @@ when navigating between terminal and other buffers."
813884
(with-selected-window win
814885
(goto-char terminal-point)
815886
(recenter -1))) ; Pin to bottom
816-
;; Terminal out of view: restore visibility
887+
;; Terminal out of view: restore visibility at bottom
817888
((not (pos-visible-in-window-p terminal-point win))
818889
(with-selected-window win
819890
(goto-char terminal-point)
820-
(recenter)))))))))
891+
(recenter -1)))))))))
821892

822893
(defun claude-code-ide--parse-command-string (command-string)
823894
"Parse a command string into (program . args) for eat-exec.
@@ -892,6 +963,8 @@ Signals an error if terminal fails to initialize."
892963
;; Set up eat mode
893964
(unless (eq major-mode 'eat-mode)
894965
(eat-mode))
966+
;; Configure eat buffer for optimal performance
967+
(claude-code-ide--configure-eat-buffer)
895968
;; Configure position preservation if enabled
896969
(when claude-code-ide-eat-preserve-position
897970
(setq-local eat--synchronize-scroll-function

0 commit comments

Comments
 (0)