在Windows上突出显示或强调输出到stdout

rob*_*sia 3 windows powershell perl cmd

背景

我需要将Perl脚本从Linux移植到Windows.脚本输出到stdout并突出显示并根据需要为特定单词加下划线.在Linux中,这可以通过将系统调用包围在一起来实现tput:

tput smsotput rmso突出显示

tput smultput rmul强调

Windows上是否有可以轻松实现此功能的系统调用?如果没有,有没有人知道可以实现类似结果的解决方法?

Cor*_*ion 5

如果您使用Perl输出内容,至少Win32 :: Console也可以在Windows上进行下划线(10以后):

my $win32_console Win32::Console->new();

        # Rendering is flakey under Windows 10
my $attr =  0x8000 # COMMON_LVB_UNDERSCORE, Windows 10 onwards
          | 0x4000 # COMMON_LVB_REVERSE_VIDEO, Windows 10 onwards
          ;
$console->Attr($attr);
$console->Write("Hello World");
Run Code Online (Sandbox Code Playgroud)

但是,如果你只是在寻找一个真正快速的移植修复,Win32 :: Console :: ANSI将"神奇地"将输出中的所有ANSI序列转换为适当的控制台调用.