4

I can't seem to identify this color sequence. I have enabled ansi colors successfully (to test, ls shows colored output), however a strange thing happens when I attempt to run npm and I can't identify the kind of colors these are, or how to make it so eshell can show them. The output is as follows

Usage npm <command>
... <remainder of usage here>
npm @ 3.3.10 /usr/lib/node_modules/npm
^[[?25h^[[0G^[[?25h^[[0G~/my/directory/that/i/am/in $

I have tried to look for things like "non-ansi color codes" and "npm color codes" and none of them have pointed me in the correct direction.

Can anyone identify these colors and help me figure out how to display them properly?

Thanks!

EDIT:

I have identified these as unicode sequences. I have added everything in:

https://www.masteringemacs.org/article/working-coding-systems-unicode-emacs

as well as the following code for Eshell specifically:

(defun set-buffer-utf8 ()
   (set-buffer-process-coding-system 'utf-8 'utf-8)
 )
 (add-hook 'eshell-mode-hook 'set-buffer-utf8)

This does not work. I have also tried this with the modes utf-16 and mule-utf-8 with no luck.

Also, if I type

echo $LANG I get en_US.UTF-8. echo $LC_ALL also returns en_US.UTF-8.

EDIT 2:

I have now tried to set the encoding of eshell (in the hook above) to iso-8859-7 and iso-8859-1 with no luck.

5
  • These are most certainly not related to colors.
    – wasamasa
    Commented Nov 27, 2015 at 22:38
  • I have seen it uses some kind of utf symbols to show the branches and sub-dependencies. It may be the character selection jointly with the color. Is your terminal utf-8? Commented Nov 28, 2015 at 11:24
  • @DiegoSevilla This is EShell so im not actually sure.
    – Steve
    Commented Nov 28, 2015 at 17:00
  • @DiegoSevilla I have added the stuff specified here: masteringemacs.org/article/working-coding-systems-unicode-emacs and it has not fixed it.
    – Steve
    Commented Nov 28, 2015 at 17:29
  • This is not encoding-related either.
    – wasamasa
    Commented Dec 16, 2015 at 8:35

1 Answer 1

2

There's a huge amount of ANSI escape sequences. I've made a regex catching most you'll run into based on this answer and wrote some code to use it with eshell:

(defvar my-ansi-escape-re
  (rx (or ?\233 (and ?\e ?\[))
      (zero-or-more (char (?0 . ?\?)))
      (zero-or-more (char ?\s ?- ?\/))
      (char (?@ . ?~))))

(defun my-nuke-ansi-escapes (beg end)
  (save-excursion
    (goto-char beg)
    (while (re-search-forward my-ansi-escape-re end t)
      (replace-match ""))))

(defun my-eshell-nuke-ansi-escapes ()
  (my-nuke-ansi-escapes eshell-last-output-start eshell-last-output-end))

(add-hook 'eshell-output-filter-functions 'my-eshell-nuke-ansi-escapes t)
2
  • Interesting, thank you! I noticed you said it is not encoding related. Could you elaborate?
    – Steve
    Commented Dec 20, 2015 at 18:22
  • Given the lack of mojibake and the presence of sequences suspiciously looking like ANSI escapes, I am fairly sure this is not a problem to solve by changing the buffer encoding and investigated Emacs' ANSI escape support instead.
    – wasamasa
    Commented Dec 21, 2015 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.