haskell / haskeline

A Haskell library for line input in command-line programs.
https://hackage.haskell.org/package/haskeline
BSD 3-Clause "New" or "Revised" License
221 stars 75 forks source link

alignment surprise when displaying tab-completions #114

Open aryairani opened 5 years ago

aryairani commented 5 years ago

image

I tried using ANSI sequences in the display field, but it threw off the alignment of the presented completions:

image

I naively tried inserting a call to stringToGraphemes in Completion.makeLines but realized that's a different sort of thing. What do you think about some way to strip out escape sequences or to provide a length directly?

judah commented 5 years ago

Using stringToGraphemes inside of makeLines seems like a reasonable workaround that would parallel how we handle prefixes. (Relevant link, though you may have already seen it: https://github.com/judah/haskeline/wiki/ControlSequencesInPrompt)

I think you could convert the display completions from strings to lists of graphemes, compute their lengths and pad and concatenate each line, then convert the lines back to strings right before outputting them. Did you run into problems with that approach?

aryairani commented 5 years ago

No; I gave up immediately when length . stringToGraphemes didn't give me what I wanted, but with this encouragement I will try again. :)

aryairani commented 5 years ago

I understand a little better now, but the ANSI sequences generated by ansi-terminal aren't bracketed by '\STX', so stringToGraphemes doesn't seem to help — is that right?

aryairani commented 5 years ago

I know the unformatted string (and consequently its length) when I construct the Completion, but it's not available at the point that we're ready to display it.