Linenoise bindings for Perl 6
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.gitignore Fixes issues with lib name generation Jan 2, 2017
.gitmodules
.travis.yml Fixes issues with lib name generation Jan 2, 2017
Build.pm
LICENSE Add license Nov 4, 2015
META6.json
Makefile.in Fixes issues with lib name generation Jan 2, 2017
README.md Add some installation notes Sep 9, 2017
constant-helper.c Use constant helper to write out the stdlib library name Nov 21, 2015
fill-constants.pl
linenoise.c Add support for mod+d Oct 23, 2015
linenoise.h

README.md

Name

Linenoise

Author

Rob Hoelz

Synopsis

use Linenoise;

while (my $line = linenoise '> ').defined {
    say "got a line: $line";
}

Description

This module provides bindings to linenoise (https://github.com/antirez/linenoise) for Perl 6 via NativeCall.

Installation

You can install via zef:

$ zef install Linenoise

Note that since this module has binary components, you'll need a working C compiler. Everything you need can be found under the build-essential package on Debian-based Linux distributions, such as Ubuntu.

Examples

Basic History

use Linenoise;

my constant HIST_FILE = '.myhist';
my constant HIST_LEN  = 10;

linenoiseHistoryLoad(HIST_FILE);
linenoiseHistorySetMaxLen(HIST_LEN);

while (my $line = linenoise '> ').defined {
    linenoiseHistoryAdd($line);
    say "got a line: $line";
}

linenoiseHistorySave(HIST_FILE);

Tab Completion

use Linenoise;

my @commands = <help quit list get set>;

linenoiseSetCompletionCallback(-> $line, $c {
    my ( $prefix, $last-word ) = find-last-word($line);

    for @commands.grep(/^ "$last-word" /).sort -> $cmd {
        linenoiseAddCompletion($c, $prefix ~ $cmd);
    }
});

while (my $line = linenoise '> ').defined {
    say "got a line: $line";
}