GDBUI

 view release on metacpan or  search on metacpan

lib/Term/GDBUI.pm  view on Meta::CPAN


=item token_chars

This argument specifies the characters that should be considered
tokens all by themselves.  For instance, if I pass
token_chars=>'=', then 'ab=123' would be parsed to ('ab', '=', '123').
Without token_chars, 'ab=123' remains a single string.

NOTE: you cannot change token_chars after the constructor has been
called!  The regexps that use it are compiled once (m//o).
Also, until the Gnu Readline library can accept "=[]," without
diving into an endless loop, we will not tell history expansion
to use token_chars (it uses " \t\n()<>;&|" by default).

=item display_summary_in_help

Usually it's easier to have the command's summary (desc) printed first,
then follow it with the documentation (doc).  However, if the doc
already contains its description (for instance, if you're reading it
from a podfile), you don't want the summary up there too.  Pass 0
to prevent printing the desc above the doc.  Defaults to 1.

=back

=cut

sub new
{
    my $type = shift;
    my %args = (
        app => $0,
        prompt => "$0> ",
        commands => undef,
        blank_repeats_cmd => 0,
		backslash_continues_command => 0,
        history_file => undef,
        history_max => 500,
        token_chars => '',
        keep_quotes => 0,
        debug_complete => 0,
        disable_history_expansion => 0,
        display_summary_in_help => 1,
        @_
    );

    my $self = {};
    bless $self, $type;

    $self->{done} = 0;

    $self->{parser} = Text::Shellwords::Cursor->new(
        token_chars => $args{token_chars},
        keep_quotes => $args{keep_quotes},
        debug => 0,
        error => sub { shift; $self->error(@_); },
        );

    # expand tildes in the history file
    if($args{history_file}) {
        $args{history_file} =~ s/^~([^\/]*)/$1?(getpwnam($1))[7]:
            $ENV{HOME}||$ENV{LOGDIR}||(getpwuid($>))[7]/e;
    }

    for(keys %args) {
        next if $_ eq 'app';    # this param is not a member
        $self->{$_} = $args{$_};
    }

    $self->{term} ||= new Term::ReadLine($args{'app'});
    $self->{term}->MinLine(0);  # manually call AddHistory

    my $attrs = $self->{term}->Attribs;
# there appear to be catastrophic bugs with history_word_delimiters
# it goes into an infinite loop when =,[] are in token_chars
    # $attrs->{history_word_delimiters} = " \t\n".$self->{token_chars};
    $attrs->{completion_function} = sub { completion_function($self, @_); };

    $self->{OUT} = $self->{term}->OUT || \*STDOUT;
    $self->{prevcmd} = "";  # cmd to run again if user hits return

    return $self;
}


=item process_a_cmd()

Prompts for and returns the results from a single command.
Returns undef if no command was called.

=cut

sub process_a_cmd
{
    my $self = shift;

    $self->{completeline} = "";
    my $OUT = $self->{'OUT'};

	my $rawline = "";
	for(;;) {
		my $prompt = $self->prompt();
		$prompt = $prompt->[length $rawline ? 1 : 0] if ref $prompt eq 'ARRAY';
		$prompt = $prompt->($self, $rawline) if ref $prompt eq 'CODE';
		my $newline = $self->{term}->readline($prompt);

		# EOF exits
		unless(defined $newline) {
			print $OUT "\n";
			$self->exit_requested(1);
			return undef;
		}

		my $continued = ($newline =~ s/\\$//);
		$rawline .= (length $rawline ? " " : "") . $newline;
		last unless $self->{backslash_continues_command} && $continued;
	} 

    # is it a blank line?
    if($rawline =~ /^\s*$/) {
        $rawline = $self->blank_line();
        return unless defined $rawline && $rawline !~ /^\s*$/;



( run in 2.390 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )