walles / moar

Moar is a pager. It's designed to just do the right thing without any configuration.
Other
647 stars 18 forks source link

Word wrapping? #26

Closed xxxserxxx closed 3 years ago

xxxserxxx commented 3 years ago

Only because the README says moar is a drop-in replacement for less...

less wraps lines; moar does not, and I can't find a setting to make moar wrap lines. If I pipe files through fmt first, I can get wrapped lines, but then moar won't apply highlighting to STDIN data.

Is there a setting I'm missing to make moar wrap lines, rather than having to scroll horizontally to read long lines?

walles commented 3 years ago

There is no setting for wrapping lines, sorry.

Could you provide a use case for this? As in "when I try to view file X, it looks Y, and I would prefer Z"?

Personally I prefer scrolling right and left with the arrow keys, and I would like to understand in what situation you think that is not good enough.

xxxserxxx commented 3 years ago

There are a couple of reasons for scrolling. First, is compatibility with less, more, and other pagers, all of which wrap lines by default. It's therefore a principle of least surprise to have this behavior. However, the stronger reason is when paging README files, especially in conjunction with highlighting and markdown. Word wrapping is preferable when reading natural languages. While it isn't universal, markup languages often allow or encourage not using hard returns within paragraphs, so that the user's display output is respected when viewing and editing.

Right now, it's not possible to use moar with highlighting and get word wrapping, even using external tools like par or fmt, and highlighting is one of the advantages moar has over less and more. If word wrapping isn't a feature that you're interested in implementing, maybe switch to allow highlighting for piped input would be (although, frankly, this seems far more clunky).

Use-case-ish: When viewing READMEs and other natural-language, paragraphical text, lines are not readable without horizontally scrolling, and I'd prefer to have lines wrapped.

walles commented 3 years ago

A concrete example with a real-world example file would be very helpful!

xxxserxxx commented 3 years ago

The README from i3status-rust is not legible without a lot of horizontal scrolling under moar, but the markdown syntax highlighting is nice. Top is moar, below is less. less, by default, wraps long lines.

2020-10-26-150722_735x942_scrot

Note, less does not word wrap, which in this case would be preferable. However, any line wrapping would be great, even if it were a command line toggle.

Edit: file in github for reference, not my project.

walles commented 3 years ago

Wrapping code added, start with --wrap or toggle with w while running.

Here's what it looks like with and without line numbers.

The wrapping is pretty dumb, possibly dumber than in less, but it works, is located in one place and has tests so it should be easy to improve for anybody who feels like it.

Yes, I know this took some time.

wrapped-with-line-numbers wrapped-without-line-numbers
walles commented 3 years ago

And your example in https://github.com/walles/moar/issues/26#issuecomment-716795992 was excellent by the way @xxxserxxx.

walles commented 3 years ago

Now with word wrapping, note specifically how URLs are wrapped at /:

moar-wordwrapping