彩色化文本/背景下,如何让pretty打印便携?此外,通过Aesthir书面彩色功能的大名单,享受? [英] Colorize text/background, how to make pretty-print portable? Also, large list of Color Functions written by Aesthir, enjoy?

查看:234
本文介绍了彩色化文本/背景下,如何让pretty打印便携?此外,通过Aesthir书面彩色功能的大名单,享受?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这不是一个具体的问题,我有一个....但首先,我想与大家分享 [Aesthir的色彩功能™] .. - 这不是真正的商标; ^) - 所有的用shell codeRS谁在那里想的东西看起来有点更好。我(70 +现)虔诚地将这些在所有我的剧本,只是为了好玩,轻松地单独的数据,并组织好。

下面是我经常使用的颜色功能...年前写他们已经变得如此使用他们,他们是我的脚本的常规部分。他们充当的printf 的替代品,因此而不是无聊的老 printf的你好\\ N,绿色你好根本 Tgreen你好\\ N只要坚持这个code座到您的.bashrc文件,开始一个新的会话,你定!地狱沾些成易彩提示您的PSN的变量。举例来说,这里是我的选择提示:出口PS3 =$(Tmagenta〔选择〕'),我的须藤提示:出口SUDO_PROMPT =$(Tgreen〔〕的密码')。这些是我经常使用的:


  ## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ [Aesthir的颜色功能] ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
    正常(){printf的'\\ E [M'$ *; }; Tblack(){printf的'\\ E [0;30米'$ *'\\ E [M'; }
    TNormal(){printf的'\\ E [M'$ *; }; TRED(){printf的'\\ E [0;31米'$ *'\\ E [M'; }
    粗体(){printf的'\\ E [1分'$ *'\\ E [M'; }; Tgreen(){printf的'\\ E [0;32米'$ *'\\ E [M'; }
    TBold(){printf的'\\ E [1分'$ *'\\ E [M'; }; Tbrown(){printf的'\\ E [0;33米'$ *'\\ E [M'; }
    下划线(){printf的'\\ E [4米'$ *'\\ E [M'; }; Tyellow(){printf的'\\ E [0;33米'$ *'\\ E [M'; }
    TUnderline(){printf的'\\ E [4米'$ *'\\ E [M'; }; Tblue(){printf的'\\ E [0;34米'$ *'\\ E [M'; }
    闪光灯(){printf的'\\ E [5分'$ *'\\ E [M'; }; Tmagenta(){printf的'\\ E [0;35米'$ *'\\ E [M'; }
    TFLASH(){printf的'\\ E [5分'$ *'\\ E [M'; }; Tpurple(){printf的'\\ E [0;35米'$ *'\\ E [M'; }
    反转(){printf的'\\ E [7米'$ *'\\ E [M'; }; Taqua(){printf的'\\ E [0;36米'$ *'\\ E [M'; }
    TInvert(){printf的'\\ E [7米'$ *'\\ E [M'; }; Tcyan(){printf的'\\ E [0;36米'$ *'\\ E [M'; }
    隐形(){printf的'\\ E [8米'$ *'\\ E [M'; }; Tgrey(){printf的'\\ E [0;37米'$ *'\\ E [M'; }
    TInvisible(){printf的'\\ E [8米'$ *'\\ E [M'; }; Twhite(){printf的'\\ E [0;37米'$ *'\\ E [M'; }
##∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞大胆的色彩文字∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞##∞∞∞∞∞∞∞∞∞∞∞∞带下划线的颜色文本∞∞∞∞∞∞∞∞∞∞∞∞∞##
    TblackB(){printf的'\\ E [1;30米'$ *'\\ E [M'; }; TblackU(){printf的'\\ E [4;30米'$ *'\\ E [M'; }
    TgreyB(){printf的'\\ E [1;30米'$ *'\\ E [M'; }; TredU(){printf的'\\ E [4;31米'$ *'\\ E [M'; }
    TredB(){printf的'\\ E [1;31米'$ *'\\ E [M'; }; TgreenU(){printf的'\\ E [4;32米'$ *'\\ E [M'; }
    TgreenB(){printf的'\\ E [1;32米'$ *'\\ E [M'; }; TbrownU(){printf的'\\ E [4;33米'$ *'\\ E [M'; }
    TbrownB(){printf的'\\ E [1;33米'$ *'\\ E [M'; }; TyellowU(){printf的'\\ E [4;33米'$ *'\\ E [M'; }
    TyellowB(){printf的'\\ E [1;33米'$ *'\\ E [M'; }; TblueU(){printf的'\\ E [4;34米'$ *'\\ E [M'; }
    TblueB(){printf的'\\ E [1;34米'$ *'\\ E [M'; }; TmagentaU(){printf的'\\ E [4;35米'$ *'\\ E [M'; }
    TmagentaB(){printf的'\\ E [1;35米'$ *'\\ E [M'; }; TpurpleU(){printf的'\\ E [4;35米'$ *'\\ E [M'; }
    TpurpleB(){printf的'\\ E [1;35米'$ *'\\ E [M'; }; TaquaU(){printf的'\\ E [4;36米'$ *'\\ E [M'; }
    TaquaB(){printf的'\\ E [1;36米'$ *'\\ E [M'; }; TcyanU(){printf的'\\ E [4;36米'$ *'\\ E [M'; }
    TcyanB(){printf的'\\ E [1;36米'$ *'\\ E [M'; }; TgreyU(){printf的'\\ E [4;37米'$ *'\\ E [M'; }
    TwhiteB(){printf的'\\ E [1;37米'$ *'\\ E [M'; }; TwhiteU(){printf的'\\ E [4;37米'$ *'\\ E [M'; }
