File: rltest

package info (click to toggle)
libterm-readline-gnu-perl 1.47-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,148 kB
  • sloc: perl: 2,191; makefile: 10
file content (36 lines) | stat: -rwxr-xr-x 830 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env perl
#
# rltest: readline() + add_history() + history_list()
#
#   Copyright (C) 2024 Hiroo Hayashi
#
# Derived from: examples/rltest.c in the GNU Readline Library
#   Copyright (C) 1987-2009,2023 Free Software Foundation, Inc.

use strict;
use warnings;
use Term::ReadLine;

my $t = new Term::ReadLine 'rltest';

my $prompt = 'readline$ ';
my $done   = 0;
while (!$done) {
    # use full qualified name not to call addhistory() implicitly.
    my $temp = Term::ReadLine::Gnu::XS::rl_readline($prompt);
    exit 1 unless defined $temp;

    if ($temp) {
        print STDERR "$temp\n";
        $t->addhistory($temp);
    }
    $done = 1 if $temp eq 'quit';

    if ($temp eq 'list') {
        my @list = $t->history_list();
        foreach my $i (@list) {
            print STDERR "$i\n";
        }
    }
}
exit 0;