From 762941c72af0316dc8647c526c91b7d464dfa99a Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 14 Apr 2024 15:14:20 +0100 Subject: [PATCH 1/2] changelog --- CHANGELOG.md | 7 +++++++ src/textual/app.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d60d5f76d..bd46bfca21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ 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 + +### Added + +- Added App.copy_to_clipboard + ## [0.56.4] - 2024-04-09 ### Fixed diff --git a/src/textual/app.py b/src/textual/app.py index 48ed9ea66b..7ed7275d0a 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -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]], From 2fcf88de537c0339be4f2667aec38d309ffdb149 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 14 Apr 2024 15:15:38 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd46bfca21..e60932a11d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added -- Added App.copy_to_clipboard +- Added `App.copy_to_clipboard` https://github.com/Textualize/textual/pull/4416 ## [0.56.4] - 2024-04-09