##∞∞∞∞∞∞∞∞∞∞∞∞∞闪烁颜色文本∞∞∞∞∞∞∞∞∞∞∞∞∞∞##∞∞∞∞∞∞∞∞∞∞∞∞∞倒颜色文本∞∞∞∞∞∞∞∞∞∞∞∞∞∞##
    TblackF(){printf的'\\ E [5;30米'$ *'\\ E [M'; }; TblackI(){printf的'\\ E [7;40米'$ *'\\ E [M'; }
    TredF(){printf的'\\ E [5;31米'$ *'\\ E [M'; };选择特迪(){printf的'\\ E [7;41米'$ *'\\ E [M'; }
    TgreenF(){printf的'\\ E [5;32米'$ *'\\ E [M'; }; TgreenI(){printf的'\\ E [7;42米'$ *'\\ E [M'; }
    TbrownF(){printf的'\\ E [5;33米'$ *'\\ E [M'; }; TbrownI(){printf的'\\ E [7;43米'$ *'\\ E [M'; }
    TyellowF(){printf的'\\ E [5;33米'$ *'\\ E [M'; }; TyellowI(){printf的'\\ E [7;43米'$ *'\\ E [M'; }
    TblueF(){printf的'\\ E [5;34米'$ *'\\ E [M'; }; TblueI(){printf的'\\ E [7;44米'$ *'\\ E [M'; }
    TmagentaF(){printf的'\\ E [5;35米'$ *'\\ E [M'; }; TmagentaI(){printf的'\\ E [7;45米'$ *'\\ E [M'; }
    TpurpleF(){printf的'\\ E [5;35米'$ *'\\ E [M'; }; TpurpleI(){printf的'\\ E [7;45米'$ *'\\ E [M'; }
    TaquaF(){printf的'\\ E [5;36米'$ *'\\ E [M'; }; TaquaI(){printf的'\\ E [7;46米'$ *'\\ E [M'; }
    TcyanF(){printf的'\\ E [5;36米'$ *'\\ E [M'; }; TcyanI(){printf的'\\ E [7;46米'$ *'\\ E [M'; }
    TgreyF(){printf的'\\ E [5;37米'$ *'\\ E [M'; }; TgreyI(){printf的'\\ E [7;47米'$ *'\\ E [M'; }
    TwhiteF(){printf的'\\ E [5;37米'$ *'\\ E [M'; }; TwhiteI(){printf的'\\ E [7;47米'$ *'\\ E [M'; }
##∞∞∞∞∞∞∞∞∞∞∞∞∞隐形颜色文本∞∞∞∞∞∞∞∞∞∞∞∞∞##∞∞∞∞∞∞∞∞的颜色背景纯文本∞∞∞∞ ∞∞∞∞##
    TblackV(){printf的'\\ E [8;30米'$ *'\\ E [M'; }; Bblack(){printf的'\\ E [M'$ *'\\ E [M'; }
    TredV(){printf的'\\ E [8;31米'$ *'\\ E [M'; };良种(){printf的'\\ E [0;41米'$ *'\\ E [M'; }
    TgreenV(){printf的'\\ E [8;32米'$ *'\\ E [M'; }; Bgreen(){printf的'\\ E [0;42米'$ *'\\ E [M'; }
    TbrownV(){printf的'\\ E [8;33米'$ *'\\ E [M'; }; Bbrown(){printf的'\\ E [0;43米'$ *'\\ E [M'; }
    TyellowV(){printf的'\\ E [8;33米'$ *'\\ E [M'; }; Byellow(){printf的'\\ E [0;43米'$ *'\\ E [M'; }
    TblueV(){printf的'\\ E [8;34米'$ *'\\ E [M'; }; Bblue(){printf的'\\ E [0;44米'$ *'\\ E [M'; }
    TmagentaV(){printf的'\\ E [8;35米'$ *'\\ E [M'; }; Bmagenta(){printf的'\\ E [0;45米'$ *'\\ E [M'; }
    TpurpleV(){printf的'\\ E [8;35米'$ *'\\ E [M'; }; Bpurple(){printf的'\\ E [0;45米'$ *'\\ E [M'; }
    TaquaV(){printf的'\\ E [8;36米'$ *'\\ E [M'; }; Baqua(){printf的'\\ E [0;46米'$ *'\\ E [M'; }
    TcyanV(){printf的'\\ E [8;36米'$ *'\\ E [M'; }; Bcyan(){printf的'\\ E [0;46米'$ *'\\ E [M'; }
    TgreyV(){printf的'\\ E [8;37米'$ *'\\ E [M'; }; Bgrey(){printf的'\\ E [0;47米'$ *'\\ E [M'; }
    TwhiteV(){printf的'\\ E [8;37米'$ *'\\ E [M'; }; Bwhite(){printf的'\\ E [0;47米'$ *'\\ E [M'; }
