emacs shell 命令输出不显示 ANSI 颜色,但显示代码 [英] emacs shell command output not showing ANSI colors but the code

查看:34
本文介绍了emacs shell 命令输出不显示 ANSI 颜色,但显示代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我做 M-!在我的 emacs 21.4 中,ANSI 代码是文字的.例如:ls --color

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 

有没有办法用颜色和 UTF8 来实现它?

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

同样的问题已经在SO之前但结果并不完全令人满意(给出的解决方案是打开shell模式).我知道如何在外壳中添加颜色.我只想知道怎么和M一起上色!(shell-command) 或者根本不可能.

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.

当您只想快速显示某些内容而不想移动到此缓冲区并且希望它在没有 C-x-k 的情况下自动消失时,shell 模式太具有侵入性.显然,在某些情况下,shell 缓冲区更方便,但多亏了另一个问题,我发现了如何为 shell 模式添加颜色.

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.

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

[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

推荐答案

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

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))))))

这篇关于emacs shell 命令输出不显示 ANSI 颜色,但显示代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