How do I color output text from Perl script on Windows?

后端 未结 5 958
别那么骄傲
别那么骄傲 2021-02-06 00:36

I would like to color format the text printed to the console using the Perl print command.

In my case the script will only be run under WinXP-DOS Command Line but it wou

5条回答
  •  猫巷女王i
    2021-02-06 00:56

    Win32::Console - here's an example

    use Win32::Console;
    my $CONSOLE = Win32::Console->new(STD_OUTPUT_HANDLE);
    my $attr = $CONSOLE->Attr(); # Get current console colors
    $CONSOLE->Attr($FG_YELLOW | $BG_GREEN); # Yellow text on green
    
    print "This is a test\n";
    
    $CONSOLE->Attr($attr); # Set console colors back to original
    

提交回复
热议问题