##∞∞∞∞∞∞∞∞∞的颜色背景粗体文字∞∞∞∞∞∞∞∞##∞∞∞∞∞∞的颜色背景∞∞∞∞∞下划线文字##
    BblackB(){printf的'\\ E [1;40米'$ *'\\ E [M'; }; BblackU(){printf的'\\ E [4;40米'$ *'\\ E [M'; }
    BredB(){printf的'\\ E [1;41米'$ *'\\ E [M'; }; BredU(){printf的'\\ E [4;41米'$ *'\\ E [M'; }
    BgreenB(){printf的'\\ E [1;42米'$ *'\\ E [M'; }; BgreenU(){printf的'\\ E [4;42米'$ *'\\ E [M'; }
    BbrownB(){printf的'\\ E [1;43米'$ *'\\ E [M'; }; BbrownU(){printf的'\\ E [4;43米'$ *'\\ E [M'; }
    ByellowB(){printf的'\\ E [1;43米'$ *'\\ E [M'; }; ByellowU(){printf的'\\ E [4;43米'$ *'\\ E [M'; }
    BblueB(){printf的'\\ E [1;44米'$ *'\\ E [M'; }; BblueU(){printf的'\\ E [4;44米'$ *'\\ E [M'; }
    BmagentaB(){printf的'\\ E [1;45米'$ *'\\ E [M'; }; BmagentaU(){printf的'\\ E [4;45米'$ *'\\ E [M'; }
    BpurpleB(){printf的'\\ E [1;45米'$ *'\\ E [M'; }; BpurpleU(){printf的'\\ E [4;45米'$ *'\\ E [M'; }
    BaquaB(){printf的'\\ E [1;46米'$ *'\\ E [M'; }; BaquaU(){printf的'\\ E [4;46米'$ *'\\ E [M'; }
    BcyanB(){printf的'\\ E [1;46米'$ *'\\ E [M'; }; BcyanU(){printf的'\\ E [4;46米'$ *'\\ E [M'; }
    BgreyB(){printf的'\\ E [1;47米'$ *'\\ E [M'; }; BgreyU(){printf的'\\ E [4;47米'$ *'\\ E [M'; }
    BwhiteB(){printf的'\\ E [1;47米'$ *'\\ E [M'; }; BwhiteU(){printf的'\\ E [4;47米'$ *'\\ E [M'; }
##∞∞∞∞∞∞∞的颜色背景∞∞∞∞∞∞##的颜色背景∞∞∞∞∞∞∞反转文本∞∞∞∞∞∞闪烁的文本##
    BblackF(){printf的'\\ E [5;40米'$ *'\\ E [M'; }; BblackI(){printf的'\\ E [7;30米'$ *'\\ E [M'; }
    BredF(){printf的'\\ E [5;41米'$ *'\\ E [M'; }; BredI(){printf的'\\ E [7;31米'$ *'\\ E [M'; }
    BgreenF(){printf的'\\ E [5;42米'$ *'\\ E [M'; }; BgreenI(){printf的'\\ E [7;32米'$ *'\\ E [M'; }
    BbrownF(){printf的'\\ E [5;43米'$ *'\\ E [M'; }; BbrownI(){printf的'\\ E [7;33米'$ *'\\ E [M'; }
    ByellowF(){printf的'\\ E [5;43米'$ *'\\ E [M'; }; ByellowI(){printf的'\\ E [7;33米'$ *'\\ E [M'; }
    BblueF(){printf的'\\ E [5;44米'$ *'\\ E [M'; }; BblueI(){printf的'\\ E [7;34米'$ *'\\ E [M'; }
    BmagentaF(){printf的'\\ E [5;45米'$ *'\\ E [M'; }; BmagentaI(){printf的'\\ E [7;35米'$ *'\\ E [M'; }
    BpurpleF(){printf的'\\ E [5;45米'$ *'\\ E [M'; }; BpurpleI(){printf的'\\ E [7;35米'$ *'\\ E [M'; }
    BaquaF(){printf的'\\ E [5;46米'$ *'\\ E [M'; }; BaquaI(){printf的'\\ E [7;36米'$ *'\\ E [M'; }
    BcyanF(){printf的'\\ E [5;46米'$ *'\\ E [M'; }; BcyanI(){printf的'\\ E [7;36米'$ *'\\ E [M'; }
    BgreyF(){printf的'\\ E [5;47米'$ *'\\ E [M'; }; BgreyI(){printf的'\\ E [7;37米'$ *'\\ E [M'; }
    BwhiteF(){printf的'\\ E [5;47米'$ *'\\ E [M'; }; BwhiteI(){printf的'\\ E [7;37米'$ *'\\ E [M'; }
##∞∞∞∞∞∞的颜色背景隐形文字∞∞∞∞∞∞##∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞颜色code注∞∞∞∞∞∞∞∞ ∞∞∞∞∞∞∞##
    BblackV(){printf的'\\ E [8;40米'$ *'\\ E [M'; } ##除非我错过了什么或做了一个错误,我##
    BredV(){printf的'\\ E [8;41米'$ *'\\ E [M'; } ##计算总7681不同的颜色codeS中,##
    BgreenV(){printf的'\\ E [8;42米'$ *'\\ E [M'; } ##无论哪一种都不重复的结果。 ##
    BbrownV(){printf的'\\ E [8;43米'$ *'\\ E [M'; } ##这将是罚款了。 ##
    ByellowV(){printf的'\\ E [8;43米'$ *'\\ E [M'; }
    BblueV(){printf的'\\ E [8;44米'$ *'\\ E [M'; }
    BmagentaV(){printf的'\\ E [8;45米'$ *'\\ E [M'; }
    BpurpleV(){printf的'\\ E [8;45米'$ *'\\ E [M'; }
    BaquaV(){printf的'\\ E [8;46米'$ *'\\ E [M'; }
    BcyanV(){printf的'\\ E [8;46米'$ *'\\ E [M'; }
    BgreyV(){printf的'\\ E [8;47米'$ *'\\ E [M'; }
    BwhiteV(){printf的'\\ E [8;47米'$ *'\\ E [M'; }
## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##

要记住的唯一的事情就是想要一个百分号或 \\ 反斜线时,你需要他们里面翻倍:

这样的:的printf$(Tblue%%小号\\\\ N)'喜'

但不适用于 Tblue%S \\ N'喜'

