rgwood / systemctl-tui

A fast, simple TUI for interacting with systemd services and their logs
MIT License
235 stars 5 forks source link

Prevent from scrolling past the bottom line in the logs #10

Open k0ral opened 10 months ago

k0ral commented 10 months ago

How to reproduce

Here's what systemctl-tui shows when first displaying the logs of, for example, the acpid service: image

Upon pressing <End> to scroll to bottom, here's what I get: image

It actually scrolled past the last log, and I have to scroll back up using <PageUp> to see the actual last (== oldest) log messages: image

Expected behavior

Scrolling to bottom should end-up with the last/oldest log message displayed at the bottom of the screen/widget, like this: image

Incidentally, pressing <PageDown> should also be a no-op if the last line is already displayed.

rgwood commented 8 months ago

I spent a little time trying to solve this, and... it's a bit tricky.

The crux of the problem is that because individual log messages can wrap onto multiple lines, I don't know how tall the rendered list is going to be ahead of time. And without that information, I don't know what the maximum scroll offset should be.

Can probably hack something together but I'm not sure what a robust solution in Ratatui would look like :thinking:

rgwood commented 7 months ago

Took another look at this. It seems like Ratatui just doesn't have a great solution for this right now. Relevant Ratatui RFCs: https://github.com/ratatui-org/ratatui/issues/293 https://github.com/ratatui-org/ratatui/issues/174

To fix this in the near future, we may need to handle text wrapping ourselves along these lines: https://github.com/ratatui-org/ratatui/issues/293#issuecomment-1617166104

It seems like the Ratatui folks want to use textwrap so that's worth a try.