John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I managed to get correct Unicode output displayed by using Win32::API to call the Console (wide version) primitives, using Encode to convert the strings to UTF-16LE. I wrapped it up using Tie::Handle and my program was able to use it without further impact.

Note that the Win32::Console module does not support Unicode. I'm supposing it only calls the narrow version of the API.

Now I'm contemplating making a polished module for this. I want feedback before I get around to making this more mature implementation and uploading it.

The prospective name is Win32::ConsoleOutput, but I'm still taking suggestions.

The primary purpose is to allow Perl programs to print output to the interactive console window, using the full character set.

Upon using this module, you can open a Perl handle (really a tie, not an actual file handle that the OS knows about) to do Console output, and it will take Perl's native encoding and make it just work.

There will be a handy way to tell it to replace STDOUT with this, if and only if STDOUT is not being redirected.

I'm also thinking about a related issue: more advanced terminal control. Other kinds of processing of the data stream are already handled by making a filter handle that sits in front of the real output, so the only business this has should be terminal-related stuff. In particular, changing colors and moving the cursor around.

Previously, it's been voiced that nobody likes the ANSI terminal stuff. Here's an idea for an extension mechanism that can handle this or whatever:

Have a hash as part of the ConsoleOutput object that maps characters to callbacks. Print a character that's listed, and the callback is invoked and the character filtered out. Use a couple chars in the Private Use zone to implement color codes, or add whatever you want. As a shortcut, a string (rather than a code ref) is a substitution. Use that to replace unprintable characters or specify alternate glyphs.

What do you think?

—John

Replies are listed 'Best First'.
Re: Module idea: Win32::ConsoleOutput
by BrowserUk (Patriarch) on Feb 18, 2004 at 00:49 UTC

    Sounds like a combination of Win32::Console and Win32::Console::ANSI + the wide character support.

    I like the idea of hiding it all behind a Tie::Handle interface.

    The name your looking at looks like you are only considering output. Have you thought about input of unicode?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Timing (and a little luck) are everything!
      No, I hadn't thought about input. I suppose it has similar problems, but input uses a different handle so a different module could be tied to it.