的printf$(Tblue%S'喜')\\ n

由于这些用printf,你可以做的东西,如:

  printf的喜$(TRED有)手册$(BaquaI%C'!')$(粗体这\\\\ t是%% s')的%S \\ n $(BgreenB'超级')$(Bblue兆七彩)

或回声:

 回声你好$(TRED有)手册$(BaquaI%C'!')$(粗体这\\\\,t是%s的$(BblackB超'))$(Bblue兆七彩)

一个更有用的例子:

 的printf\\ t%的音量\\%s \\的未连接。\\ n$(TwhiteB [)$(TredB错误)$(TwhiteB \\] :) $(Tbrown $卷)

或与其他命令:

 评估回声这是OSX'| sed的的:OSX:$(反转[)$(TaquaF OSX)$(反转):'

或以更高一点的东西斯旺克:

 找到。 -exec统计-f姓名:$(Tbrown %% N)%T%T $(Tpurple - >中)%tPermissions:$(Tgreen %% SP){} \\;

这是倾倒的任何让你在扫描什么伸出像一个突兀...(在这种情况下,跳动的红色)控制命令

 评估的ps aux | sed中的|庆典| $(BredF'庆典')| G'

使用你的想象力!欢迎大家使用这些...

可能有人会说,有什么用看不见的文字?

         - 不多,真的......但它的存在。我用了几次,但只能排队文本时,绘图和UNI code等字母



现在对于我的问题...


       1)元问题:如果有人在那里感觉就像打字什么,我已经开始了一个延续,可以请你使用上面的格式?或至少​​相似的格式?一些实例是:

  TgreenBU ##粗体,下划线的绿色文本##
TcyanBUFBblackI ##粗体青色/ AQUA文字的下划线和一个倒黑色背景上闪烁##

等等...弥补自己的名字,这样有可能都以最小的,目前还不清楚参数名的排列。这些都是例子,但我没有看过,看这些名称与他人发生冲突...
如果有人在那里喜欢这些功能,经常使用它们,有一段时间,woud想给后面的东西,可这个神话的人,请发表他们对我在这个问题上作为回复,或通过电子邮件发送给我的 [mdouglas34@hotmail.com] 1 。我懒得打字了所有的可能性(我很快在他们的7000计算,但有可能是很多很多,如果我错过了什么)。

       2)的主要问题:由于我使用这些 颜色功能 所有的时间......在每一个剧本,我需要知道一些关于其他用户的终端:

           有没有什么办法来确定终端(不看它直接明显)的背景颜色

           可以与任何其他信息收集?就像如果终端设置为处理的颜色?也许他们的LSCOLORS或东西在他们的终端能力/设置给予提示?我猜 $ TERM 如果设置为 xterm的色,这是一个大破绽的颜色是可能的...但什么是其他终端的能力?可的rxvt 产生同样的颜色吗? 的xterm-256color 如何涉及到这个?可以更多的颜色被比标准8中使用? 8大胆?

          基本上,我想写code,它吐出彩色输出,非常适合运行的任何终端在任何系统上,具有任何设置。 有没有办法得到这个信息,或者这只是一个白日梦?

          最后... 什么字体?做终端使用比例/等宽字体?有没有什么办法来确定用户是否有,比方说,UNI code支持?这将是很好konw如果某些pretty又看中的字符不会显示性能,因为它们可能被交换与丑陋,更简单的字符。

所以基本上,我正在寻找多种方法来扫描非本地用户的设置,环境,使pretty打印code会被其他地方移植。
是否有创作的用于此目的,在那里,我不知道?软件

对不起,所有的问题......有些precise,其他人有点模糊......我希望会有很多答案对我来说汇集在一起​​。移植pretty打印在Unix世界的一个重大挑战......我希望做一个凹痕在这艘战舰的问题。

在平均时间是,随时都用我的颜色功能您认为合适的!

享受!

- Aesthir


解决方案

大家好......我再回答我的问题,企图将其撞为主动......如果这是可能的吗?

我要指出的是,我花了不少的的时间研究,打字,并问一个问题,理应达到数以百万计的过程中等待。下面是我所做的:


  • 研究之:尝试长发布前谷歌式的回答我的问题,并没有发现任何

  • 搜索网站:不想说已经问,所以我搜索了每一个措辞/标记可能性我能想到的....和ASKA aquestion也很喜欢上面的没有

  • 发布pretty印刷:长岗所以花费的时间标记(粗体/斜体/较大的文本)及组织(相关块相应间隔/中心等)为清晰,易读的职位。读者pssed想念我的问题很难$ P $,它们分别位于:

               【现在我的问题...

          2)主要问题:】 &# x2003; 根据水平线在我的岗位部分

  • 集思广益:想出来的所有的角度和可能的子问题,这可能会出现

  • 还给:我甚至给社会;一些code我用如此频繁我想其他人可能想尝试一下。

  • 新增例子:竟然去创造,测试,并键入了一堆例子搞清楚如何使用我的色彩功能,以帮助

  • 等了:最后,我等3¹/₂个月的答案...任何回答...什么都没有呢。   8 ^(



我想我把至少在一些力气发布了几个问题,也许有人能可怜可怜我,把几分钟到发布的答复。

什么我正在寻找(从多到少):


  1. 一个答案,一个或多个我的问题... 耶!我一直想现在探测长时间终端的能力。除了终端的在原来的职位要求的功能,这里有2个结果

    • 当彩色功能输出到文件中,每一个逃生code是present ... 如何知道自己是否 SDOUT 变重定向到一个文件没有办法拦截和sed输出 - ?也许中断调用 -

    • 我的脚本大量的含有高价值的统一code和他们得到转换为gargabe(一个人),还有一些〜/ .inputrc文件选项set.Which选项​​(S)是谁的?如果我知道,我可以测试绑定-v的结果| SED


  2. 的响应或含有大约相同的方式更雷色彩功能的电子邮件( mdouglas34@hotmail.com )是。不能与上述功能的属性文本的例子:

    • 大胆的的下划线的文本

      • (任意2非彩色特性,或更多个)


    • 在红色背景大胆的黄色文字

      • (在differrent彩色背景的彩色文本)


    • 大胆,红色,闪烁黑色背景上的文字

      • (基本上是前两个例子加盟)



  3. 部分的的问题进行了研究的泵UPS ... ...笑总是好的有

  4. 并沿着这些线路,一些信誉*的+ 1的* S

  5. 说的问的事情之一以上的回复是不可能的

    • 如果不是,为什么?什么是$ P $从知道有关它的运行在终端?
    • 有点pventing我

  6. 什么反应......有这些麻烦。没有一个在3个月以上。

  7. 评论亦欢迎。只拿到2。顺便说一句,THX Triplee &安培; shellter

    THX一切!

               - Aesthir


Although this isn't a specific question, I do have one.... but first, I'd like to share [ Aesthir's Color Functions™ ]... —— it's not really trademarked ;^) —— with all the shell-coders out there who would like things to look a bit nicer. I use these religiously throughout all my scripts (70+ now), just for fun, to easily separate data and to organize better.

Below are the color functions that I use regularly... wrote them years ago and have gotten so used to them that they're a regular part of my scripting. They function as printf substitutes, so rather than boring old printf "Hello\n", a green hello simply Tgreen "Hello\n" Just stick this code block into your .bashrc file, start a new session, and you're set! Hell stick some into your PSn variables for easy color prompts. For instance, here is my select prompt: export PS3="$(Tmagenta '  〔Select〕 ')", and my sudo prompt: export SUDO_PROMPT="    $(Tgreen '〔Password〕') ". These are the ones I use:


## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ [ Aesthir's Color Functions ] ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
    Normal () { printf '\e[m'"$*"; }                  ; Tblack () { printf '\e[0;30m'"$*"'\e[m'; }
    TNormal () { printf '\e[m'"$*"; }                 ; Tred () { printf '\e[0;31m'"$*"'\e[m'; }
    Bold () { printf '\e[1m'"$*"'\e[m'; }             ; Tgreen () { printf '\e[0;32m'"$*"'\e[m'; }
    TBold () { printf '\e[1m'"$*"'\e[m'; }            ; Tbrown () { printf '\e[0;33m'"$*"'\e[m'; }
    Underline () { printf '\e[4m'"$*"'\e[m'; }        ; Tyellow () { printf '\e[0;33m'"$*"'\e[m'; }
    TUnderline () { printf '\e[4m'"$*"'\e[m'; }       ; Tblue () { printf '\e[0;34m'"$*"'\e[m'; }
    Flash () { printf '\e[5m'"$*"'\e[m'; }            ; Tmagenta () { printf '\e[0;35m'"$*"'\e[m'; }
    TFlash () { printf '\e[5m'"$*"'\e[m'; }           ; Tpurple () { printf '\e[0;35m'"$*"'\e[m'; }
    Invert () { printf '\e[7m'"$*"'\e[m'; }           ; Taqua () { printf '\e[0;36m'"$*"'\e[m'; }
    TInvert () { printf '\e[7m'"$*"'\e[m'; }          ; Tcyan () { printf '\e[0;36m'"$*"'\e[m'; }
    Invisible () { printf '\e[8m'"$*"'\e[m'; }        ; Tgrey () { printf '\e[0;37m'"$*"'\e[m'; }
    TInvisible () { printf '\e[8m'"$*"'\e[m'; }       ; Twhite () { printf '\e[0;37m'"$*"'\e[m'; }
## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Bold Color Text ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ## ∞∞∞∞∞∞∞∞∞∞∞∞ Underlined Color Text ∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
    TblackB () { printf '\e[1;30m'"$*"'\e[m'; }       ; TblackU () { printf '\e[4;30m'"$*"'\e[m'; }
    TgreyB () { printf '\e[1;30m'"$*"'\e[m'; }        ; TredU () { printf '\e[4;31m'"$*"'\e[m'; }
    TredB () { printf '\e[1;31m'"$*"'\e[m'; }         ; TgreenU () { printf '\e[4;32m'"$*"'\e[m'; }
    TgreenB () { printf '\e[1;32m'"$*"'\e[m'; }       ; TbrownU () { printf '\e[4;33m'"$*"'\e[m'; }
    TbrownB () { printf '\e[1;33m'"$*"'\e[m'; }       ; TyellowU () { printf '\e[4;33m'"$*"'\e[m'; }
    TyellowB () { printf '\e[1;33m'"$*"'\e[m'; }      ; TblueU () { printf '\e[4;34m'"$*"'\e[m'; }
    TblueB () { printf '\e[1;34m'"$*"'\e[m'; }        ; TmagentaU () { printf '\e[4;35m'"$*"'\e[m'; }
    TmagentaB () { printf '\e[1;35m'"$*"'\e[m'; }     ; TpurpleU () { printf '\e[4;35m'"$*"'\e[m'; }
    TpurpleB () { printf '\e[1;35m'"$*"'\e[m'; }      ; TaquaU () { printf '\e[4;36m'"$*"'\e[m'; }
    TaquaB () { printf '\e[1;36m'"$*"'\e[m'; }        ; TcyanU () { printf '\e[4;36m'"$*"'\e[m'; }
    TcyanB () { printf '\e[1;36m'"$*"'\e[m'; }        ; TgreyU () { printf '\e[4;37m'"$*"'\e[m'; }
    TwhiteB () { printf '\e[1;37m'"$*"'\e[m'; }       ; TwhiteU () { printf '\e[4;37m'"$*"'\e[m'; }
## ∞∞∞∞∞∞∞∞∞∞∞∞∞ Flashing Color Text ∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ## ∞∞∞∞∞∞∞∞∞∞∞∞∞ Inverted Color Text ∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
    TblackF () { printf '\e[5;30m'"$*"'\e[m'; }       ; TblackI () { printf '\e[7;40m'"$*"'\e[m'; }
    TredF () { printf '\e[5;31m'"$*"'\e[m'; }         ; TredI () { printf '\e[7;41m'"$*"'\e[m'; }
    TgreenF () { printf '\e[5;32m'"$*"'\e[m'; }       ; TgreenI () { printf '\e[7;42m'"$*"'\e[m'; }
    TbrownF () { printf '\e[5;33m'"$*"'\e[m'; }       ; TbrownI () { printf '\e[7;43m'"$*"'\e[m'; }
    TyellowF () { printf '\e[5;33m'"$*"'\e[m'; }      ; TyellowI () { printf '\e[7;43m'"$*"'\e[m'; }
    TblueF () { printf '\e[5;34m'"$*"'\e[m'; }        ; TblueI () { printf '\e[7;44m'"$*"'\e[m'; }
    TmagentaF () { printf '\e[5;35m'"$*"'\e[m'; }     ; TmagentaI () { printf '\e[7;45m'"$*"'\e[m'; }
    TpurpleF () { printf '\e[5;35m'"$*"'\e[m'; }      ; TpurpleI () { printf '\e[7;45m'"$*"'\e[m'; }
    TaquaF () { printf '\e[5;36m'"$*"'\e[m'; }        ; TaquaI () { printf '\e[7;46m'"$*"'\e[m'; }
    TcyanF () { printf '\e[5;36m'"$*"'\e[m'; }        ; TcyanI () { printf '\e[7;46m'"$*"'\e[m'; }
    TgreyF () { printf '\e[5;37m'"$*"'\e[m'; }        ; TgreyI () { printf '\e[7;47m'"$*"'\e[m'; }
    TwhiteF () { printf '\e[5;37m'"$*"'\e[m'; }       ; TwhiteI () { printf '\e[7;47m'"$*"'\e[m'; }
## ∞∞∞∞∞∞∞∞∞∞∞∞∞ Invisible Color Text ∞∞∞∞∞∞∞∞∞∞∞∞∞ ## ∞∞∞∞∞∞∞∞ Plain Text on Color Background ∞∞∞∞∞∞∞∞ ##
    TblackV () { printf '\e[8;30m'"$*"'\e[m'; }       ; Bblack () { printf '\e[m'"$*"'\e[m'; }
    TredV () { printf '\e[8;31m'"$*"'\e[m'; }         ; Bred () { printf '\e[0;41m'"$*"'\e[m'; }
    TgreenV () { printf '\e[8;32m'"$*"'\e[m'; }       ; Bgreen () { printf '\e[0;42m'"$*"'\e[m'; }
    TbrownV () { printf '\e[8;33m'"$*"'\e[m'; }       ; Bbrown () { printf '\e[0;43m'"$*"'\e[m'; }
    TyellowV () { printf '\e[8;33m'"$*"'\e[m'; }      ; Byellow () { printf '\e[0;43m'"$*"'\e[m'; }
    TblueV () { printf '\e[8;34m'"$*"'\e[m'; }        ; Bblue () { printf '\e[0;44m'"$*"'\e[m'; }
    TmagentaV () { printf '\e[8;35m'"$*"'\e[m'; }     ; Bmagenta () { printf '\e[0;45m'"$*"'\e[m'; }
    TpurpleV () { printf '\e[8;35m'"$*"'\e[m'; }      ; Bpurple () { printf '\e[0;45m'"$*"'\e[m'; }
    TaquaV () { printf '\e[8;36m'"$*"'\e[m'; }        ; Baqua () { printf '\e[0;46m'"$*"'\e[m'; }
    TcyanV () { printf '\e[8;36m'"$*"'\e[m'; }        ; Bcyan () { printf '\e[0;46m'"$*"'\e[m'; }
    TgreyV () { printf '\e[8;37m'"$*"'\e[m'; }        ; Bgrey () { printf '\e[0;47m'"$*"'\e[m'; }
    TwhiteV () { printf '\e[8;37m'"$*"'\e[m'; }       ; Bwhite () { printf '\e[0;47m'"$*"'\e[m'; }
## ∞∞∞∞∞∞∞∞∞ Bold Text on Color Background ∞∞∞∞∞∞∞∞ ## ∞∞∞∞∞∞ Underlined Text on Color Background ∞∞∞∞∞ ##
    BblackB () { printf '\e[1;40m'"$*"'\e[m'; }       ; BblackU () { printf '\e[4;40m'"$*"'\e[m'; }
    BredB () { printf '\e[1;41m'"$*"'\e[m'; }         ; BredU () { printf '\e[4;41m'"$*"'\e[m'; }
    BgreenB () { printf '\e[1;42m'"$*"'\e[m'; }       ; BgreenU () { printf '\e[4;42m'"$*"'\e[m'; }
    BbrownB () { printf '\e[1;43m'"$*"'\e[m'; }       ; BbrownU () { printf '\e[4;43m'"$*"'\e[m'; }
    ByellowB () { printf '\e[1;43m'"$*"'\e[m'; }      ; ByellowU () { printf '\e[4;43m'"$*"'\e[m'; }
    BblueB () { printf '\e[1;44m'"$*"'\e[m'; }        ; BblueU () { printf '\e[4;44m'"$*"'\e[m'; }
    BmagentaB () { printf '\e[1;45m'"$*"'\e[m'; }     ; BmagentaU () { printf '\e[4;45m'"$*"'\e[m'; }
    BpurpleB () { printf '\e[1;45m'"$*"'\e[m'; }      ; BpurpleU () { printf '\e[4;45m'"$*"'\e[m'; }
    BaquaB () { printf '\e[1;46m'"$*"'\e[m'; }        ; BaquaU () { printf '\e[4;46m'"$*"'\e[m'; }
    BcyanB () { printf '\e[1;46m'"$*"'\e[m'; }        ; BcyanU () { printf '\e[4;46m'"$*"'\e[m'; }
    BgreyB () { printf '\e[1;47m'"$*"'\e[m'; }        ; BgreyU () { printf '\e[4;47m'"$*"'\e[m'; }
    BwhiteB () { printf '\e[1;47m'"$*"'\e[m'; }       ; BwhiteU () { printf '\e[4;47m'"$*"'\e[m'; }
## ∞∞∞∞∞∞∞ Flashing Text on Color Background ∞∞∞∞∞∞ ## ∞∞∞∞∞∞∞ Inverted Text on Color Background ∞∞∞∞∞∞ ##
    BblackF () { printf '\e[5;40m'"$*"'\e[m'; }       ; BblackI () { printf '\e[7;30m'"$*"'\e[m'; }
    BredF () { printf '\e[5;41m'"$*"'\e[m'; }         ; BredI () { printf '\e[7;31m'"$*"'\e[m'; }
    BgreenF () { printf '\e[5;42m'"$*"'\e[m'; }       ; BgreenI () { printf '\e[7;32m'"$*"'\e[m'; }
    BbrownF () { printf '\e[5;43m'"$*"'\e[m'; }       ; BbrownI () { printf '\e[7;33m'"$*"'\e[m'; }
    ByellowF () { printf '\e[5;43m'"$*"'\e[m'; }      ; ByellowI () { printf '\e[7;33m'"$*"'\e[m'; }
    BblueF () { printf '\e[5;44m'"$*"'\e[m'; }        ; BblueI () { printf '\e[7;34m'"$*"'\e[m'; }
    BmagentaF () { printf '\e[5;45m'"$*"'\e[m'; }     ; BmagentaI () { printf '\e[7;35m'"$*"'\e[m'; }
    BpurpleF () { printf '\e[5;45m'"$*"'\e[m'; }      ; BpurpleI () { printf '\e[7;35m'"$*"'\e[m'; }
    BaquaF () { printf '\e[5;46m'"$*"'\e[m'; }        ; BaquaI () { printf '\e[7;36m'"$*"'\e[m'; }
    BcyanF () { printf '\e[5;46m'"$*"'\e[m'; }        ; BcyanI () { printf '\e[7;36m'"$*"'\e[m'; }
    BgreyF () { printf '\e[5;47m'"$*"'\e[m'; }        ; BgreyI () { printf '\e[7;37m'"$*"'\e[m'; }
    BwhiteF () { printf '\e[5;47m'"$*"'\e[m'; }       ; BwhiteI () { printf '\e[7;37m'"$*"'\e[m'; }
## ∞∞∞∞∞∞ Invisible Text on Color Background ∞∞∞∞∞∞ ## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Color Code Notes ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##
    BblackV () { printf '\e[8;40m'"$*"'\e[m'; }     ## Unless I missed something or made a mistake, I   ##
    BredV () { printf '\e[8;41m'"$*"'\e[m'; }       ## calculate a total of 7681 different color codes, ##
    BgreenV () { printf '\e[8;42m'"$*"'\e[m'; }     ## none of which produce a duplicate result.        ##
    BbrownV () { printf '\e[8;43m'"$*"'\e[m'; }     ##                      These will be fine for now. ##
    ByellowV () { printf '\e[8;43m'"$*"'\e[m'; }
    BblueV () { printf '\e[8;44m'"$*"'\e[m'; }
    BmagentaV () { printf '\e[8;45m'"$*"'\e[m'; }
    BpurpleV () { printf '\e[8;45m'"$*"'\e[m'; }
    BaquaV () { printf '\e[8;46m'"$*"'\e[m'; }
    BcyanV () { printf '\e[8;46m'"$*"'\e[m'; }
    BgreyV () { printf '\e[8;47m'"$*"'\e[m'; }
    BwhiteV () { printf '\e[8;47m'"$*"'\e[m'; }
## ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ ##

The only thing to keep in mind is when wanting a % percent sign or a \ backslash, you need to double them up inside:
like: printf "$(Tblue "%%s\\n")" 'hi'
but not for Tblue "%s\n" 'hi'
or printf "$(Tblue "%s" 'hi')\n"

Since these use printf, you can do stuff like:

printf "hi $(Tred there) man $(BaquaI "%c" '!') $(Bold 'This \\t is %%s') %s\n" "$(BgreenB 'super')" "$(Bblue mega Colorful)"

or in an echo:

echo "hi $(Tred there) man $(BaquaI "%c" '!') $(Bold 'This \\t is %s' "$(BblackB 'super')") $(Bblue mega Colorful)"

A more useful example:

printf "\t%s Volume \"%s\" is not connected.\n" "$(TwhiteB [)$(TredB Error)$(TwhiteB \]:)" "$(Tbrown $Volume)"

Or with other commands:

eval "echo 'This is OSX' | sed 's:OSX:$(Invert [)$(TaquaF OSX)$(Invert ]):'"

Or something with a bit more swank:

find . -exec stat -f "Name: $(Tbrown %%N)%t%t$(Tpurple "->")%tPermissions: $(Tgreen %%Sp)" {} \;

Control commands that dump anything so that what you're scanning for sticks out like a sore thumb... (throbbing red in this case):

eval "ps aux | sed 's|bash|$(BredF 'bash')|g'"

Use your imagination! Feel free all to use these...

Some may say, what's the use of invisible text?
        –– Not much, really... but it's there. I have used it a few times, but only to line up text when "drawing" with Unicode characters...


Now for my questions...

      1) The meta-question: If anyone out there feels like typing up a continuation of what I've started, can you please use the format above? or at least a similar format? Some examples are:

