in reply to Re^3: Saving a Perl session to a file
in thread Saving a Perl session to a file

hello estimed AnomalousMonk,

I do not wanted you doing the job in my place ;=) I just hoped you had a more precise idea of how to work with this module: infact i looked at it several times in the past and i gave up, everytime.

> to show what might be done with Win32::Console.

This is exactly my problem. What is effectively possible to do with this? The lack of SYNOPSIS in the module is well.. disorienting at least

The /eg/sample.pl runs fine here but is not a simple sample. Nor the net nor PM are source of great examples..

The module date 10 Feb 1997, by dada, the XS seems to do everything and is beyond my possibilities.

And yes your example works for me but as you said it prints everything in vertical, as you shown.

I'v played with it a bit, using what the logic of names suggested to me and got not WriteRect working as I expected:

use warnings; use strict; use Win32::Console qw(GENERIC_READ GENERIC_WRITE); use Data::Dump qw(dd); my $con_current = Win32::Console->new(GENERIC_READ | GENERIC_WRITE); $con_current or die 'new Win32::Console failed'; my ($left, $top, $right, $bottom) = $con_current->Window; print "Dimensions (left top right bottom):",qq($left, $top, $right, $b +ottom \n); my $rect = $con_current->ReadRect($left, $top, $right, $bottom); $rect or die 'read Win32::Console failed'; #$rect =~ s{ \0\a\0 } ''xmsg; #$rect =~ s{ [ ]+ \z } ''xmsg; #dd $rect; print qq{======\nBefore writing anything from Win32.:Console\n======\n +}; $con_current->WriteRect($rect,$left, $top, $right, $bottom )or die 'wr +ite Win32::Console failed'; print "dd of \$rect: "; dd $rect; ##OUTPUT Dimensions (left top right bottom):0, 0, 119, 29 ====== Before writing anything from Win32.:Console ====== dd of $rect: (" \0\37\0" x 3600)

I suspect \0\37\0 is because i run the sample.pl and the screen remained white on blue; after i issued color 0A (green on black) i got dd of $rect: (" \0\n\0" x 3600) so this seems to be the attribute thing;

Your good luck was now comprensible ;=)

thanks anyway

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^5: Saving a Perl session to a file - Win32::Console usabability
by AnomalousMonk (Archbishop) on Apr 15, 2017 at 18:54 UTC

    Win32::Console is frustrating to use because it exposes you to the frustrations inherent in Windows!

    There are some problems I see in your code.
        my $con_current = Win32::Console->new(GENERIC_READ | GENERIC_WRITE);
    I can't get this to work. What works for me is  STD_OUTPUT_HANDLE as the argument to new().
        $con_current->WriteRect($rect,$left, $top, $right, $bottom )or die 'write Win32::Console failed';
    This will write the rectangle back to the console window at the exact position from which it was read, and there will be no visible effect!

    Here's a version of your code modified to produce some effect in the console window. The rectangle read by  ReadRect() has its coordinates shifted so a difference can be seen when written back by  WriteRect(). (You might also try changing color, etc., attributes to produce a noticeable change.)

    The intent of my original code was to produce a print-able string that might also be saved to a file. I see now that the
        $rect =~ s{ \0\a\0  } ''xmsg;
    substitution to strip out the attribute stuff was too specific to my console configuration. Try the more general
        $rect =~ s{ \G . \K ... } ''xmsg;
    (Note: This regex needs Perl version 5.10+ for the  \K regex operator. If you have a pre-5.10 Perl, I can supply an alternate regex.)

    All this is still very kludgy, but I hope it may be of some interest or use to you. And again, good luck!


    Give a man a fish:  <%-{-{-{-<