Skip Menu |

This queue is for tickets about the Term-ReadLine-Perl CPAN distribution.

Report information
The Basics
Id: 53792
Status: open
Priority: 0/
Queue: Term-ReadLine-Perl

People
Owner: Nobody in particular
Requestors: roland [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.0303
Fixed in: (no value)



Subject: Prompt with colors gets messed up
Using ANSI Colors in a prompt messes up the display as it seems that the for the internal prompt length calculation the ANSI control codes are not ignored. PERL_RL="Perl o=0" perl -MTerm::ReadLine -MTerm::ANSIColor=YELLOW,RESET -e 'new Term::ReadLine()->readline(YELLOW . "H" . RESET . "ell" . YELLOW . "o" . RESET . " : ")' which gives looks like in the attachted screenshot.
Subject: screenshot.png
Download screenshot.png
image/png 39.5k
screenshot.png
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Mon, 18 Jan 2010 14:08:23 -0800
To: Roland Huss via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Mon, Jan 18, 2010 at 07:37:43AM -0500, Roland Huss via RT wrote: Show quoted text
> Mon Jan 18 07:37:40 2010: Request 53792 was acted upon. > Transaction: Ticket created by ROLAND > Queue: Term-ReadLine-Perl > Subject: Prompt with colors gets messed up > Broken in: 1.0303 > Severity: (no value) > Owner: Nobody > Requestors: roland@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=53792 > > > > Using ANSI Colors in a prompt messes up the display as it seems that the for the internal > prompt length calculation the ANSI control codes are not ignored. > > PERL_RL="Perl o=0" perl -MTerm::ReadLine -MTerm::ANSIColor=YELLOW,RESET -e 'new > Term::ReadLine()->readline(YELLOW . "H" . RESET . "ell" . YELLOW . "o" . RESET . " : ")' > > which gives looks like in the attachted screenshot.
Behaves as expected. (But improvements welcome.) Yours, Ilya
Show quoted text
> Behaves as expected. (But improvements welcome.)
You probably mean 'works as designed' ? Frankly, I would have expected something different (i.e. taking into account 'invisible' character combinations like ANSI Escape sequences in the prompt when redisplaying). Please don't get me wrong, I really love Term::ReadLine::Perl for it's painless multiplatform support (everyboy trying to install Term::ReadLine::Gnu on a stock OS X can confirm this) and I'm consistently surprised about the feature richness of Term::ReadLine::Perl. Chapeu ! And in fact, I looked into the code before opening this ticket but thought you are closer to it as it seems that the code carries quite some 'historical baggage'. (i.e. because you did a release recently) Nevertheless, your answer is clear and I will try to find a patch if I get into it. In the meantime I disable prompt-coloring when using Term::ReadLine::Perl and enable it for Term:ReadLine::Gnu for which prompt-coloring works unexpectedly ;-) Thanks again for this cool module. You can close the ticket, I would then open a new one in case I have a patch.
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Tue, 19 Jan 2010 07:11:15 -0800
To: Roland Huss via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Tue, Jan 19, 2010 at 10:04:16AM -0500, Roland Huss via RT wrote: Show quoted text
> > Behaves as expected. (But improvements welcome.)
> > You probably mean 'works as designed' ? Frankly, I would have > expected something different
Probably, you never used any `readline' package? Show quoted text
> Nevertheless, your answer is clear and I will try to find a patch if I get into it.
Do not forget to look into the "detailed" docs of xterm (available in the distribution) to see what can of worms it is... Show quoted text
> In the meantime I disable prompt-coloring when using Term::ReadLine::Perl > and enable it for Term:ReadLine::Gnu for which prompt-coloring works unexpectedly ;-)
Hmm, interesting... Do not think it was there recently (e.g., 10 years ago...). This changes things. Yours, Ilya
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Tue, 19 Jan 2010 07:14:32 -0800
To: Roland Huss via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Tue, Jan 19, 2010 at 10:04:16AM -0500, Roland Huss via RT wrote: Show quoted text
> In the meantime I disable prompt-coloring when using Term::ReadLine::Perl > and enable it for Term:ReadLine::Gnu for which prompt-coloring works unexpectedly ;-)
What happens if you have multiline prompt, and edit multiline input so that part of prompt goes off screen? (This is a functional equivalent of "our" operation...) Ilya
For the notes, here's the similar screenshot for Term::ReadLine::Gnu For muti-line prompts, I will try it as well.
Subject: screenshot gnu.png
Download screenshot gnu.png
image/png 33.3k
screenshot gnu.png
Show quoted text
> What happens if you have multiline prompt, and edit multiline input so > that part of prompt goes off screen? (This is a functional equivalent > of "our" operation...)
Sorry, don't know exactly how to do this one. Multi line prompt, ok, but what is required to allow multi-line input. Any options ? Can't find it in the documentation of Term::ReadLine either. I guess, Term::ReadLine::Gnu use 'rl_expand_prompt' for proper prompt handling (though I didn't verify this). From the GNU Readline 6.1 documentation: Function: int rl_expand_prompt (char *prompt) Expand any special character sequences in prompt and set up the local Readline prompt redisplay variables. This function is called by readline(). It may also be called to expand the primary prompt if the rl_on_new_line_with_prompt() function or rl_already_prompted variable is used. It returns the number of visible characters on the last line of the (possibly multi-line) prompt. Applications may indicate that the prompt contains characters that take up no physical screen space when displayed by bracketing a sequence of such characters with the special markers RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE (declared in `readline.h'. This may be used to embed terminal-specific escape sequences in prompts.
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Tue, 19 Jan 2010 14:00:30 -0800
To: Roland Huss via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Tue, Jan 19, 2010 at 10:51:01AM -0500, Roland Huss via RT wrote: Show quoted text
> Sorry, don't know exactly how to do this one. Multi line prompt, ok, but what > is required to allow multi-line input.
With GNU, just enter quoted C-j... Show quoted text
> Function: int rl_expand_prompt (char *prompt) > Expand any special character sequences in prompt and set up the local Readline prompt > redisplay variables. This function is called by readline(). It may also be called to expand the > primary prompt if the rl_on_new_line_with_prompt() function or rl_already_prompted variable > is used. It returns the number of visible characters on the last line of the (possibly multi-line) > prompt. Applications may indicate that the prompt contains characters that take up no > physical screen space when displayed by bracketing a sequence of such characters with the > special markers RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE (declared in > `readline.h'. This may be used to embed terminal-specific escape sequences in prompts.
I see. So it is as it always was: there is no support for color-escapes (except for manually bracketing them). How would one find RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE through Term::ReadLine? Yours, Ilya
On Tue Jan 19 17:01:07 2010, nospam-abuse@ilyaz.org wrote: Show quoted text
> > Sorry, don't know exactly how to do this one. Multi line prompt, ok,
> but what
> > is required to allow multi-line input.
> > With GNU, just enter quoted C-j...
For bash this works, but using Term::ReadLine::GNU, I get [osgish] : "Bla Blub need closing quote ["] at char 0: "Bla Blub ^ [osgish] : Show quoted text
> [...]
> > physical screen space when displayed by bracketing a sequence of
> such characters with the
> > special markers RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE
> (declared in
> > `readline.h'. This may be used to embed terminal-specific escape
> sequences in prompts. > > I see. So it is as it always was: there is no support for > color-escapes (except for manually bracketing them). How would one > find RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE through > Term::ReadLine?
Actually I wouldn't mind to put the burden on the user. I.e. she is responsible for mixing in the proper escapes when setting the prompt. Special control characters are interpreted by the backend, which by coincidence could be the same for Term::ReadLine::Gnu and Term::ReadLine::Perl. The frontend Term::ReadLine itself is agnostic to the content of the prompt (as it always was). Alternatively, Term::ReadLine could provide constants on its own (to be respected by the backend) but I guess, this is out of scope as Term::ReadLine is bundled with Perl itself. And in fact, Term::ReadLine::Gnu isn't that smart as I thought first. Color prompting without escaping as described above seems to work, but if one uses the history and comes across an entry which is longer than the prompt itself, then the display gets messed up, too (an additonal length($prompt) offset for the input). However, when I manually put in the escapes as described above ("\01" . YELLOW . "\02") everything works smoothely so far (except that I still wasn't able to check multiline input). bye ... ... roland
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Wed, 20 Jan 2010 14:23:22 -0800
To: Roland Huss via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Wed, Jan 20, 2010 at 03:45:24AM -0500, Roland Huss via RT wrote: Show quoted text
> Actually I wouldn't mind to put the burden on the user. I.e. she is responsible > for mixing in the proper escapes when setting the prompt.
My question was: how would user find the bracketing characters using (only) the Term::Readline interface? (So that user's code has a chance to work with different backends...) Yours, Ilya
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Wed, 20 Jan 2010 15:33:03 -0800
To: Ilya Zakharevich via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Wed, Jan 20, 2010 at 05:23:43PM -0500, Ilya Zakharevich via RT wrote: Show quoted text
> Queue: Term-ReadLine-Perl > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=53792 > > > On Wed, Jan 20, 2010 at 03:45:24AM -0500, Roland Huss via RT wrote:
> > Actually I wouldn't mind to put the burden on the user. I.e. she is responsible > > for mixing in the proper escapes when setting the prompt.
> > My question was: how would user find the bracketing characters using > (only) the Term::Readline interface? (So that user's code has a > chance to work with different backends...)
In fact, having 2 bracketing characters would not work with TRlP. The prompt may be substr()inged; so we need "0-length stuff which sticks left" (as in "end highlighting"), and "0-length stuff which sticks right" (as in "start highlighting"). Yours, Ilya
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Wed, 20 Jan 2010 16:18:35 -0800
To: Ilya Zakharevich via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Wed, Jan 20, 2010 at 06:33:28PM -0500, Ilya Zakharevich via RT wrote: Show quoted text
> > My question was: how would user find the bracketing characters using > > (only) the Term::Readline interface? (So that user's code has a > > chance to work with different backends...)
> > In fact, having 2 bracketing characters would not work with TRlP. The > prompt may be substr()inged; so we need "0-length stuff which sticks > left" (as in "end highlighting"), and "0-length stuff which sticks > right" (as in "start highlighting").
Thinking yet more: still not enough. 0-length stuff cmay control out-of-band information (such as xterm's title, xterm's readline-mousing etc). On the other hand, I can't invent a situation when leaving ALL 0-length stuff, and cutting out "only printable substrings" would hurt the display (all for the cases we need to substr()ing the prompt...). Ilya
On Wed Jan 20 17:23:42 2010, nospam-abuse@ilyaz.org wrote: Show quoted text
> On Wed, Jan 20, 2010 at 03:45:24AM -0500, Roland Huss via RT wrote:
> > Actually I wouldn't mind to put the burden on the user. I.e. she is
> responsible
> > for mixing in the proper escapes when setting the prompt.
> > My question was: how would user find the bracketing characters using > (only) the Term::Readline interface? (So that user's code has a > chance to work with different backends...)
You are right, that the perfect solution where a user can semantically manage an *already* set RL prompt is really a heroic task (as you give in your examples). My assumption however was that for by far the most use cases the user is in complete control of the prompt and only sets this in TRl and never read it back. Within this model, he can prepare the prompt in a concise form for the specific backend in use. He is also responsible for the proper bracket alignment and can decided on it's own, which characters should be of 0-length. In my naive view, a TRl backend only needs to take into account the markers and rely on a proper alignment as set by the client. The backend, though, needs to keep track about the brackets. If I understand right, you suggest to keep two copies of the prompt, the original one and a 'clean' version on which text manipulations are done. The challenge here is to keep track between the corresponding printable characters in both versions of the prompt. But where, except for multi line prompts, do you need text manipulations for prompt handling ? (BTW, for multi-line prompts wouldn't it be nicer if Term::ReadLine::prompt() would be able to be called with an arrayref ?) Arghh. Never thought that terminal control is such a hard stuff. For sure, this discussion here increased my (even already high) respect for Term::ReadLine and its various backends ... ;-) Thanks a lot. ...roland
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Thu, 21 Jan 2010 04:10:10 -0800
To: Roland Huss via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Thu, Jan 21, 2010 at 04:32:23AM -0500, Roland Huss via RT wrote: Show quoted text
> Queue: Term-ReadLine-Perl > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=53792 > > > On Wed Jan 20 17:23:42 2010, nospam-abuse@ilyaz.org wrote:
> > On Wed, Jan 20, 2010 at 03:45:24AM -0500, Roland Huss via RT wrote:
> > > Actually I wouldn't mind to put the burden on the user. I.e. she is
> > responsible
> > > for mixing in the proper escapes when setting the prompt.
> > > > My question was: how would user find the bracketing characters using > > (only) the Term::Readline interface? (So that user's code has a > > chance to work with different backends...)
> > You are right, that the perfect solution where a user can semantically > manage an *already* set RL prompt is really a heroic task (as you give in your > examples). > > My assumption however was that for by far the most use cases the user is in > complete control of the prompt and only sets this in TRl and never read it back. > Within this model, he can prepare the prompt in a concise form for the specific backend in > use.
Sorry, but I have very little interest in this scenario. If TR::Gnu had provided an "only-through T::R solution" (i.e, not backend-cognizant), I might be interested to support it in TRP. But given that there is no pool of scripts which would suddently become more usable due to my efforts, it looks this becomes quite a theoretical exercise... Show quoted text
> The backend, though, needs to keep track about the brackets. If I understand right, you > suggest to keep two copies of the prompt, the original one and a 'clean' version on which > text manipulations are done.
I did not look in the code, but I think all I need is sub prompt_screen_width ($); sub prompt_substr_keep_all_0length_escapes($$$); Show quoted text
> printable characters in both versions of the prompt. But where, > except for multi line prompts, do you need text manipulations for > prompt handling ?
I recall that TRP does not use any fancy terminal escapes. Everything is shown on one line. As a corollary, prompt is shortened if too long for 1-line display. Yours, Ilya
Thanks for your efforts. For me the current situation is perfectly ok, I can live without a colored prompt in TRP (although it would be nice, too :) To avoid misunderstandings, by "user" I meant the 'user' of the module (i.e. a script), not the end-user (so, the script using TR has control over the prompt and 'owns' it. That's true at least for my own scripts). Thanks again, let me know, when I can help testing sth. Or maybe (but unlikely) I have time to dive into the control character hell, too ;)
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #53792] Prompt with colors gets messed up
Date: Thu, 21 Jan 2010 14:08:50 -0800
To: Roland Huss via RT <bug-Term-ReadLine-Perl [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Thu, Jan 21, 2010 at 07:25:52AM -0500, Roland Huss via RT wrote: Show quoted text
> Thanks for your efforts. For me the current situation is perfectly ok, I can live > without a colored prompt in TRP (although it would be nice, too :) > > To avoid misunderstandings, by "user" I meant the 'user' of the module (i.e. a script), > not the end-user (so, the script using TR has control over the prompt and 'owns' it. That's true > at least for my own scripts). > > Thanks again, let me know, when I can help testing sth. Or maybe (but unlikely) I have time to > dive into the control character hell, too ;)
Did you notice a loophole? If you make TR::Gnu announce "a Feature" presence, and make the bracketing chars available via Attribs, then things change. ;-) Yours, Ilya