TgreenBU            ## Bold, underlined, green text ##
TcyanBUFBblackI     ## Bold cyan/aqua text that's underlined and flashing on an inverted black background ##

And so on... make up your own names so that it's possible to have all the permutations with minimal, yet clear parameter names. These are examples, but I haven't looked to see if these names conflict with others... If someone out there likes these functions, uses them regularly, has some time, and woud like to give back something, can this mythical person please post them for me on this question as a reply or email them to me at [mdouglas34@hotmail.com]1. I'm too lazy to type up all the possibilities (I've quickly calculated over 7000 of them, but there may be many, many more if I missed something).

      2) The main question: Since I use these Color Functions all the time... in every script, I need to know something about another user's terminal:
          Is there any way to determine the background color of a terminal (without looking at it directly obviously)?

          Can any other information be gleaned? Like if the terminal is set to handle colors? Perhaps their LSCOLORS or something to give hints at their terminal capabilities/settings? I guess $TERM if set to xterm-color, that's a dead giveaway that colors are possible... but what are the capabilities of other terminals? Can rxvt produce the same colors? How is xterm-256color relate to this? can more colors be used than the standard 8? and 8 bold?
          basically, I want to write code that spits out color output and is suitable on any system running any terminal, with any setting. Is there any way to get this information or is this only a pipe dream?

          Finally... What about fonts? do all terminals use proportional/monospaced fonts? Is there any way to determine if a user has, say, unicode support? It would be nice to konw if certain pretty yet fancy characters are not going to display property as they could be swapped with uglier, yet simpler characters.

