Subject: | Enable UTF8 in different ways |
Hello
I noticed there is code to handle unicode if the -C flag is used ($^{UNICODE} variable). I feel most people do not use the -C flag at all, and it would be nice if it was possible to just enable unicode read/output from standard Perl code.
The patch in attach is doing so. I am using it on a tool that uses unicode in most directions (printing in the OUT handler, reading unicode from readline, unputting unicode strings in readline method, etc) and it is working perfectly.
So, if you are happy with it, I would be very grateful if the patch could be applied.
Best regards,
Alberto
Subject: | trg.diff |
Index: Gnu.pm
===================================================================
--- Gnu.pm (revision 485)
+++ Gnu.pm (working copy)
@@ -141,7 +141,7 @@
preput => 1, attribs => 1, newTTY => 1,
tkRunning => Term::ReadLine::Stub->Features->{'tkRunning'},
ornaments => Term::ReadLine::Stub->Features->{'ornaments'},
- stiflehistory => 1,
+ stiflehistory => 1, unicode => 0,
);
# keep rl_readline_version value for efficiency
@@ -350,7 +350,7 @@
# from ReadLine.pm: convert to the internal representation from UTF-8
# see 'perldoc perlvar'
- if ((${^UNICODE} & 1 || defined ${^ENCODING}) &&
+ if (($Features{unicode} || ${^UNICODE} & 1 || defined ${^ENCODING}) &&
utf8::valid($line)) {
#utf8::upgrade($line);
utf8::decode($line);
@@ -505,6 +505,19 @@
select($sel);
}
+=item C<enableUTF8>
+
+activates unicode support, binmoding output file handle,
+and preencoding input.
+
+=cut
+
+sub enableUTF8 {
+ my ($self) = @_;
+ $Features{unicode} = 1;
+ binmode $self->OUT, ":utf8";
+}
+
=back
=cut