emacs shell 命令输出不显示 ANSI 颜色,但显示代码

发布于 2024-11-03 13:43:47 字数 652 浏览 0 评论 0原文

当我做M-!在我的 emacs 21.4 中,ANSI 代码是字面意思。例如:ls --color

^[[0m^[[0m05420273.pdf^[[0m
^[[0m100829_Baño1.pdf^[[0m 

有没有办法让它具有颜色和UTF8?

同样的问题之前已经回答过< /a> 但结果并不完全令人满意(给出的解决方案是打开 shell 模式)。我知道如何在贝壳中添加颜色。我只想知道怎么才能和M有颜色! (shell 命令)或者如果根本不可能。

当您只想快速显示某些内容并且不想移动到此缓冲区并且希望它在没有 Cxk 的情况下自动消失时,shell 模式的干扰性太大。显然,在某些情况下,shell 缓冲区更方便,但由于另一个问题,我发现了如何将颜色添加到 shell 模式。

【注意】emacs使用中 builder6.centos.org 上的 2008 年 6 月 15 日的 GNU Emacs 21.4.1(x86_64-redhat-linux-gnu、X 工具包、Xaw3d 滚动条)

When I do M-! in my emacs 21.4 the ANSI codes gets literal. Eg: ls --color

^[[0m^[[0m05420273.pdf^[[0m
^[[0m100829_Baño1.pdf^[[0m 

Is there a way of having it with color and UTF8?

The same question has been answered in SO before but with not totally satisfactory results (the solution given was to open a shell-mode). I know how to have colors in a shell. I only want to know how I can have color with M! (shell-command) or if it is not possible at all.

A shell mode is too intrusive when you want only to show something quick and don't want to move to this buffer and you would like to have it disappear automatically without C-x-k. Obviously there are situations where a shell buffer is more convenient but thanks to the other question I found how to put color to the shell-mode.

[note] emacs in use
GNU Emacs 21.4.1 (x86_64-redhat-linux-gnu, X toolkit, Xaw3d scroll bars) of 2008-06-15 on builder6.centos.org

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽梦紫曦~ 2024-11-10 13:43:48

ansi-color.el 包含处理 ANSI 颜色代码的函数。不幸的是,并没有真正的好方法将其挂接到 shell-command 中。这是一个 hack,但它有效:

(require 'ansi-color)

(defadvice display-message-or-buffer (before ansi-color activate)
  "Process ANSI color codes in shell output."
  (let ((buf (ad-get-arg 0)))
    (and (bufferp buf)
         (string= (buffer-name buf) "*Shell Command Output*")
         (with-current-buffer buf
           (ansi-color-apply-on-region (point-min) (point-max))))))

ansi-color.el contains the functions to process ANSI color codes. Unfortunately, there's not really a good way to hook it into shell-command. This is something of a hack, but it works:

(require 'ansi-color)

(defadvice display-message-or-buffer (before ansi-color activate)
  "Process ANSI color codes in shell output."
  (let ((buf (ad-get-arg 0)))
    (and (bufferp buf)
         (string= (buffer-name buf) "*Shell Command Output*")
         (with-current-buffer buf
           (ansi-color-apply-on-region (point-min) (point-max))))))
只是我以为 2024-11-10 13:43:48

关于 UTF-8:

指定编码系统
转换非 ASCII 字符
shell命令输出,使用Cx RET c
在此命令之前。

非交互式调用者可以指定
结合编码系统
编码系统读取'和
写入编码系统。

这是来自 shell-command 的文档。

About UTF-8:

To specify a coding system for
converting non-ASCII characters in the
shell command output, use C-x RET c
before this command.

Noninteractive callers can specify
coding systems by binding
coding-system-for-read' and
coding-system-for-write'.

This is from the documentation of shell-command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文