Skip to content

Commit

Permalink
changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Apr 14, 2024
1 parent e0a5c4d commit 762941c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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

0 comments on commit 762941c

Please sign in to comment.