Skip to content

Commit

Permalink
Merge pull request #5534 from Textualize/bump-2.0.0
Browse files Browse the repository at this point in the history
Bump 2.0.0
  • Loading branch information
willmcgugan authored Feb 16, 2025
2 parents 993ff75 + b28d7b3 commit 5e1aa4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased - 2025
## 2.0.0 - 2024-02-16

### Added

Expand Down Expand Up @@ -44,13 +44,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- OptionList no longer supports `Separator`, a separator may be specified with `None`
- Breaking change: OptionList no longer supports `Separator`, a separator may be specified with `None`
- Implemented smooth (pixel perfect) scrolling on supported terminals. Set `TEXTUAL_SMOOTH_SCROLL=0` to disable.

### Removed

- Removed `wrap` argument from OptionList (use CSS `text-wrap: nowrap; text-overflow: ellipses`)
- Removed `tooltip` argument from OptionList. Use `tooltip` attribute or `with_tooltip(...)` method.
- Breaking change: Removed `wrap` argument from OptionList (use CSS `text-wrap: nowrap; text-overflow: ellipses`)
- Breaking change: Removed `tooltip` argument from OptionList. Use `tooltip` attribute or `with_tooltip(...)` method.

## [1.0.0] - 2024-12-12

Expand Down
25 changes: 18 additions & 7 deletions docs/blog/posts/smooth-scrolling.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,38 @@ It isn't granular enough to know where the pointer is *within* a cell.

Until recently terminal apps couldn't do any better.
More granular mouse reporting is possible in the terminal; write the required escape sequence and mouse coordinates are reported in pixels rather than cells.

So why haven't TUIs been using this?

The problem is that we can't translate between pixel coordinates and cell coordinates without first knowing how many pixels are in a cell.
And in order to know that, we need to know the width and height of the terminal in *pixels*.
Unfortunately, that standard way to get the terminal size reports just cells.
The problem is that pixel coordinates are pretty much useless in TUIs unless we have some way of translating between pixel and cell coordinates.
Without that, we can never know which cell the user clicked on.

It's a trivial calculation, but we are missing a vital piece of information; the size of the terminal window in pixels.
If we had that, we could divide the pixel dimensions by the cell dimensions to calculate the pixels per cell.
Divide the pixel coordinates by *pixels per cell* and we have cell coordinates.

But the terminal reports its size in cells, and *not* pixels.
So we can't use granular mouse coordinates.

!!! question "What did people use pixel coordinate for?"

This does make we wonder what pixel reporting was ever used for in terminals.
Ping me on Discord if you know!


At least they didn't before [this extension](https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83) which reports the size of the terminal in cell *and* pixel coordinates.
At least we couldn't until [this recent extension](https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83) which reports the size of the terminal in cell *and* pixel coordinates.
Once we have both the mouse coordinates in pixels and the dimensions of the terminal in pixels, we can implement much smoother scrolling.

Let's see how this looks.

On the right we have smooth scrolling enabled, on the left is the default non-smooth scrolling:
On the left we have the default scrolling, on the right, Textual is using granular mouse coordinates.


| Default scrolling | Smooth scrolling |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| ![A TUI Scrollbar](../images/smooth-scroll/no-smooth-scroll.gif) | ![A TUI Scrollbar with smooth scrolling](../images/smooth-scroll/smooth-scroll.gif) |

Notice how much smoother the motion of the table is, now that it tracks the mouse cursor more accurately.
If you move the scrollbar quickly, you may not notice the difference.
But if you move slowly like you are searching for something, it is a respectable quality of life improvement.

If you have one of the terminals which support this feature[^2], and at least [Textual](https://github.com/textualize/textual/) 2.0.0 you will be able to see this in action.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "textual"
version = "1.0.0"
version = "2.0.0"
homepage = "https://github.com/Textualize/textual"
repository = "https://github.com/Textualize/textual"
documentation = "https://textual.textualize.io/"
Expand Down
3 changes: 2 additions & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,9 @@ def _delay_update(self, delay: float = 0.05) -> None:

def end_batch() -> None:
"""Re-enable updates, and refresh screen."""
self.screen.refresh()
self._end_batch()
if not self._batch_count:
self.screen.refresh()

self.set_timer(delay, end_batch, name="_delay_update")

Expand Down

0 comments on commit 5e1aa4d

Please sign in to comment.