| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# rltest: readline() + add_history() + history_list() |
| 4 |
# |
| 5 |
# Copyright (C) 2024 Hiroo Hayashi |
| 6 |
# |
| 7 |
# Derived from: examples/rltest.c in the GNU Readline Library |
| 8 |
# Copyright (C) 1987-2009,2023 Free Software Foundation, Inc. |
| 9 |
|
| 10 |
use strict; |
| 11 |
use warnings; |
| 12 |
use Term::ReadLine; |
| 13 |
|
| 14 |
my $t = new Term::ReadLine 'rltest'; |
| 15 |
|
| 16 |
my $prompt = 'readline$ '; |
| 17 |
my $done = 0; |
| 18 |
while (!$done) { |
| 19 |
# use full qualified name not to call addhistory() implicitly. |
| 20 |
my $temp = Term::ReadLine::Gnu::XS::rl_readline($prompt); |
| 21 |
exit 1 unless defined $temp; |
| 22 |
|
| 23 |
if ($temp) { |
| 24 |
print STDERR "$temp\n"; |
| 25 |
$t->addhistory($temp); |
| 26 |
} |
| 27 |
$done = 1 if $temp eq 'quit'; |
| 28 |
|
| 29 |
if ($temp eq 'list') { |
| 30 |
my @list = $t->history_list(); |
| 31 |
foreach my $i (@list) { |
| 32 |
print STDERR "$i\n"; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
exit 0; |