Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(viewport): horizontal scroll #240

Merged

Conversation

tty2
Copy link
Contributor

@tty2 tty2 commented Sep 14, 2022

implement #235

@meowgorithm
Copy link
Member

meowgorithm commented Sep 14, 2022

Thanks for the PR! One immediate things is jumping out here:

len() counts bytes and not runes, which are not always the same. Similarly, some runes occupy two cells. For example:

// 3 bytes, 3 cells
Hi!

// 7 bytes, 5 cells:
世界!

So, in short, keep in mind that horizontal scrolling will need to handle double-width runes. Here’s a more in-depth example that breaks it down further:

https://go.dev/play/p/7lPoU2SMjn5

@tty2
Copy link
Contributor Author

tty2 commented Sep 14, 2022

Thanks for the PR! One immediate things is jumping out here:

len() counts bytes and not runes, which are not always the same. Similarly, some runes occupy two cells. For example:

// 3 bytes, 3 cells
Hi!

// 7 bytes, 5 cells:
世界!

So, in short, keep in mind that horizontal scrolling will need to handle double-width runes. Here’s a more in-depth example that breaks it down further:

https://go.dev/play/p/7lPoU2SMjn5

It's a good point. I guess I have to use lipgloss.Width here.

@tty2
Copy link
Contributor Author

tty2 commented Sep 15, 2022

Waiting for this PR merge and tagging.
Will continue after that.

@tty2
Copy link
Contributor Author

tty2 commented Sep 20, 2022

Don't merge it yet, please.
I'm gonna write some simple tests later this evening.

@tty2
Copy link
Contributor Author

tty2 commented Sep 20, 2022

Done!
@meowgorithm could you check it, please?
I can suppose that last test case (list: with y offset: horizontal scroll) can be too complicated. But I'm not sure it it's better to change it.
WDYT?

@meowgorithm
Copy link
Member

Thanks, @tty2. Before we get to this, do you mind adding some tests with double-width runes? That is going to be the number one thing we'll want to verify. In particular, cases where there's a mix of single and double width runes.

@tty2
Copy link
Contributor Author

tty2 commented Sep 20, 2022

These tests I've written inside go-runewidth library. For TruncateLeft function I use here.
But ok I'll write them here as well. I'll do it tomorrow.

@tty2
Copy link
Contributor Author

tty2 commented Sep 21, 2022

@meowgorithm
Done! Check the last test case.

@tty2
Copy link
Contributor Author

tty2 commented Sep 26, 2022

Hi, @meowgorithm
Should I change anything?

@meowgorithm
Copy link
Member

meowgorithm commented Sep 26, 2022

Hey, @tty2! Thanks for all your work on this so far. It's going to be a little bit of time until we can give this a proper review, but I promise we'll get to it.

@bobziuchkovski
Copy link

We'd absolutely love this functionality as well!

However, I tested this branch and found a potential issue: the rune trimming also trims color codes. The below are a series of screens showing horizontal scroll of a terraform plan that includes colored text:

Screenshot 2023-09-17 at 10 10 17 AM
Screenshot 2023-09-17 at 10 10 25 AM
Screenshot 2023-09-17 at 10 10 37 AM
Screenshot 2023-09-17 at 10 10 45 AM

@Sojamann Sojamann mentioned this pull request Sep 30, 2023
@kalensk
Copy link

kalensk commented May 24, 2024

It would be great to have this feature as well.

Copy link
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the only issue here is the truncation using rune width, ansi.Truncate should be a quick fix though!

if m.indent > 0 {
cutLines := make([]string, len(lines))
for i := range lines {
cutLines[i] = runewidth.TruncateLeft(lines[i], m.indent, "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably use ansi.Truncate so it doesn't trim escape codes as well...

https://pkg.go.dev/github.com/charmbracelet/x/ansi#Truncate

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a patch that does that and renames indent to XOffset to match YOffset

@tty2 tty2 force-pushed the feature/i236-viewport-horizontal-scroll branch from ba37376 to 143ea43 Compare December 14, 2024 18:03
@tty2 tty2 requested review from Caden64 and caarlos0 December 14, 2024 18:09
@tty2
Copy link
Contributor Author

tty2 commented Dec 14, 2024

@Caden64
Hey
Thanks for your ping via email. Sorry I haven't looked at this PR for years.
Thanks for providing your patch, it helped a lot but I used TuncateLeft that was implemented after, cause it was exactly we need here. I believe @caarlos0 mentioned it for help.
Hopefully it is what we need now.
Could you review it please?

@caarlos0
Copy link
Member

thanks @tty2!

I'll look into glamour and what's needed there, just to make sure we're not missing anything here. :)

@flavono123
Copy link

  • models in here should support this feature, such as table

@tty2
Copy link
Contributor Author

tty2 commented Dec 19, 2024

Hi @caarlos0
I fixed tests for viewport only yesterday.
I see you are going to look into other part of the lib.
Sorry, it's hard to recall everything after 2 years delay, but I'm sure that there was some flag before for the behavior you implemented here #240 (comment) .
And as I understand these changes break tests in table too.
I'm confused now.
In the initial issue #235 you can find that there was the way to prevent wrapping onto a new line (see screenshots).

@flavono123
Copy link

this change is not breaking the other models in the lib, for instance table, i guess.

a proper keymap and update implements are required to do this feature for them and this could be in another PR

@flavono123
Copy link

cannot wait this til next two years 😇 @meowgorithm @bashbunni are you mind to check this?

@meowgorithm
Copy link
Member

I hear you @flavono123. We're all on holiday through the new year but we'll pick this up after then. We've done an initial review internally, made some changes, and we intend to merge this.

@flavono123
Copy link

thanks got it. have a holy holiday

@meowgorithm
Copy link
Member

Alright, so I pushed a few changes to make the horizontal scroll API better match the rest of the API.

I think this is ready to go (the implementation is really good) although I'd love to figure out why it's breaking table tests first.

@caarlos0
Copy link
Member

caarlos0 commented Jan 6, 2025

Will take a look later

@caarlos0 caarlos0 merged commit 2d53a61 into charmbracelet:master Jan 10, 2025
26 checks passed
@meowgorithm
Copy link
Member

Thanks for the PR, @tty2, and for the discourse, @flavono123. This was a long time coming.

We expect to release this soon.

@bashbunni bashbunni linked an issue Jan 23, 2025 that may be closed by this pull request
@rdalbuquerque
Copy link

Hi Guys,
can we expect new features like this and #697 to be integrated with v2 alpha releases?

thank you all by all the amazing work btw!

@meowgorithm
Copy link
Member

@rdalbuquerque Yep, absolutely. We regularly merge new stuff on master into v2-exp. We plan to tag another v2 prerelease soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

viewport: horizontal scroll
10 participants