【问题标题】:Highlighting or underlining output to stdout on Windows在 Windows 上突出显示或下划线输出到标准输出
【发布时间】:2019-03-02 22:35:23
【问题描述】:

背景

我需要将 Perl 脚本从 Linux 移植到 Windows。脚本输出到标准输出并根据需要突出显示和下划线特定的单词。在 Linux 中,这可以通过使用对 tput 的系统调用将单词括起来来实现:

tput smso 和 tput rmso 用于突出显示

tput smul 和 tput rmul 用于下划线

问题

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

【问题讨论】:

  • Write-Host 具有可用于突出显示的 -BackgroundColor 和 -ForegroundColor 参数。

标签: windows powershell perl cmd


【解决方案1】:

如果您使用 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");

但如果您只是在寻找真正快速的移植修复程序,Win32::Console::ANSI 会“神奇地”将您输出中的所有 ANSI 序列转换为适当的控制台调用。

【讨论】:

  • 谢谢! Win32::Console::ANSI 正是我想要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-08
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
  • 1970-01-01
相关资源
最近更新 更多