为基于 B&W 终端的应用程序着色? [英] Colorize B&W terminal-based apps?

查看:36
本文介绍了为基于 B&W 终端的应用程序着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何软件可以为不支持颜色的基于终端的应用程序自动添加终端颜色?

Is there any software that will automagically add terminal colors to terminal-based apps that don't support colors?

它会如何运作?好吧,该软件至少可以尝试以与语法高亮器相同的方式来识别源代码(尽管大多数语法高亮器都会出现部分源代码树的问题),并且这种通用方法可以扩展到许多其他更人性化的数据形式;例如,日期、时间、金钱、电子邮件地址等很容易自动识别.

How would it work? Well, the software could at least try to identify source code in the same way that syntax highlighters do (albeit most syntax highlighters would have problems with parts of the source tree being off-screen), and this general method can be extended to lots of other more-human forms of data; for example, dates, times, money, email addrs, etc are easy to automatically identify.

推荐答案

问题分为两部分:

1) 一般如何添加颜色?这些通过ANSI颜色代码

1) How do I add colors in general? Those are signaled via ANSI Color Codes

例如:

$ echo -e "plain \033[0;36mcyan\033[0;0m"

您应该看到纯青色,带有青色"颜色.

You should see plain cyan, with "cyan" colored.

2) 如何为我的特定应用添加颜色?对于写入标准输出的标准命令行实用程序,您可以将其通过管道传输到插入颜色代码的脚本:

2) How do I add colors to my specific app? For a standard command-line utility that writes to standard output, you can pipe it to a script that inserts the color codes:

$ echo "plain cyan" | sed 's/cyan/\\033[0;36mcyan\\033[0;0m/'
plain \033[0;36mcyan\033[0;0m
$ echo "plain cyan" | sed 's/cyan/\\\\033[0;36mcyan\\\\033[0;0m/' | while read x; do echo -e "$x"; done
plain cyan

这篇关于为基于 B&W 终端的应用程序着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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