【问题标题】:Print more than ANSI color values in Perl在 Perl 中打印超过 ANSI 颜色值
【发布时间】:2012-02-24 08:34:38
【问题描述】:

我喜欢 Perl 的 Term::ANSIColor 模块,但是是否可以打印出提供的颜色以外的颜色?

我正在尝试打印出介于深红色和亮绿色之间的单词,并且它们之间的步数相当多。有没有办法提供 RGB 值或其他东西来改变文本的颜色?

【问题讨论】:

    标签: perl colors ansi-escape


    【解决方案1】:

    您使用Term::ExtendedColor。 您可以通过此模块使用 256 种颜色。

    【讨论】:

    • 值得注意的是,显示的颜色取决于 OP 使用的终端。
    【解决方案2】:

    一些终端甚至接受完整的 8 位 RGB 颜色规范。

    $ perl -E 'say "\e[38:2:255:100:80mHello\e[m"'
    Hello
    

    这可以用rgb(255,100,80) 粉红色打印。取决于你的终端。

    作为一种从任意 RGB 组合中获取 xterm256 颜色值的方法,您可能还喜欢Convert::Color

    use strict;
    use warnings;
    
    use Convert::Color;
    use Convert::Color::XTerm;
    
    foreach my $hue ( map { $_ * 15 } 0 .. 120/15 ) {
       my $c = Convert::Color->new( "hsv:$hue,1,1" );
       my $index = $c->as_xterm->index;
       print "\e[38:5:${index}mHue=$hue\e[m\n";
    }
    

    我会在此处粘贴输出,但很难在评论中传达颜色:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-01
      • 2020-06-12
      • 1970-01-01
      • 2016-08-17
      • 2023-04-07
      • 2015-01-25
      • 2020-01-29
      • 2017-09-30
      相关资源
      最近更新 更多