Search code examples
perlterminalmouseeventlibtermkey

Term::TermKey: How to enable wide mouse support?


When I run this script, the position of the mouse works up to the column 255 - then the count begins by 0. Does this mean that my terminal does not support SGR/mode 1006?
(edited due ak2's answer)

#!/usr/bin/env perl
use warnings;
use 5.12.0;
use utf8;
use Term::TermKey qw(FLAG_UTF8 FORMAT_LONGMOD FORMAT_MOUSE_POS);
my $tk = Term::TermKey->new( \*STDIN );
binmode STDOUT, ':encoding(UTF-8)' if $tk->get_flags & FLAG_UTF8;

$|++;
print "\e[?1003h";
print "\e[?1006h";

say "Quit with \"q\"";
while( 1 ) {
    $tk->waitkey( my $key );
    say $tk->format_key( $key, FORMAT_LONGMOD | FORMAT_MOUSE_POS );
    last if $tk->format_key( $key, 0 ) eq 'q';
}

print "\e[?1006l";
print "\e[?1003l";

Solution

  • No.

    It means you're not using the very lastest libtermkey library yet, the one that supports positions greater than column 255. Possibly because I haven't actually released it yet ;)

    I'll let you know once that's up, along with the extra CSI capture support for position reporting, etc..

    Also: If you have more libtermkey-specific questions, you might want to let me know more directly. E.g. you could email me to let me know you've posted a question; I don't always make a habit of searching them out. :)


    Edit 2012/04/26: I've now released libtermkey 0.15 and Term::TermKey 0.14, which supports these columns above 255, along with the position report API.