peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.05k stars 132 forks source link

Word Wrap support? #18

Closed ghost closed 10 years ago

ghost commented 10 years ago

Hey,

Thanks for this plug in, we use it for some of our admin tools. It's brilliant! I was wondering if you guys had any plans to support word wrap. We sometimes have long strings of json that would be much easier to work with if it didn't trail off the screen.

Thanks! Jono

peterh commented 10 years ago

Thank you for the kind words.

There are no plans for word wrap at this time. It's a fair amount of work (twice, because Windows is so different from ANSI/ECMA-48/VT100), and long command lines are fairly niche. At least, I know that when I'm looking at a lengthy command line, I'm thinking of ways to change my program to make the commands shorter.

Another major point of trouble is: I can't think of a simple way to implement word wrap. In particular, it sounds like you would want "words" to be broken on "commas outside quotes", which isn't the same thing as the normal whitespace based word wrap. Also, what does Home/Ctrl-A or End/Ctrl-E do on a word wrapped line? Start/end of the buffer, or start/end of the current wrapped segment? Do Up/Down navigate within the wrapped line, or are they still history operators?

Then you'd have to make liner configurable, because the current scrolling behaviour is expected by current applications (and would have to be the default). I generally prefer not to add configuration knobs, and just have one set of functionality that is good enough.

All that said, "you guys" includes you; you could have said "us guys". If you can find a clean way to implement word wrap, I'd at least consider a pull request.

As an alternative suggestion, maybe there's something simpler we can do to help make it easier to work with long lines. Ctrl-Left and Ctrl-Right move the cursor left or right to the next whitespace. Perhaps something like Alt-Left and Alt-Right to move the cursor further (40 characters? 80 characters? Half a screen width? A whole screen width?) would help. What do you think?