App-AltSQL
view release on metacpan or search on metacpan
lib/App/AltSQL/Term.pm view on Meta::CPAN
package App::AltSQL::Term;
use Moose;
use Term::ReadLine::Zoid;
use Data::Dumper;
use JSON qw(encode_json decode_json);
use Term::ANSIColor;
with 'App::AltSQL::Role';
with 'MooseX::Object::Pluggable';
has 'term' => (
is => 'ro',
lazy_build => 1,
);
has 'prompt' => (
is => 'rw',
default => 'altsql> ',
);
has 'history_fn' => ( is => 'ro' );
has 'autocomplete_entries' => ( is => 'rw' );
sub args_spec {
return (
history_fn => {
cli => 'history=s',
default => $ENV{HOME} . '/.altsql_history.js',
help => '--history FILENAME',
},
);
}
sub BUILD {
my $self = shift;
$self->log_info("Ctrl-C to reset the line; Ctrl-D to exit");
}
sub setup {
my $self = shift;
if (my $custom_prompt = $self->app->config->{prompt}) {
$self->prompt($custom_prompt);
}
}
sub _build_term {
my $self = shift;
my $term = Term::ReadLine::Zoid->new("altsql-shell");
$self->{term} = $term;
# Require the tab key to be hit twice before showing the list of autocomplete items
$term->Attribs->{autolist} = 0;
$term->Attribs->{completion_function} = sub {
$self->completion_function(@_);
};
$term->Attribs->{beat} = sub {
# Check on things in the background here; called every second there is no input from the user
};
$term->bindkey('^Z', sub {
# The Term::ReadLine::Zoid uses Term::ReadKey in 'raw' mode which disables all signals
# If we can find a way to background ourselves at this point, that's the only option that I can see
$self->log_info("Backgrounding is not currently possible");
( run in 0.726 second using v1.01-cache-2.11-cpan-39bf76dae61 )