markbt / streampager

A pager for command output or large files
MIT License
45 stars 11 forks source link

add line wrapping #20

Closed markbt closed 4 years ago

markbt commented 4 years ago

This change rewrites the screen rendering algorithm to allow wrapping of lines. Lines can be wrapped at grapheme or word boundaries. The wrapping mode is controlled with the \ key.

markbt commented 4 years ago

I started using this today and it seems to work fine. Once I'm happy I haven't regressed anything, I'll merge it.

Any additional testing help appreciated.

quark-zju commented 4 years ago

The direct mode currently truncates lines unconditionally since that's easier to implement. Perhaps it can respond to the line wrapping too, or just enter the full screen mode if the user wants the wrapper behavior.

markbt commented 4 years ago

I was thinking that direct mode should default to showing things wrapped. It doesn't make much sense to show things unwrapped there as the user can't scroll to the right. Probably it needs a config option, and probably we need to start thinking about a proper config file for streampager.

quark-zju commented 4 years ago

Related to this. I wonder if we should make the text in the stderr panel wrapped by default. Internally, hintutil prints to there and some hints are quite long.

wez commented 4 years ago

Some thoughts:

I'd be hesitant to add a configuration file because the complexity increases disproportionately, but it depends on just many options you think you'll need to grow over time. If you think it will be super simple declarative stuff forever then serde/TOML are pretty easy.

However, I just started to move away from those in wezterm because I was feeling constrained when it came to eg: key assignments. I've switched to using lua and wrote some serde glue to keep it almost as simple as TOML to embed and map data to/from lua. This is likely overkill for a pager!

markbt commented 4 years ago

I actually prefer non-wrapping by default, with the ability to wrap if needed. When viewing logs with timestamps at the left they don't get broken up by the wrapped lines, and the graph view in hg/git log also doesn't get chopped up. But I can see I might be unusual there, which is why I think it'll need to be config.

The less option for defaulting to this is -S, but afaik there's no easy way to toggle it from within less, which is a shame.

I actually wanted to add config files precisely for keymapping, which is what I planned to work on after wrapping is wrapped up. What problems did you hit that required using lua? I was thinking a simple "key combo" -> "action" mapping would be sufficient.

wez commented 4 years ago

What problems did you hit that required using lua? I was thinking a simple "key combo" -> "action" mapping would be sufficient.

I kept wanting to use loops to emit bindings for numbers and function keys for jumping directly to tabs because it was a bit of a chore and repeaty to duplicate the lines.

I also wanted to allow defining a callback to allow more complex actions; eg: press a single key and have it spawn a set of windows/tabs to re-establish a preferred workspace layout.

sp doesn't seem likely to need either of these anytime soon so you're probably safe to skip lua :)

quark-zju commented 4 years ago

It's also not too difficult to implement some lisp-like language (with true lambda support, but no control flow call/cc) in pure Rust and integrate with pure Rust functions well. I have done that. I can make things more reusable if it's interesting.