-
-
Notifications
You must be signed in to change notification settings - Fork 326
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(backend): add window size api #276
Conversation
Codecov Report
@@ Coverage Diff @@
## main #276 /- ##
==========================================
Coverage 89.25% 89.61% 0.36%
==========================================
Files 40 40
Lines 10767 10939 172
==========================================
Hits 9610 9803 193
Misses 1157 1136 -21
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite the commit message title in the convention commit style using imperative tone (e.g. feat(backend): add window_size_in_pixels() method
).
This is pretty close to being mergable (or will be once the crossterm PR is merged), so can you please rebase and squash your commits into a single commit and setup commit signing? See https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits for info.
Backend is woefully under-tested. I wonder if there's some way to fix that. |
* `sixel-bytes` encodes to `String` instead of file. * `serde` for `BackendType` for e.g. user configs. * `Send Sync` for threads/tokio. * `rustix::termios` to get window/font size until ratatui/crossterm get `window_size()`: [`ratatui::Backend::window_size()`](ratatui/ratatui#276) needs [`crossterm::terminal::window_size()`](crossterm-rs/crossterm#790).
* `sixel-bytes` encodes to `String` instead of file. * `serde` for `BackendType` for e.g. user configs. * `Send Sync` for threads/tokio. * `rustix::termios` to get window/font size until ratatui/crossterm get `window_size()`: [`ratatui::Backend::window_size()`](ratatui/ratatui#276) needs [`crossterm::terminal::window_size()`](crossterm-rs/crossterm#790).
* `sixel-bytes` encodes to `String` instead of file. * `serde` for `BackendType` for e.g. user configs. * `Send Sync` for threads/tokio. * `rustix::termios` to get window/font size until ratatui/crossterm get `window_size()`: [`ratatui::Backend::window_size()`](ratatui/ratatui#276) needs [`crossterm::terminal::window_size()`](crossterm-rs/crossterm#790).
6aaf325
to
7cacfcc
Compare
Regarding tests, I don't think it's really feasible to cover this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there was a mention of this not yet working with windows on crossterm if I read the linked issue right. Can you make sure to document this in the crossterm docs for the window_size method?
BTW, another PR upgraded crossterm 0.27 and brought in the changes to the error bits. Can you rebase this on main please? |
8601a65
to
5bb8543
Compare
I tried adding some test coverage for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think perhaps make this non-breaking with the existing size() and resize() continuing to take Rects? We can come back to that decision at a later date however.
Aiming for a 0.23.0 release after the weekend, so this should be in that if you can make the changes in time.
5001d14
to
0a4b51f
Compare
@joshka I toned this down to only adding the new It's cool if we can get this into the release, but it's not critical like the cell skipping, as the window pixel size can be queried outside of Some thoughts on In In general, I think it could be healthy to cut down a few public methods in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now. Thanks again. This seems like something we could merge before release. I'll flip it to the other maintainers to take a look.
Comments are non-blocking
For image (sixel, iTerm2, Kitty...) support that handles graphics in terms of `Rect` so that the image area can be included in layouts. For example: an image is loaded with a known pixel-size, and drawn, but the image protocol has no mechanism of knowing the actual cell/character area that been drawn on. It is then impossible to skip overdrawing the area. Returning the window size in pixel-width / pixel-height, together with colums / rows, it can be possible to account the pixel size of each cell / character, and then known the `Rect` of a given image, and also resize the image so that it fits exactly in a `Rect`. Crossterm and termwiz also both return both sizes from one syscall, while termion does two. Add a `Size` struct for the cases where a `Rect`'s `x`/`y` is unused (always zero). `Size` is not "clipped" for `area < u16::max_value()` like `Rect`. This is why there are `From` implementations between the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good ! Thanks for this !
I'll have to take a look at the image crate soon ! Exciting stuff.
@joshka what do you think about the scope of the conventional commit PR title ? let me know if anything else would be more suited. Thanks for all the review on this !
I think it's probably ok as is. Merging this now. Thanks again @benjajaja. This is going to lead to some fun apps. |
Depends on crossterm-rs/crossterm#790, and should update crossterm in an independent PR. Related to #215
For image (sixel, iTerm2, Kitty...) support that handles graphics in
terms of
Rect
so that the image area can be included in layouts.For example: an image is loaded with a known pixel-size, and drawn, but
the image protocol has no mechanism of knowing the actual cell/character
area that been drawn on. It is then impossible to skip overdrawing the
area.
Returning the window size in pixel-width / pixel-height, together with
colums / rows, it can be possible to account the pixel size of each cell
/ character, and then known the
Rect
of a given image, and also resizethe image so that it fits exactly in a
Rect
and avoid artifacts.