Skip to content

Commit

Permalink
Merge branch 'main' into fix-datatable-prevent-crash-with-border-link
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Apr 15, 2024
2 parents 8e6a5a0 + bd8f748 commit 89f8323
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

## Fixed
### Fixed

- Fixed a crash in `DataTable` if you clicked a link in the border https://github.com/Textualize/textual/issues/4410

### Added

- Added `App.copy_to_clipboard` https://github.com/Textualize/textual/pull/4416

## [0.56.4] - 2024-04-09

### Fixed
Expand Down
7 changes: 3 additions & 4 deletions src/textual/_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@


def partition(
pred: Callable[[T], object], iterable: Iterable[T]
predicate: Callable[[T], object], iterable: Iterable[T]
) -> tuple[list[T], list[T]]:
"""Partition a sequence in to two list from a given predicate. The first list will contain
the values where the predicate is False, the second list will contain the remaining values.
Args:
pred: A callable that returns True or False for a given value.
predicate: A callable that returns True or False for a given value.
iterable: In Iterable of values.
Returns:
Expand All @@ -22,7 +22,6 @@ def partition(

result: tuple[list[T], list[T]] = ([], [])
appends = (result[0].append, result[1].append)

for value in iterable:
appends[1 if pred(value) else 0](value)
appends[1 if predicate(value) else 0](value)
return result
18 changes: 18 additions & 0 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,24 @@ def get_loading_widget(self) -> Widget:

return LoadingIndicator()

def copy_to_clipboard(self, text: str) -> None:
"""Copy text to the clipboard.
!!! note
This does not work on macOS Terminal, but will work on most other terminals.
Args:
text: Text you wish to copy to the clipboard.
"""
if self._driver is None:
return

import base64

base64_text = base64.b64encode(text.encode("utf-8")).decode("utf-8")
self._driver.write(f"\x1b]52;c;{base64_text}\a")

def call_from_thread(
self,
callback: Callable[..., CallThreadReturnType | Awaitable[CallThreadReturnType]],
Expand Down
4 changes: 2 additions & 2 deletions src/textual/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def describe_failure(self, failure: Failure) -> str | None:
A string description of the failure.
"""
if isinstance(failure, Number.NotANumber):
return f"Must be a valid number."
return "Must be a valid number."
elif isinstance(failure, Number.NotInRange):
if self.minimum is None and self.maximum is not None:
return f"Must be less than or equal to {self.maximum}."
Expand Down Expand Up @@ -364,7 +364,7 @@ def describe_failure(self, failure: Failure) -> str | None:
A string description of the failure.
"""
if isinstance(failure, Integer.NotAnInteger):
return f"Must be a valid integer."
return "Must be a valid integer."
elif isinstance(failure, Integer.NotInRange):
if self.minimum is None and self.maximum is not None:
return f"Must be less than or equal to {self.maximum}."
Expand Down

0 comments on commit 89f8323

Please sign in to comment.