-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add_defun() can define 13 functions max. #23
Comments
Thank you for your report. 3 functions are already defined by this module. --- a/Gnu.pm
+++ b/Gnu.pm
@@ -2291,6 +2291,7 @@ GTK+ support in addition to Tk.
L<the bug tracker on GitHub|https://github.com/hirooih/perl-trg/issues>.
=item C<add_defun()> can define up to 16 functions.
+And some of them are used already.
=item Some functions and variables do not have test code yet. Your
contribution is welcome. See F<t/readline.t> for details. I have not found a way to eliminate this limitation. It requires to define a function dynamically. See Line 1638-1681 of Gnu.xs for the current implementation. |
I appreciate the quick response and suggestion.
I see that I can distribute a version of trg modified with
say, 32 custom perl functions to support the needs
of my application(*1).
However since I am distributing my app via debian, it will
great if trg can support 32 named functions by default,
if the memory costs are acceptable.
https://metacpan.org/dist/Audio-Nama/view/script/nama
Thank you
Joel Roth
…On Fri, Oct 20, 2023 at 07:12:34PM -0700, hirooih wrote:
Thank you for your report.
3 functions are already defined by this module.
```diff
--- a/Gnu.pm
+++ b/Gnu.pm
@@ -2291,6 +2291,7 @@ GTK+ support in addition to Tk.
L<the bug tracker on GitHub|https://github.com/hirooih/perl-trg/issues>.
=item C<add_defun()> can define up to 16 functions.
+And some of them are used already.
=item Some functions and variables do not have test code yet. Your
contribution is welcome. See F<t/readline.t> for details.
```
I have not found a way to eliminate this limitation. It requires to define a function dynamically.
See Line 1638-1681 of [Gnu.xs](https://github.com/hirooih/perl-trg/blob/master/Gnu.xs#L1637) for the current implementation.
If you need to define more functions, increase the size of `fntbl[]`.
--
Reply to this email directly or view it on GitHub:
#23 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
--
Joel Roth
|
I think the memory costs are acceptable in these years. The issue is how many functions are enough. This is the first request since 1996 when I released the first version. It seems that it is the time to double the size of the By the way, do you really need so many |
On Sat, Oct 21, 2023 at 07:51:53PM -0700, hirooih wrote:
I think the memory costs are acceptable in these years.
The issue is how many functions are enough. This is the first request since 1996 when I released the first version. It seems that it is the time to double the size of the `fntbl[]`.
By the way, do you really need so many `add_defun()` calls? Your example above needs only one `add_defun()` call.
As described [here](https://metacpan.org/pod/Term::ReadLine::Gnu#Custom-Functions) a custom function has two arguments. You can use the second argument, `$key`, to distinguish which key sequence is used. Does this solve your issue?
Yes, I could certainly dispatch on the key sequence.
… --
Reply to this email directly or view it on GitHub:
#23 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
--
Joel Roth
|
Good! After some thought, I decide not to change the size of the table this time. I will add a link to this issue ticket in the bug section of the documentation. Again, thank you for your report. |
On Sun, Oct 22, 2023 at 06:40:26AM -0700, hirooih wrote:
>> Does this solve your issue?
> Yes, I could certainly dispatch on the key sequence.
Good!
After some thought, I decide not to change the size of the table this time.
I will add a link to this issue ticket in the bug section of the documentation.
I will change it when I really have a good reason to do it.
Again, thank you for your report.
That's fine, but I will say it's a more complicated API to
deal with to avoid bumping into the limit. Admittedly
a slow worker, I've spent an hour working on something
that was already working before.
Thank you for your awesome software.
… --
Reply to this email directly or view it on GitHub:
#23 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
--
Joel Roth
|
On Sun, Oct 22, 2023 at 10:40:18AM -1000, Joel Roth wrote:
On Sun, Oct 22, 2023 at 06:40:26AM -0700, hirooih wrote:
> >> Does this solve your issue?
>
> > Yes, I could certainly dispatch on the key sequence.
>
> Good!
Hi,
I tried to dispatch on the key sequence as you suggest.
I encounter a problem that several keys return the
same code. In particular all of
Insert/Home/PageUp/Delete/End/PageDown return code 126,
which is only the last of the four codes returned
by showkey -a in my xterm.
I'm attaching test code to demonstrate.
Thanks for your attention.
use v5.30;
use Term::ReadLine;
my $term = Term::ReadLine->new('custom function test');
my %escape_code;
read_esc_codes();
my $func_name = 'hotkey_dispatch';
my $coderef = \&hotkey_dispatch;
$term->add_defun($func_name, $coderef);
my $i = 0;
while ( my ($keyname,$seq) = each %escape_code) {
$term->bind_keyseq($seq, $func_name);
say ++$i;
}
our %function;
sub hotkey_dispatch {
say join ' ',@_
}
sub read_esc_codes {
%escape_code = qw(
Escape \\e
Insert \\e[2~
Home \\e[1~
PageUp \\e[5~
Delete \\e[3~
End \\e[4~
PageDown \\e[6~
Up \\e[A
Left \\e[D
Down \\e[B
Right \\e[C
F1 \\eOP
F2 \\eOQ
F3 \\eOR
F4 \\eOS
F5 \\e[15~
F6 \\e[17~
F7 \\e[18~
F8 \\e[19~
F9 \\e[20~
F10 \\e[21~
F11 \\e[23~
F12 \\e[24~
Keypad/ \\eOo
Keypad* \\eOj
Keypad- \\eOm
Keypad+ \\eOk
Keypad7 \\eOw
Keypad8 \\eOx
Keypad9 \\eOy
Keypad4 \\eOt
Keypad5 \\eOu
Keypad6 \\eOv
Keypad1 \\eOq
Keypad2 \\eOr
Keypad3 \\eOs
Keypad0 \\eOp
Keypad. \\eOn
KeypadEnter \\eOM
);
our %keyname = ( reverse %escape_code );
}
while ( defined ($_ = $term->readline('prompt>')) ) {say "got a line: $_" }
|
Sorry I was wrong. sub hotkey_dispatch {
say string_to_hex_dump($term->Attribs->{executing_keyseq});
}
sub string_to_hex_dump {
my ($string) = @_;
my $hex_dump = '';
for my $char (split //, $string) {
$hex_dump .= sprintf("%02X ", ord($char));
}
return $hex_dump;
} |
With the help of your code I reduced to one the number of
custom functions needed to dispatch from special
key character combinations.
Here is an improved version of my sample code. It identifies
the key pressed, and shows the sequence in various formats.
I'm curious that this script doesn't correctly capture many
of the key combinations (such as Ctrl-Insert, Shift-F3) that
showkey -a displays.
use v5.30;
use Term::ReadLine;
my $term = Term::ReadLine->new('keyboard code and custom dispatch test');
my %escape_code; # Insert -> \e[2~
my %keyname; # \e[2~ -> Insert
read_esc_codes();
my $func_name = 'hotkey_dispatch';
my $coderef = \&hotkey_dispatch;
$term->add_defun($func_name, $coderef);
while ( my ($keyname,$seq) = each %escape_code) {
$term->bind_keyseq($seq, $func_name);
}
sub hotkey_dispatch {
my ($seq, $decimal, $hex) = string_to_escape_code($term->Attribs->{executing_keyseq});
my $name = $keyname{$seq};
say "Special key: $name, escape sequence: $seq, decimal: $decimal, hex: $hex";
say
}
sub string_to_escape_code {
my ($string) = @_;
my $esc = '';
my $decimal = '';
my $hex = '';
for my $char (split //, $string) {
my $ord = ord($char);
# It seems that readline intercepts control characters
# so don't try to convert them.
$char = '\e' if $ord == 27;
$decimal .= "$ord ";
$esc .= $char;
$hex .= sprintf("%02X ", $ord);
}
$esc, $decimal, $hex;
}
sub read_esc_codes {
%escape_code = qw(
Escape \\e
Insert \\e[2~
Delete \\e[3~
Home \\e[1~
End \\e[4~
PageUp \\e[5~
PageDown \\e[6~
Up \\e[A
Left \\e[D
Down \\e[B
Right \\e[C
F1 \\eOP
F2 \\eOQ
F3 \\eOR
F4 \\eOS
F5 \\e[15~
F6 \\e[17~
F7 \\e[18~
F8 \\e[19~
F9 \\e[20~
F10 \\e[21~
F11 \\e[23~
F12 \\e[24~
Keypad/ \\eOo
Keypad* \\eOj
Keypad- \\eOm
Keypad+ \\eOk
Keypad7 \\eOw
Keypad8 \\eOx
Keypad9 \\eOy
Keypad4 \\eOt
Keypad5 \\eOu
Keypad6 \\eOv
Keypad1 \\eOq
Keypad2 \\eOr
Keypad3 \\eOs
Keypad0 \\eOp
Keypad. \\eOn
KeypadEnter \\eOM
);
%keyname = ( reverse %escape_code );
}
while ( defined ($_ = $term->readline('prompt>')) ) {say "got a line: $_" }
…__END__
--
Joel Roth
|
I have never heard of the command On my terminal Does this ( rl_set_timeout ) help you? |
I've debugged my problems. Thank you for your
assistance. You may close this issue.
regards,
…--
Joel Roth
|
[#23] Signed-off-by: Hiroo HAYASHI <[email protected]>
You are welcome. I've created PR #24. It will be included in the next release. Thanks!. |
The BUGS section of the manual says up to 16 functions may be defined using add_defun(). This test code fails after 13 functions are defined.
The text was updated successfully, but these errors were encountered: