Native Cut&Paste on Win* and Mac?

  • Thread starter Ilya Zakharevich
  • Start date
I

Ilya Zakharevich

My current version of Term::ReadLine::perl (should be on CPAN in a
couple of hours) supports native cut&paste only on OS/2. If somebody
can very quickly supply patches (or code snippets) which work on Win*
and Mac, there is a good chance of their inclusion into the module.

Here are two samples:

if ($^O eq 'os2') {
eval {
require OS2::process;
$in = OS2::process::ClipbrdText();
$in =~ s/\r\n/\n/g; # With old versions, or what?
}
} else {

-------------------

my $in = shift;
if ($^O eq 'os2') {
eval {
require OS2::process;
OS2::process::ClipbrdText_set($in);
1
} and return;
}

Thanks,
Ilya
 
A

A. Sinan Unur

My current version of Term::ReadLine::perl (should be on CPAN in a
couple of hours) supports native cut&paste only on OS/2. If somebody
can very quickly supply patches (or code snippets) which work on Win*
and Mac, there is a good chance of their inclusion into the module.

Here are two samples:

if ($^O eq 'os2') {
eval {
require OS2::process;
$in = OS2::process::ClipbrdText();
$in =~ s/\r\n/\n/g; # With old versions, or what?
}
} else {

I was not able to locate the module. But, would something like this
work?

if ($^O eq 'MSWin32') {
eval {
require Win32::Clipboard;
$in = Win32::Clipboard::GetText();
$in =~ s/\r\n/\n/g; # is this needed?
}
} else {

and
-------------------

my $in = shift;
if ($^O eq 'os2') {
eval {
require OS2::process;
OS2::process::ClipbrdText_set($in);
1
} and return;
}

my $in = shift;
if ($^O eq 'MSWin32') {
eval {
require Win32::Clipboard;
Win32::Clipboard::Set($in);
1
} and return;
}

I can patch and test, probably on Monday afternoon.

HTH.

Sinan
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
A. Sinan Unur
I was not able to locate the module. But, would something like this
work?

Sorry, I have no way to test on Win32 and Mac. So what I need is code
which is tested to work (at least to some extent ;-).

Well, I can incorporate the stuff even if only compiles ;-); and I can
test *this*. Running is an extra (with eval{}, it can't break things
much). ;-)

Thanks,
Ilya
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
A. Sinan Unur
I was not able to locate the module. But, would something like this
work?

I put your code into 1.0207 (it compiles, but I can't check
functionality, especially what happens with \r\n - on OS/2 by default
there is translation on setting, but not on getting). Should
propagate PAUSE -> CPAN very soon.

Thanks,
Ilya
 
A

A. Sinan Unur

[A complimentary Cc of this posting was sent to
A. Sinan Unur
I was not able to locate the module. But, would something like this
work?

I put your code into 1.0207 (it compiles, but I can't check
functionality, especially what happens with \r\n - on OS/2 by default
there is translation on setting, but not on getting). Should
propagate PAUSE -> CPAN very soon.

I'll see if I can provide any useful input on Monday.

Sinan
 
A

A. Sinan Unur

[A complimentary Cc of this posting was sent to
A. Sinan Unur
I was not able to locate the module. But, would something like this
work?

I put your code into 1.0207 (it compiles, but I can't check
functionality, especially what happens with \r\n - on OS/2 by default
there is translation on setting, but not on getting). Should
propagate PAUSE -> CPAN very soon.

I decided to install the module on my office computer in between
teaching. Here is what I get if I run test.pl after installation:

C:\Home\asu1\src\Term-ReadLine-Perl-1.0207> perl test.pl
Features present: preput 1 getHistory 1 addHistory 1 attribs 1 ornaments
1 appname 1 minline 1 autohistory 1 newTTY 1 tkRunning 1 setHistory 1
Flipping rl_default_selected each line.

SetConsoleMode failed, LastError=|6| at
C:/opt/Perl/site/lib/Term/ReadKey.pm line 265.
at C:/opt/Perl/site/lib/Term/ReadLine/readline.pm line 1475
readline::readline('Enter arithmetic or Perl expression: ',
'exit') called at C:/opt/Perl/site/lib/Term/ReadLine/Perl.pm line 11
Term::ReadLine::perl::readline('Term::ReadLine::perl=ARRAY
(0x1a67b14)',
'Enter arithmetic or Perl expression: ', 'exit') called at test.pl line
38
Enter arithmetic or Perl expression:

The example works after that, but I am having a hard time using any
keybindings to actually copy from and paste into the line when test.pl is
running in a cmd.exe shell.

I gotta run to class now, but I'll look into this later.

Sinan
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
A. Sinan Unur
I decided to install the module on my office computer in between
teaching. Here is what I get if I run test.pl after installation:

C:\Home\asu1\src\Term-ReadLine-Perl-1.0207> perl test.pl
Features present: preput 1 getHistory 1 addHistory 1 attribs 1 ornaments
1 appname 1 minline 1 autohistory 1 newTTY 1 tkRunning 1 setHistory 1
Flipping rl_default_selected each line.
SetConsoleMode failed, LastError=|6| at
C:/opt/Perl/site/lib/Term/ReadKey.pm line 265.

Sigh. At least you got an error message; so did TRP, and it had a
chance to fall back to a "dumb" input method. In some cases a broken
Term::ReadKey installation will just fail silently, without any way to
inform the caller that she should resolve to some fallbacks...

And, in my experience, most vendor-supplied Perl installations are
shipped completely broken...

Hope this helps,
Ilya
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
A. Sinan Unur
SetConsoleMode failed, LastError=|6| at
C:/opt/Perl/site/lib/Term/ReadKey.pm line 265.
at C:/opt/Perl/site/lib/Term/ReadLine/readline.pm line 1475
readline::readline('Enter arithmetic or Perl expression: ',
'exit') called at C:/opt/Perl/site/lib/Term/ReadLine/Perl.pm line 11
Term::ReadLine::perl::readline('Term::ReadLine::perl=ARRAY
(0x1a67b14)',
'Enter arithmetic or Perl expression: ', 'exit') called at test.pl line
38
Enter arithmetic or Perl expression:

As Adam Kennedy informed me, this may be not a bug in Perl
installation, but a bug in the Windows device driver for 'CON:'. A
temporary workaround for the test script is to run it as

perl -Mblib test.pl std

See the discussion in

http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2006-02/msg01018.html

Looks like a permanent workaround should be put in Term::ReadLine, if
the communication path between Term::ReadLine and Term::ReadLine::perl
is flexible enough (as I hope it is).

Anyone knowing how Term::ReadLine::Gnu is handling this bug of Windows?

Thanks,
Ilya
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Ilya Zakharevich
As Adam Kennedy informed me, this may be not a bug in Perl
installation, but a bug in the Windows device driver for 'CON:'.

I would appreciate tests of the latest version 1.0208 of
Term::ReadLine::perl on Win*. It should have a workaround for this
bug. (Best if the test are run with unpatched Term::ReadLine.)

[I already know about the "multiple Enter presses" required syndrom.]

Thanks,
Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top