Home > Archive > PERL POE > February 2007 > POE::Wheel::ReadLine change_prompt
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
POE::Wheel::ReadLine change_prompt
|
|
| Paul Miller 2007-02-06, 4:20 am |
| I'm using POE::Wheel::Run successfully and there's a situation where
my prompt should change dynamically. I couldn't find a way to do it
directly, but using the source I created this mess:
sub change_prompt {
my $heap = $_[HEAP];
my $arg0 = $_[ARG0];
EVIL_HACK: {
local $| = 1; print "\r", " " x (length $heap->{prompt}),
"\r";
$heap->{prompt} = $arg0;
$heap->{wheel}->[ $heap->{wheel}->SELF_PROMPT ] = $arg0;
$heap->{wheel}->_repaint_input_line;
}
}
First of all, is there a better, less internally hacky way to do
this? Second, if not, given that it seems like such a natural thing
to want to do; why isn't it already in there somewhere?
| |
| David Davis 2007-02-06, 7:17 pm |
| Did $heap->{wheel}->get( "prompt:" ); not work for you?
It's documented.
David
On 5 Feb 2007 13:35:13 -0800, Paul Miller <jettero@gmail.com> wrote:
>
> I'm using POE::Wheel::Run successfully and there's a situation where
> my prompt should change dynamically. I couldn't find a way to do it
> directly, but using the source I created this mess:
>
> sub change_prompt {
> my $heap = $_[HEAP];
> my $arg0 = $_[ARG0];
>
> EVIL_HACK: {
> local $| = 1; print "\r", " " x (length $heap->{prompt}),
> "\r";
>
> $heap->{prompt} = $arg0;
> $heap->{wheel}->[ $heap->{wheel}->SELF_PROMPT ] = $arg0;
> $heap->{wheel}->_repaint_input_line;
> }
> }
>
> First of all, is there a better, less internally hacky way to do
> this? Second, if not, given that it seems like such a natural thing
> to want to do; why isn't it already in there somewhere?
>
>
| |
| Paul Miller 2007-02-07, 7:17 pm |
| On Feb 5, 4:35 pm, jett...@gmail.com (Paul Miller) wrote:
> I'm using POE::Wheel::Run
For some reason, I always seem to type ::Run when I mean ::ReadLine.
| |
| Paul Miller 2007-02-07, 7:17 pm |
| Hrm, I wasn't very clear, sorry. By 'dynamically' I mean, not during
an
input routine. The prompt chaned somewhere else. get() doesn't do
anything
if the wheel is already getting, so it just ignores your prompt
change.
On Tue, Feb 06, 2007 at 11:47:57AM -0800, David Davis wrote:
> Did $heap->{wheel}->get( "prompt:" ); not work for you?
>
> It's documented.
>
> David
| |
| Rocco Caputo 2007-02-18, 4:15 am |
| On Feb 5, 2007, at 16:35, Paul Miller wrote:
> I'm using POE::Wheel::Run successfully and there's a situation where
> my prompt should change dynamically. I couldn't find a way to do it
> directly, but using the source I created this mess:
>
> sub change_prompt {
> my $heap = $_[HEAP];
> my $arg0 = $_[ARG0];
>
> EVIL_HACK: {
> local $| = 1; print "\r", " " x (length $heap->{prompt}),
> "\r";
>
> $heap->{prompt} = $arg0;
> $heap->{wheel}->[ $heap->{wheel}->SELF_PROMPT ] = $arg0;
> $heap->{wheel}->_repaint_input_line;
> }
> }
Wow, that DOES seem like an evil hack. I think I'd use _curs_left()
to move the cursor to the start of the line. Also your use of $_
[HEAP] and $_[ARG0] makes me wonder how you're calling this. How are
you calling this?
> First of all, is there a better, less internally hacky way to do
> this? Second, if not, given that it seems like such a natural thing
> to want to do; why isn't it already in there somewhere?
Or maybe I'd use _wipe_input_line() to erase the current input and
then _repaint_input_line() to repaint it after the prompt was changed.
Generally stuff like this isn't implemented because $you are the
first to need it. If you use some of the existing cursor movement or
command line painting functions instead, and you document this, I'll
commit it for the next release.
--
Rocco Caputo - rcaputo@pobox.com
|
|
|
|
|