hanspr has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I'm trying to read a range of text from Vte::Terminal

There is a very old reference of Gtk2::Vte on how to call this method at :
https://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Vte/Terminal.html

And this link documents the function and its parameters
https://api.gtkd.org/vte.Terminal.Terminal.getTextRange.html

My problem is that I don't understand how to create the $func parameter

I have tried this code, but it fails with fatal errors

$$self{_GUI}{_VTE} = Vte::Terminal->new(); # more code my $func = sub { return 1 }; my $string = $$self{_GUI}{_VTE}->get_text_range($row, $col, $row, $end +_col, $func, my $data = undef);
ERROR:gperl-i11n-invoke-c.c:584:_allocate_out_mem: assertion failed: (interface_info)
Bail out! ERROR:gperl-i11n-invoke-c.c:584:_allocate_out_mem: assertion failed: (interface_info)

And many other variants that make even less sense, and all of them fail. Inclusive passing the undef value to the function.

For example this line does not crash, but it does not work either

my $func = {sub => {return 1}}; my $string = $$self{_GUI}{_VTE}->get_text_range($row, $col, $row, $end +_col, $func, my $data = undef);

I need to be able to grab the text from a line where the user clicks, so I can test for the existence of a url and then try to open the url on a browser.

This is for the open source project asbru on github

If you need a working code, the only option I can offer is to clone the repo at : https://github.com/asbru-cm/asbru-cm

Edit PACTerminal.pm and around line 1141 you should see the button_press_event

In the button_press_event, you can add the line to grab the text with any fixed parameters at any point when the user clicks

Thanks

Replies are listed 'Best First'.
Re: how to call gtk3::vte::grab_text_range
by bliako (Abbot) on Sep 17, 2025 at 13:07 UTC

    I would say that this my $func = {sub => {return 1}}; should be my $func = sub { return 1 };, that's in the 2nd case.

    Where is the source code of get_text_range()? You should start from there and see the whole chain of the complain it spewed. Logically, memory should be allocated in the buffer to accommodate the text which should be related to the row/col range you pass in. Are you sure they are OK?

      Pardon me from the previous answer, you did help me a lot

      After searching for the current vte development at gitlab, found the solution

      get_text_range , is depreciated

      Using: get_text_range_format, works perfectly

      my ($string, $l) = $$self{_GUI}{_VTE}->get_text_range_format('VTE_FORM +AT_TEXT', 0, 0, 0, 20);

      Thanks a lot

      Thanks for the answer

      The second case, was a test. fixing to $func = sub {return 1}, returns to the first case

      The only reason I mentioned is because, strangely it does not crash sending that parameter like that, which is weird for me

      Accessing the source code of the get_text_range(), must be in some place of the gitlab repos for gtk from the gnome project, written in C

      But in general by reading the Gtk documentation I have been able to work out everything, this is the first time I don't

      This link shows the parameters to send : https://api.gtkd.org/vte.Terminal.Terminal.getTextRange.html

      This link shows the function call : https://api.gtkd.org/vte.c.types.VteSelectionFunc.html

      This link shows the old gnome2 vte documentation : https://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Vte/Terminal.html, from where I must of the basic code that I use, everything else still works

      I'm sure that I send the parameters correctly, because, I have tried a simple fixed call like this:

      # Right mouse click on VTE $$self{_GUI}{_VTE}->signal_connect( 'button_press_event' => sub { if ($right_click_deep) { return 0; # Bubble up, let VTE's original handler t +ake care of it. } my ($widget, $event) = @_; my $state = $event->get_state(); my $shift = $state * ['shift-mask']; if ($event->button eq 2) { if (!$$self{_CFG}{'environments'}{ $$self{_UUID} }{'se +nd slow'}) { return 0; } $$self{_GUI}{_VTE}->paste_primary(); $$self{FOCUS}->child_focus('GTK_DIR_TAB_FORWARD'); return 1; } elsif ($event->button eq 3 and $event->type eq 'button-p +ress') { # See #209 for all this hack. my $handled_by_vte = 0; if (!$shift) { $right_click_deep = 1; $handled_by_vte = $$self{_GUI}{_VTE}->event($eve +nt); $right_click_deep = 0; } if (!$handled_by_vte) { $$self{FOCUS}->child_focus('GTK_DIR_TAB_FORWARD'); $self->_vteMenu($event); } return 1; # One way or another, we've handled it. } elsif ($event->button eq 1 && $event->type eq 'button-pr +ess' && $shift) { my ($w, $h) = $$self{_WINDOWTERMINAL}->get_size(); my ($col, $row) = (int($event->x / $$self{_GUI}{_VTE}- +>get_char_width()), int($event->y / $$self{_GUI}{_VTE}->get_char_widt +h() - 1)); print "($col,$row)\n"; my $func = sub { return 1 }; #my $string = $$self{_GUI}{_VTE}->get_text_range($row, + $col, $row, int($w / $$self{_GUI}{_VTE}->get_char_width() + 0.5), $f +unc, my $data = undef); my $string = $$self{_GUI}{_VTE}->get_text_range(1, 0, +1, 5, $func, my $data = undef); #my @list = $$self{_GUI}{_VTE}->get_text(); #print "($row,$col):@list\n"; }

      In this case I send fixed values for row,col that I know have text in that range and still I get the error

      The other oddity of this is that this code crashes too

      my @list = $$self{_GUI}{_VTE}->get_text(); my @list = $$self{_GUI}{_VTE}->get_text($func = udef,$data = undef);

      Even when the documentation says that the 2 parameters are optional

      The other thing I'm not able to find is where is the documentation for the current Vte library is I just have this old link to use as a reference https://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Vte/Terminal.html

Re: how to call gtk3::vte::grab_text_range
by Anonymous Monk on Sep 21, 2025 at 01:23 UTC