App-Prima-REPL

 view release on metacpan or  search on metacpan

bin/prima-repl  view on Meta::CPAN

	}
	else {
		print "No initialization script found\n";
	}
}
redo_initrc if -f $initrc_filename or -f "$initrc_filename.pl";

run Prima;
# Remove the logfile. This will not happen with a system failure, which means
# that the logfile is 'saved' only when there was a problem. The special case of
# the user typing 'exit' at the prompt is handled in pressed_enter().
unlink 'prima-repl.logfile';

__END__

=head1 App::Prima::REPL Help

This is the help documentation for App::Prima::REPL, a graphical run-eval-print-loop
(REPL) for perl development, targeted at pdl users. Its focus is on L<PDL>, the
Perl Data Language, but it works just fine even if you don't have PDL.

bin/prima-repl  view on Meta::CPAN

 CTRL-h           CTRL-h        open or switch to the help window
 ALT-1            ??????        go to the output window
 CTRL-i           CTRL-i        put the cursor in the input line
 CTRL-PageUp      CTRL-FN-Up    go to the previous tab
 CTRL-PageDown    CTRL-FN-Down  go to the next tab

=head1 Tutorials

These are a collection of tutorials to get you started using the Prima REPL.
Except for the first tutorial, text that you should enter will be prefixed with
a prompt like C<< > >>.

=head2 Basic Output

Our first exercise will be getting basic output from the REPL. Enter the
following into the input line, but don't press enter yet:

 print "Hello!"

Take note of the last line of text in the output window, then press enter.
You should see the following appear on your output screen:

lib/PrimaX/InputHistory.pm  view on Meta::CPAN

		# Enter runs the line
		, ['Run', 'Return', kb::Return, sub {$_[0]->PressEnter}]
		, ['Run', 'Enter', kb::Enter, sub {$_[0]->PressEnter}]
	);

	return {
		%def,
		pageLines => 10,		# lines to 'scroll' with pageup/pagedown
		accelItems => \@acc,
		outputWidget => ih::StdOut,
		promptFormat => '> ',
		currentLine => 0,
		storeType => ih::All,
	}
}

# This stage initializes the inputline. I believe this is the appropriate stage
# for (1) setting the properties above (2) loading the history file data, and
# (3) connecting to the output widget.
sub init {
	my $self = shift;
	my %profile = $self->SUPER::init(@_);
	foreach ( qw(pageLines promptFormat currentLine outputWidget storeType) ) {
		$self->{$_} = $profile{$_};
	}
	
	# Store the history and revisions:
	$self->currentRevisions([]);
	$self->history([]);
	# history calls currentLine, so this doesn't need to be called:
	# $self->currentLine(0);
	
	# Set up the output widget. Perl scalars with text are not allowed:

lib/PrimaX/InputHistory.pm  view on Meta::CPAN

	# and go there
	$self->currentLine($line_number);
}

# The class properties. Template code for these was taken from Prima::Object's
# name example property code:
sub pageLines {
	return $_[0]->{pageLines} unless $#_;
	$_[0]->{pageLines} = $_[1];
}
sub promptFormat {
	return $_[0]->{promptFormat} unless $#_;
	$_[0]->{promptFormat} = $_[1];
}
sub outputWidget {
	return $_[0]->{outputWidget} unless $#_;
	$_[0]->{outputWidget} = $_[1];
}
sub history {
	return $_[0]->{history} unless $#_;
	$_[0]->{history} = $_[1];
	$_[0]->currentLine(0);
	return $_[1];

lib/PrimaX/InputHistory.pm  view on Meta::CPAN

sub on_pressenter {
	my ($self, $text) = @_;

	# Remove the endlines, if present, replacing them with safe whitespace:
	$text =~ s/\n/ /g;
	
	# Reset the current collection of revisions:
	$self->{currentRevisions} = [];
	
	# print this line:
	$self->outputWidget->newline_printout($self->promptFormat, $text, "\n");

	# We are about to add this text to the history. Before doing so, check if
	# the history needs to be modified before performing the add:
	if ($self->storeType == ih::NoRepeat
		and defined $self->history->[-1]
		and $self->history->[-1] eq $text
	) {
		# remove the previous entry if it's identical to this one:
		pop @{$self->history};
	}



( run in 0.565 second using v1.01-cache-2.11-cpan-6aa56a78535 )