App-Prima-REPL
view release on metacpan or search on metacpan
bin/prima-repl view on Meta::CPAN
);
# Add a notbook with output tab:
our $notebook = $window->insert(TabbedScrollNotebook =>
pack => { fill => 'both', expand => 1, padx => $padding, pady => $padding },
tabs => ['Output'],
style => tns::Simple,
);
our $output = $notebook->insert_to_page(0, Edit =>
pack => { fill => 'both', expand => 1, padx => $padding, pady => $padding },
text => '',
cursorWrap => 1,
wordWrap => 1,
readOnly => 1,
backColor => cl::LightGray,
font => { name => 'courier new'},
);
# Over-ride the defaults for these:
$output->accelTable->insert([
['', '', km::Ctrl | kb::PageUp, \&goto_prev_page ] # previous
, ['', '', km::Ctrl | kb::PageDown, \&goto_next_page ] # next
bin/prima-repl view on Meta::CPAN
unless eval{$widget->isa("Prima::Edit")};
# Allow for insertions, deletions, newlines, etc
$widget->set(
tabIndent => 4,
syntaxHilite => 1,
wantTabs => 1,
wantReturns => 1,
wordWrap => 0,
autoIndent => 1,
cursorWrap => 1,
font => { pitch => fp::Fixed, style => fs::Bold, name => 'courier new'},
);
# Update the accelerators.
my $accTable = $widget->accelTable;
# Add some functions to the accelerator table
$accTable->insert([
# Ctrl-Enter runs the file
['CtrlReturn', '', kb::Return | km::Ctrl, sub{main::run_file()} ]
bin/prima-repl view on Meta::CPAN
# Output handling and mangling #
################################
# Set autoflush on stdout:
$|++;
# Useful function to simulate user input. This is useful for initialization
# scripts when you want to run commands and put them into the command history
sub REPL::simulate_run {
my $command = shift;
# Get the current content of the inline and cursor position:
my $old_text = $inline->text;
my $old_offset = $inline->charOffset;
# Set the content to the new command:
$inline->text($command);
# run it:
$inline->PressEnter();
# put the original content back on the inline:
$inline->text($old_text);
$inline->charOffset($old_offset);
}
bin/prima-repl view on Meta::CPAN
$output_column += length($_);
}
}
# close the logfile:
close $logfile;
# Let the application update itself:
$::application->yield;
# I'm not super-enthused with manually putting the cursor at the end of
# the text, or with forcing the scrolling. I'd like to have some way to
# determine if the text was already at the bottom, in which case I would
# continue scrolling, if it was not, I would not scroll. But, I cannot find
# how to do that at the moment, so it'll just force scroll with every
# printout. working here:
$output->cursor_cend;
}
###############################
# Tie STDOUT to Output window #
###############################
# Redirect standard output using this filehandle tie. Thanks to
# http://stackoverflow.com/questions/387702/how-can-i-hook-into-perls-print
# for this one.
package IO::OutWindow;
use base 'Tie::Handle';
bin/prima-repl view on Meta::CPAN
=head1 Basic Navigation
Before I launch into the tutorial, I want to cover some basic navigation to help
you quickly get around the REPL. The following keyboard shortcuts should be
helpful to you even as we get started:
Normal Keyboard Mac Laptop
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
lib/PrimaX/InputHistory.pm view on Meta::CPAN
}
# Set self's current line:
$self->{currentLine} = $line_number;
# Load the text using the Orcish Maneuver:
my $new_text = $self->currentRevisions->[$line_number]
//= $self->history->[-$line_number]; #/
$self->text($new_text);
# Put the cursor at the previous offset. However, if the previous offset
# was zero, put the cursor at the end of the line:
$self->charOffset($curr_offset || length($new_text));
return $line_number;
}
# Add a new notification_type for each of on_PressEnter and on_Evaluate. The
# first should be set with hooks that remove or modify any text that needs to be
# cleaned before the eval stage. In other words, if you want to define commands
# that do not parse as a function in Perl, add it as a hook under on_PressEnter.
# The best examples I can think of, which also serve to differentiate between
( run in 0.241 second using v1.01-cache-2.11-cpan-4d50c553e7e )