So basically, I'm looking for many ways to scan a non-local user's settings, environment, so that pretty-print code would be ported elsewhere. Is there software writted for this purpose out there that I don't know of?

Sorry for all the questions... some precise, others a bit vague... I hope there will be lots of answers for me to pool together. Porting pretty-print is a major challenge in the unix world... I hope to make a dent in this battleship of a problem.

In the mean time all, feel free all to use my Color Functions as you see fit!

Enjoy!

-- Aesthir

解决方案

Hi all... I'm answering my own question in an attempt to bump it to active again... if that is possible?

I want to point out that I spent quite a long time researching, typing, and waiting during the process of asking a question that supposedly reaches millions. Here's what I did:

  • Researched: tried to google-up the answers to my questions long before posting and found nothing.
  • Searched the Site: did not want to aska aquestion that has already been asked so I searched for every wording/tagging possibility I could think of.... and also like above, nothing.
  • Posted pretty-printed: long post so time spent labeling (bold/italic/larger text) & organizing (related chunks spaced accordingly/centering, etc..) for a clear, easily readable post. The reader is hard pressed to miss my questions, they are located:

               【 Now for my questions...

         2) The main question: 】   section in my post under the horizontal rule
  • Brainstormed: thought out all the angles and possible sub-questions that may arise
  • Gave Back: I even gave to the community; some code I use so frequently I thought others may want try it out.
  • Added Examples: went so far as to invent, test, and type up a bunch of examples to aid in figuring out how to use my color functions.
  • Waited: Finally, I waited 3¹/₂ months for an answer... any answer... nothing yet.  8.^.(

I figure I put in at least some effort into posting a few questions, perhaps someone out there will pity me and put a few minutes into posting a reply.

What I'm looking for (from most to least):

  1. An answer to one or more of my questions... yay! I've been wanting the ability to probe the terminal for a long time now. In addition to the "Terminal" features requested in my original post, here are 2 more
    • When the color functions are output to a file, every escape code is present... How do I know if sdout gets redirected to a file? and any way to intercept that and sed the output – maybe a trap call – ?
    • Lots of my scripts contain high-value Unicode and they get translated to gargabe (to a human) with some ~/.inputrc options set.Which option(s) are these? If I knew that, I could test the results of bind -v | sed
  2. A response or email (mdouglas34@hotmail.com) containing more Color functions in about the same manner as mine are. examples of text that cannot have the properties with the above functions:
    • bold and underlined text
      • (any 2 non-color properties, or more)
    • bold yellow text on a red background
      • (any color text on a differrent color background)
    • bold, red, flashing text on a black background
      • (basically the first two examples joined)
  3. Some "Question has been researched" pump ups... lol... always good to have
  4. And along those lines, some reputation *"+1"*s
  5. A response saying one or more of the things asked for are not possible
    • if not, why? what's preventing me from knowing a little about the terminal it's run on?
  6. Any response at all... having trouble with those. Not one in over 3 months.
  7. Comments are welcome as well. Only got 2. btw, thx Triplee & shellter

    Thx all!

              Aesthir

这篇关于彩色化文本/背景下,如何让pretty打印便携?此外,通过Aesthir书面彩色功能的大名单,享受?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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