简体   繁体   English

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

[英]Highlighting or underlining output to stdout on Windows

Background 背景

I need to port a Perl script from Linux to Windows. 我需要将Perl脚本从Linux移植到Windows。 The script outputs to stdout and highlights and underlines specific words as needed. 脚本输出到stdout并突出显示并根据需要为特定单词加下划线。 In Linux, this can be accomplished by surrounding the word(s) with system calls to tput : 在Linux中,这可以通过将系统调用包含在tput

tput smso and tput rmso for highlighting tput smsotput rmso用于突出显示

tput smul and tput rmul for underlining tput smultput rmul强调

Question

Are there any system calls on Windows that can easily accomplish this functionality? Windows上是否有可以轻松实现此功能的系统调用? If not, does anyone know a workaround that would accomplish similar results? 如果没有,有没有人知道可以实现类似结果的解决方法?

If you're using Perl to output stuff, at least Win32::Console can do underline on Windows (10 onwards) as well: 如果您使用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");

But if you're just looking for a Really Quick porting fix, Win32::Console::ANSI will "magically" convert all ANSI sequences in your output to the appropriate console calls. 但是,如果你只是在寻找一个真正快速的移植修复, Win32 :: Console :: ANSI将“神奇地”将输出中的所有ANSI序列转换为适当的控制台调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM