[haskeline] #78: control characters in prompt mess up width calculations

haskeline haskeline at projects.haskell.org
Fri Aug 20 22:26:43 EDT 2010

#78: control characters in prompt mess up width calculations
Reporter:  judah   |        Owner:     
    Type:  defect  |       Status:  new
Priority:  minor   |    Milestone:     
 Version:  0.6     |   Resolution:     
Keywords:          |  
Changes (by guest):

 * cc: lordrat at e-region.net (added)


 Example for colored `GHCi` prompt:

 :set prompt "\27[32;1m:mod +\27[0m %s\27[32;1m>\27[0m "

 And this one even sets window title:

 :set prompt "\27]0;GHCi: %s\7\27[32;1m:mod +\27[0m %s\27[32;1m>\27[0m "

 (`\[\]` nor `\SOH\STX` escaping was applied because neither of them works)

 And, as you might expect (as I'm writing here) they are not working ...
 properly `;-)`.
 (And it wasn't short way to find out why... I thought that
 `GHCi` is not properly handling things around libreadline... how big was
 surprise when I realized that there was no spoon`^W`libreadline...)

 I tried it this way:
 hunk ./System/Console/Haskeline/LineState.hs 109
  stringToGraphemes = mkString . dropWhile isCombiningChar
          mkString [] = []
 +        mkString ('\SOH':cs) = mkString (dropWhile (/='\STX') cs)
 +        mkString ('\STX':cs) = mkString cs
          mkString (c:cs) = Grapheme c (takeWhile isCombiningChar cs)
                                  : mkString (dropWhile isCombiningChar cs)
 but, as you see, it's nasty hack. However, I can't see simple and
 straightforward solution using current Grapheme approach (I tried another
 hack — prepending control sequence to next grapheme, but it had some
 issues(=wasn't working properly) too and there was unresolved special case
 — string containing nothing but escaped seqences... there was no grapheme
 to prepend it to...).

 I'm looking forward to any progress on this ticket `:-)`.

Ticket URL: <http://trac.haskell.org/haskeline/ticket/78#comment:6>
haskeline <http://example.org/>
My example project

More information about the Haskeline mailing list