diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-26 12:09:55 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-26 12:09:55 -0400 |
| commit | 706bf8ebef2acc91db3782966904f601bb1084ae (patch) | |
| tree | 1dae3f17d45f1be3239ad9cd795d4d00d6314162 /modules/eat-config.el | |
| parent | ed8f4781d953fca0052765518a17cca15f2167ab (diff) | |
| download | dotemacs-706bf8ebef2acc91db3782966904f601bb1084ae.tar.gz dotemacs-706bf8ebef2acc91db3782966904f601bb1084ae.zip | |
feat(eat): reset SGR at newline to contain unterminated-color bleed
Claude Code and similar inline TUIs sometimes truncate a colored span without emitting a reset; the unterminated color then bleeds onto every following line in the EAT buffer. Advise eat-term-process-output to inject an SGR reset before each newline, containing the bleed to its own line. Validated in real EAT and via an ansi-color proxy: it contains the bleed and leaves per-line coloring intact, since programs re-open their color on each line. Gated by cj/eat-reset-sgr-at-newline (default on) so it can be disabled if a program ever carries one color across newlines without re-opening it.
Diffstat (limited to 'modules/eat-config.el')
| -rw-r--r-- | modules/eat-config.el | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/eat-config.el b/modules/eat-config.el index 317f6a63f..74012b9b6 100644 --- a/modules/eat-config.el +++ b/modules/eat-config.el @@ -48,6 +48,31 @@ but it makes each jump gentler." (setq-local scroll-margin 0) (setq-local auto-window-vscroll nil)) +(defcustom cj/eat-reset-sgr-at-newline t + "When non-nil, EAT resets SGR (color) at each newline. +Claude Code and similar inline TUIs sometimes truncate a colored span without +emitting a reset; the unterminated color then bleeds onto every following line +in the buffer. Injecting a reset before each newline contains it to its own +line. Safe for the common case where programs re-open their color per line; a +program that carries a single color across newlines without re-opening it would +lose that color past the first line, so set this to nil if you hit that." + :type 'boolean + :group 'eat) + +(declare-function eat-term-process-output "eat") + +(defun cj/--eat-reset-sgr-at-newline (args) + "`:filter-args' advice for `eat-term-process-output'. +When `cj/eat-reset-sgr-at-newline' is non-nil, inject an SGR reset before each +newline in the pty OUTPUT so an unterminated color cannot bleed past its line. +ARGS is (TERMINAL OUTPUT)." + (if cj/eat-reset-sgr-at-newline + (list (car args) + (replace-regexp-in-string "\n" "\e[0m\n" (cadr args) t t)) + args)) + +(advice-add 'eat-term-process-output :filter-args #'cj/--eat-reset-sgr-at-newline) + ;; ------------------------------- eat package --------------------------------- (use-package eat |
