Skip to content

Commit 32b39df

Browse files
committed
Remove unwanted ansi chars from the REPL output
The change deletes some arbitrary characters that the Lumo REPL emits.
1 parent 71117d5 commit 32b39df

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

inf-clojure.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ to continue it."
332332
(setq comint-input-filter #'inf-clojure-input-filter)
333333
(setq-local comint-prompt-read-only inf-clojure-prompt-read-only)
334334
(add-hook 'comint-preoutput-filter-functions #'inf-clojure-preoutput-filter nil t)
335+
(add-hook 'comint-output-filter-functions 'inf-clojure--ansi-filter)
335336
(add-hook 'completion-at-point-functions #'inf-clojure-completion-at-point nil t)
336337
(ansi-color-for-comint-mode-on))
337338

@@ -356,6 +357,19 @@ to continue it."
356357
"Remove subprompts from STRING."
357358
(replace-regexp-in-string inf-clojure-subprompt "" string))
358359

360+
(defconst inf-clojure--ansi-clear-line "\\[1G\\|\\[0J\\|\\[13G"
361+
"Ansi codes sent by the lumo repl that we need to clear." )
362+
363+
(defun inf-clojure--ansi-filter (string)
364+
"Filter unwanted ansi character from STRING."
365+
(save-excursion
366+
;; go to start of first line just inserted
367+
(comint-goto-process-mark)
368+
(goto-char (max (point-min) (- (point) (string-width string))))
369+
(forward-line 0)
370+
(while (re-search-forward inf-clojure--ansi-clear-line nil t)
371+
(replace-match ""))))
372+
359373
(defun inf-clojure-preoutput-filter (str)
360374
"Preprocess the output STR from interactive commands."
361375
(cond

0 commit comments

Comments
 (0)