如何在 (emacs) shell 命令的输出中添加颜色?
执行命令 shell-command 时,关联缓冲区中显示的输出不会着色。
当从 emacs 中调用测试框架(输出黄色/绿色/红色...)时,这尤其令人烦恼。
如何配置或扩展 emacs,以便让 shell 命令允许在 shell 中进行彩色输出并在表示该输出时保留颜色?
谢谢!
附:我在 UN*X 系统上使用 Bash shell。
When executing the command shell-command, the output shown in the associated buffer is not colorized.
This is particularly annoying when calling a testing framework (outputting yellow/green/red...) from within emacs.
How can I configure, or extend, emacs in order to have shell-command allowing colorized output in the shell and preserving the colors while representing that output?
Thanks!
ps. I'm using the Bash shell, on a UN*X system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以实现你自己的 shell-execute,比如
You can implement your own shell-execute, something like
这可能就是您想要的:
This is probably what you want :
这会添加一条建议,以便在 shell 命令完成后在迷你缓冲区上运行
ansi-color-apply-on-region
:它不依赖于 shell 模式或 comint。我将其与类似以下内容一起使用以获得良好的测试输出(带有成功文档测试计数的绿色笑脸。
This adds an advice to run
ansi-color-apply-on-region
on the minibuffer after shell-command finishes:It does not rely on shell-mode or comint. I accompany it with something like the following to get nice test output (a green smiley with the count of successful doctests.
此解决方案的灵感来自 @ArneBabenhauserheide,但使用
xterm-color
而不是ansi-color
。它还为*Shell Command Output*
缓冲区以及迷你缓冲区着色。This solution is inspired by @ArneBabenhauserheide's but uses
xterm-color
instead ofansi-color
. It also colorizes the*Shell Command Output*
buffer as well as the mini