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

haskeline haskeline at projects.haskell.org
Sat Aug 21 12:37:46 EDT 2010


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

  * owner:  => judah
  * status:  new => assigned

Comment:

 Thanks for your suggestions.  I originally balked at adding what's
 essentially a platform-specific hack; but you're both right that it's
 better to at least work with the above cases.  So I've applied the
 following patch:

 {{{
 Sat Aug 21 09:18:37 PDT 2010  Judah Jacobson <judah.jacobson at gmail.com>
   * #78: If "\ESC...\STX" or "\SOH\ESC...\STX" appears in the prompt,
 treat it as a zero-width grapheme.
     hunk ./System/Console/Haskeline/LineState.hs 109
     +        -- Minor hack: "\ESC...\STX" or "\SOH\ESC...\STX", where
 "\ESC..." is some
     +        -- control sequence (e.g., ANSI colors), is represented as a
 grapheme
     +        -- of zero length with '\ESC' as the base character.
     +        -- Note that this won't round-trip correctly with
 graphemesToString.
     +        -- In practice, however, that's fine since control characters
 can only occur
     +        -- in the prompt.
     +        mkString ('\SOH':cs) = stringToGraphemes cs
     +        mkString ('\ESC':cs) | (ctrl,'\STX':rest) <- break (=='\STX')
 cs
     +                    = Grapheme '\ESC' ctrl : stringToGraphemes rest
 }}}
 Please let me know if that doesn't work for you, or if the width
 calculations don't behave correctly.

 I'll document this on the wiki before releasing the next version.

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


More information about the Haskeline mailing list