Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/CopyText/TextCopy
A cross platform package to copy text to and from the clipboard.
https://github.com/CopyText/TextCopy
Last synced: 10 days ago
JSON representation
A cross platform package to copy text to and from the clipboard.
- Host: GitHub
- URL: https://github.com/CopyText/TextCopy
- Owner: CopyText
- License: mit
- Created: 2018-08-16T09:30:19.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-01T09:55:05.000Z (6 months ago)
- Last Synced: 2024-05-01T12:34:17.294Z (6 months ago)
- Language: C#
- Homepage:
- Size: 1.4 MB
- Stars: 478
- Watchers: 10
- Forks: 37
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.txt
Awesome Lists containing this project
- awesome-blazor - TextCopy - ![GitHub stars](https://img.shields.io/github/stars/CopyText/TextCopy?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/CopyText/TextCopy?style=flat-square&cacheSeconds=86400) A cross platform package to copy text to and from the clipboard. [Supports Blazor](https://github.com/CopyText/TextCopy#blazor-webassembly) via the [Clipboard Browser API](https://developer.mozilla.org/docs/Web/API/Clipboard). (Libraries & Extensions / Tools & Utilities)
README
# TextCopy
[![Build status](https://ci.appveyor.com/api/projects/status/35uq76nlt9tl6m3t/branch/master?svg=true)](https://ci.appveyor.com/project/SimonCropp/textcopy)
[![NuGet Status](https://img.shields.io/nuget/v/TextCopy.svg)](https://www.nuget.org/packages/TextCopy/)A cross platform package to copy text to and from the clipboard.
**See [Milestones](../../milestones?state=closed) for release notes.**
## NuGet package
https://nuget.org/packages/TextCopy/
## Usage
### SetTextAsync
```cs
await ClipboardService.SetTextAsync("Text to place in clipboard");
```
snippet source | anchor### SetText
```cs
ClipboardService.SetText("Text to place in clipboard");
```
snippet source | anchor### GetTextAsync
```cs
var text = await ClipboardService.GetTextAsync();
```
snippet source | anchor### GetText
```cs
var text = ClipboardService.GetText();
```
snippet source | anchor## Clearing The Clipboard
```cs
ClipboardService.SetText("");
```
snippet source | anchor
```cs
await ClipboardService.SetTextAsync("");
```
snippet source | anchor## Instance API
In addition to the above static API, there is an instance API exposed:
```cs
Clipboard clipboard = new();
clipboard.SetText("Text to place in clipboard");
```
snippet source | anchor### Dependency Injection
An instance of `Clipboard` can be injected into `IServiceCollection`:
```cs
serviceCollection.InjectClipboard();
```
snippet source | anchorThe instance should be injected by using `IClipboard`.
There is also a `InjectMockClipboard` that injects an instance of `MockClipboard` with all methods stubbed out.
## Supported on
* Windows with .NET Framework 4.6.1 and up
* Windows with .NET Core 2.0 and up
* Windows with Mono 5.0 and up
* OSX with .NET Core 2.0 and up
* OSX with Mono 5.20.1 and up
* Linux with .NET Core 2.0 and up
* Linux with Mono 5.20.1 and up
* Xamarin.Android 9.0 and up
* Xamarin.iOS 10.0 and up
* Blazor WebAssembly 6.0 and up## Blazor WebAssembly
Due to the dependency on `JSInterop` the static `ClipboardService` is not supported on Blazor.
Instead inject an `IClipboard`:
```cs
var builder = WebAssemblyHostBuilder.CreateDefault();
var serviceCollection = builder.Services;
serviceCollection.InjectClipboard();
builder.RootComponents.Add("app");
```
snippet source | anchorThen consume it:
```cs
public partial class IndexModel :
ComponentBase
{
[Inject]
public IClipboard Clipboard { get; set; }public string Content { get; set; }
public Task CopyTextToClipboard() =>
Clipboard.SetTextAsync(Content);public async Task ReadTextFromClipboard() =>
Content = await Clipboard.GetTextAsync();
}
```
snippet source | anchorBlazor support requires the browser APIs [clipboard.readText](https://caniuse.com/#feat=mdn-api_clipboard_readtext) and [clipboard.writeText](https://caniuse.com/#feat=mdn-api_clipboard_writetext).
## Linux
Linux uses [xsel](https://github.com/kfish/xsel) to access the clipboard. As such it needs to be installed and callable.
## Icon
[Clone](https://thenounproject.com/term/Clone/207435/) designed by [Wes Breazell](https://thenounproject.com/wes13/) from [The Noun Project](https://thenounproject.com).