3 package Devel::REPL::Plugin::FancyPrompt;
5 use Devel::REPL::Plugin;
6 use namespace::autoclean;
8 has 'fancy_prompt' => (
11 # yes, this needs to be a double sub
15 sprintf 're.pl(%s):%03d%s> ',
16 $self->can('current_package') ? $self->current_package : 'main',
18 $self->can('line_depth') ? ':' . $self->line_depth : '';
23 has 'fancy_continuation_prompt' => (
24 is => 'rw', lazy => 1,
26 # yes, this needs to be a double sub
30 sprintf 're.pl(%s):%03d:%d* ',
31 $self->can('current_package') ? $self->current_package : 'main',
39 is => 'rw', lazy => 1, default => 0,
42 around 'prompt' => sub {
45 if ($self->can('line_depth') && $self->line_depth) {
46 return $self->fancy_continuation_prompt->($self);
49 return $self->fancy_prompt->($self);
53 before 'read' => sub {
55 $self->lines_read($self->lines_read + 1);
64 Devel::REPL::Plugin::FancyPrompt - facilitate user-defined prompts
70 my $repl = Devel::REPL->new;
71 $repl->load_plugin('MultiLine::PPI'); # for indent depth
72 $repl->load_plugin('Packages'); # for current package
73 $repl->load_plugin('FancyPrompt');
78 FancyPrompt helps you write your own prompts. The default fancy prompt resembles
79 C<irb>'s default prompt. The default C<fancy_prompt> looks like this:
81 re.pl(main):001:0> 2 + 2
84 C<re.pl> is a constant. C<main> is the current package. The first number is how
85 many lines have been read so far. The second number (only if you have a
86 C<MultiLine> plugin) is how deep you are; intuitively, your indent level. This
87 default can be implemented with:
89 $_REPL->fancy_prompt(sub {
91 sprintf 're.pl(%s):%03d%s> ',
92 $self->can('current_package') ? $self->current_package : 'main',
94 $self->can('line_depth') ? ':' . $self->line_depth : '';
97 C<current_package> is provided by L<Devel::REPL::Plugin::Packages> (which
98 tracks the current package). C<line_depth> is provided by a C<MultiLine> plugin
99 (probably C<MultiLine::PPI>).
101 You may also set a C<fancy_continuation_prompt>. The default is very similar to
102 C<fancy_prompt>'s default (except C<*> instead of C<< > >>).
110 Shawn M Moore, C<< <sartak at gmail dot com> >>
112 =head1 COPYRIGHT AND LICENSE
114 Copyright (C) 2007 by Shawn M Moore
116 This library is free software; you can redistribute it and/or modify
117 it under the same terms as Perl itself.