* Readline behavior with colored custom prompt
@ 2016-02-25 17:20 Matthew Keeter
2016-02-25 18:05 ` Mike Gran
2016-02-26 5:09 ` Nala Ginrut
0 siblings, 2 replies; 5+ messages in thread
From: Matthew Keeter @ 2016-02-25 17:20 UTC (permalink / raw)
To: guile-user
Hi all,
I’m seeing strange behavior with readline's interaction with ANSI codes.
Here’s a minimal sample script that reproduces the behavior:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-modules (system repl repl) (system repl common))
(use-modules (ice-9 readline))
(define (custom-prompt repl) "\x1b[34m :D > \x1b[0m")
(activate-readline)
(repl-default-option-set! 'prompt custom-prompt)
(start-repl)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Run this and you’ll get a Guile shell. Into that shell, type
'(1 2 3 4 5 6 7 8 9 10)
The final parenthesis will highlight a character midway through the string
(instead of the first parenthesis).
The same issues happen if you try to scroll through history: lines end up
overlapping in strange ways.
Removing the ANSI codes from custom-prompt resolves the issue, but I’d really
like to have a colored prompt and correct readline behavior.
Does anyone have any ideas?
Thanks,
Matt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Readline behavior with colored custom prompt
2016-02-25 17:20 Readline behavior with colored custom prompt Matthew Keeter
@ 2016-02-25 18:05 ` Mike Gran
2016-02-25 18:53 ` Matthew Keeter
2016-02-26 5:09 ` Nala Ginrut
1 sibling, 1 reply; 5+ messages in thread
From: Mike Gran @ 2016-02-25 18:05 UTC (permalink / raw)
To: Matthew Keeter, guile-user@gnu.org
On Thursday, February 25, 2016 9:21 AM, Matthew Keeter <matt.j.keeter@gmail.com> wrote:
>
>Run this and you’ll get a Guile shell. Into that shell, type
>
> '(1 2 3 4 5 6 7 8 9 10)
>
>The final parenthesis will highlight a character midway through the string
>(instead of the first parenthesis).
>
>The same issues happen if you try to scroll through history: lines end up
>overlapping in strange ways.
>
>Removing the ANSI codes from custom-prompt resolves the issue, but I’d really
>like to have a colored prompt and correct readline behavior.
>
>Does anyone have any ideas?
The conflict is likely between your codes and the bounce-parens functionality
of the readline prompt.
(readline-set! bounce-parens 0) should disable that functionality and make the
colored prompt work.
To get your escape sequences and bounce-parens working would probably require
more thinking...
-Mike
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Readline behavior with colored custom prompt
2016-02-25 18:05 ` Mike Gran
@ 2016-02-25 18:53 ` Matthew Keeter
2016-02-25 22:09 ` Matthew Keeter
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Keeter @ 2016-02-25 18:53 UTC (permalink / raw)
To: Mike Gran; +Cc: guile-user@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1537 bytes --]
I think the fundamental issue is incorrect prompt length calculation, since it’s not just bounce-parens:
even with that turned off, scrolling through history ends up printing weird mismatched lines.
Here’s a similar issue discussed in nodejs:
https://github.com/nodejs/node-v0.x-archive/issues/3860
Any suggestions where to look for prompt length calculations?
I flipped through guile-readline/readline.c but didn’t see any obvious places to apply a fix.
Thanks,
Matt
On Feb 25, 2016, at 1:05 PM, Mike Gran <spk121@yahoo.com> wrote:
>
>
>
> On Thursday, February 25, 2016 9:21 AM, Matthew Keeter <matt.j.keeter@gmail.com> wrote:
>
>>
>> Run this and you’ll get a Guile shell. Into that shell, type
>>
>> '(1 2 3 4 5 6 7 8 9 10)
>>
>> The final parenthesis will highlight a character midway through the string
>> (instead of the first parenthesis).
>>
>> The same issues happen if you try to scroll through history: lines end up
>> overlapping in strange ways.
>>
>> Removing the ANSI codes from custom-prompt resolves the issue, but I’d really
>> like to have a colored prompt and correct readline behavior.
>>
>> Does anyone have any ideas?
>
> The conflict is likely between your codes and the bounce-parens functionality
> of the readline prompt.
>
> (readline-set! bounce-parens 0) should disable that functionality and make the
> colored prompt work.
>
> To get your escape sequences and bounce-parens working would probably require
> more thinking...
>
> -Mike
[-- Attachment #2: Type: text/html, Size: 2165 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Readline behavior with colored custom prompt
2016-02-25 18:53 ` Matthew Keeter
@ 2016-02-25 22:09 ` Matthew Keeter
0 siblings, 0 replies; 5+ messages in thread
From: Matthew Keeter @ 2016-02-25 22:09 UTC (permalink / raw)
To: Mike Gran; +Cc: guile-user@gnu.org
[-- Attachment #1: Type: text/plain, Size: 2018 bytes --]
Figured it out, after a bit more searching – it’s purely due to readline's behavior.
readline obeys the magic characters \x01 and \x02, ignoring anything in between then
when calculating prompt length. Wrapping the escape sequences makes everything
behave correctly.
(similar bug: https://bugs.python.org/issue17337)
-Matt
On Feb 25, 2016, at 1:53 PM, Matthew Keeter <matt.j.keeter@gmail.com> wrote:
> I think the fundamental issue is incorrect prompt length calculation, since it’s not just bounce-parens:
> even with that turned off, scrolling through history ends up printing weird mismatched lines.
>
> Here’s a similar issue discussed in nodejs:
> https://github.com/nodejs/node-v0.x-archive/issues/3860
>
> Any suggestions where to look for prompt length calculations?
> I flipped through guile-readline/readline.c but didn’t see any obvious places to apply a fix.
>
> Thanks,
> Matt
>
> On Feb 25, 2016, at 1:05 PM, Mike Gran <spk121@yahoo.com> wrote:
>
>>
>>
>>
>> On Thursday, February 25, 2016 9:21 AM, Matthew Keeter <matt.j.keeter@gmail.com> wrote:
>>
>>>
>>> Run this and you’ll get a Guile shell. Into that shell, type
>>>
>>> '(1 2 3 4 5 6 7 8 9 10)
>>>
>>> The final parenthesis will highlight a character midway through the string
>>> (instead of the first parenthesis).
>>>
>>> The same issues happen if you try to scroll through history: lines end up
>>> overlapping in strange ways.
>>>
>>> Removing the ANSI codes from custom-prompt resolves the issue, but I’d really
>>> like to have a colored prompt and correct readline behavior.
>>>
>>> Does anyone have any ideas?
>>
>> The conflict is likely between your codes and the bounce-parens functionality
>> of the readline prompt.
>>
>> (readline-set! bounce-parens 0) should disable that functionality and make the
>> colored prompt work.
>>
>> To get your escape sequences and bounce-parens working would probably require
>> more thinking...
>>
>> -Mike
>
[-- Attachment #2: Type: text/html, Size: 3091 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Readline behavior with colored custom prompt
2016-02-25 17:20 Readline behavior with colored custom prompt Matthew Keeter
2016-02-25 18:05 ` Mike Gran
@ 2016-02-26 5:09 ` Nala Ginrut
1 sibling, 0 replies; 5+ messages in thread
From: Nala Ginrut @ 2016-02-26 5:09 UTC (permalink / raw)
To: Matthew Keeter; +Cc: guile-user
Are you looking for something like guile-colorized?
https://github.com/NalaGinrut/guile-colorized
On Thu, 2016-02-25 at 12:20 -0500, Matthew Keeter wrote:
> Hi all,
>
> I’m seeing strange behavior with readline's interaction with ANSI codes.
>
> Here’s a minimal sample script that reproduces the behavior:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (use-modules (system repl repl) (system repl common))
> (use-modules (ice-9 readline))
>
> (define (custom-prompt repl) "\x1b[34m :D > \x1b[0m")
>
> (activate-readline)
> (repl-default-option-set! 'prompt custom-prompt)
>
> (start-repl)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> Run this and you’ll get a Guile shell. Into that shell, type
>
> '(1 2 3 4 5 6 7 8 9 10)
>
> The final parenthesis will highlight a character midway through the string
> (instead of the first parenthesis).
>
> The same issues happen if you try to scroll through history: lines end up
> overlapping in strange ways.
>
> Removing the ANSI codes from custom-prompt resolves the issue, but I’d really
> like to have a colored prompt and correct readline behavior.
>
> Does anyone have any ideas?
>
> Thanks,
> Matt
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-26 5:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-25 17:20 Readline behavior with colored custom prompt Matthew Keeter
2016-02-25 18:05 ` Mike Gran
2016-02-25 18:53 ` Matthew Keeter
2016-02-25 22:09 ` Matthew Keeter
2016-02-26 5:09 ` Nala Ginrut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).