[GHC] #9364: GHCi (or haskeline?) confused by non-single-width characters

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Keywords: linux, terminal, | Operating System: colour, color, prompt | Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: Other Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Hi, there's an issue in the GHCi prompt. To reproduce: 1. Do everything in Linux (I don't have other operating systems); I'm using a version of the gnome 2 gnome-terminal. 2. Use the following to colourise the prompt in GHCi: echo -e :set prompt '"\033[32;1m%s\033[34;1m>\033[0m "' >> ~/.ghc/ghci.conf 3. Import quite a few modules (say, 5 to 10 should be enough) 4. Give the prompt enough text that it wraps around. It's best if you start the text with -- so that it's a comment and doesn't produce any output. For example, say I entered "-- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", I now see the following: *Types Control.Monad.Writer Control.Monad Data.Functor Control.Applicative Data.Monoid> -- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb (do note that the first set of b's is located on the same line as the prompt, and the second is located under the prompt) 5. Press Enter. You should now see: *Types Control.Monad.Writer Control.Monad Data.Functor Control.Applicative Data.Monoid> -- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb *Types Control.Monad.Writer Control.Monad Data.Functor Control.Applicative Data.Monoid> 6. Press Ctrl-P or the up arrow key to select the previous history item. You will now see the following: *Types Control.Monad.Writer Control.Monad Data.Functor Control.Applicative Data.Monoid> -- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb *Types Control.Monad.Writer Control.Monad Data.Functor Control.Applicative Data.Monoid> -- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 7. Press Ctrl-A or the Home cursor key to go to the beginning of the text entry, and then type X. You will now see the last prompt to be: *Types Control.Monad.Writer Control.Monad Data.Functor Control.Applicative Data.Monoid> -- bbbbbbbbbbbbX-- bbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 8. If you press Enter, you will find out that prompt was actually (without line breaks): X-- bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb I tried resizing the terminal window to 45 chars to make the lines above shorter; I imported Data.Monoid and Data.Functor in a new GHCi. The prompt contained garbage, most likely badly wrapped escape codes. See attachment. As both likely are a single bug in disguise, I include both reports in this ticket. Creating a test case for whether things actually work in a terminal might be difficult, but creating test for whether things get wrapped correctly (and not testing how things work out in a terminal) should be simple if annoying. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: linux, terminal, Operating System: | colour, color, prompt Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Other | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cheater): * cc: cheater (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: linux, terminal, Operating System: | colour, color, prompt Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Other | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: 5850 Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cheater): * related: => 5850 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: linux, terminal, Operating System: | colour, color, prompt Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Other | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #5850 Differential Revisions: | -------------------------------------+------------------------------------- Changes (by cheater): * related: 5850 => #5850 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: linux, | terminal, colour, color, prompt Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #5850 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by joeljk13): Here's a more minimalistic way to see the first bug: To ~/.ghc/ghci.conf, add {{{ :set prompt "^[[0m^O" }}} which can be done with {{{ $ echo ":set prompt \"$(tput sgr 0)\"" >>~/.ghc/ghci.conf }}} Note that this prompt consists only of the terminal control sequence to reset any color, so effectively there should be no prompt at all. Then run ghci, type enough that it wraps to the next line, and press HOME. The cursor will move not to the very beginning of the line, as it should, but to column 4. I think the issue is simply that GHCi doesn't recognize terminal control sequences, and the fix would be to make it treat all terminal control sequences as width 0. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: linux, | terminal, colour, color, prompt Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #5850 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by cheater): Evan Laforge brought up the following fix on ghc-dev: ------------ Here's what I use: :set prompt "\ESC[46m\STX%s>\ESC[39;49m\STX " I believe \STX is a signal to haskeline for control sequences. Documentation is here: https://github.com/judah/haskeline/wiki/ControlSequencesInPrompt -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: wontfix | Keywords: linux, | terminal, colour, color, prompt Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #5850 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by cheater): * status: new => closed * resolution: => wontfix Comment: Because the \STX escape character works well for reaching the intended scenario, I am resolving this bug. The resolution comes from haskeline. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9364: GHCi (or haskeline?) confused by non-single-width characters -------------------------------------+------------------------------------- Reporter: cheater | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: linux, | terminal, colour, color, prompt Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #5850 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by cheater): * status: closed => new * resolution: wontfix => Comment: The issue persists for multi-line prompts. Here is the relevant report in Haskeline: https://github.com/judah/haskeline/issues/72 once this is fixed in Haskeline and this is merged into ghci, this and the bug does not exist for single or multiline prompts, this issue may be closed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9364#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC