Git Product home page Git Product logo

textcopy's Introduction

TextCopy

  • AppVeyor: Build status
  • TravisCI: Build status
  • NuGet Status

A cross platform package to copy text to and from the clipboard.

NuGet package

https://nuget.org/packages/TextCopy/

Usage

SetTextAsync

await ClipboardService.SetTextAsync("Text to place in clipboard");

snippet source | anchor

SetText

ClipboardService.SetText("Text to place in clipboard");

snippet source | anchor

GetTextAsync

var text = await ClipboardService.GetTextAsync();

snippet source | anchor

GetText

var text = ClipboardService.GetText();

snippet source | anchor

Clearing The Clipboard

ClipboardService.SetText("");

snippet source | anchor

await ClipboardService.SetTextAsync("");

snippet source | anchor

Instance API

In addition to the above static API, there is an instance API exposed:

Clipboard clipboard = new();
clipboard.SetText("Text to place in clipboard");

snippet source | anchor

Dependency Injection

An instance of Clipboard can be injected into IServiceCollection:

serviceCollection.InjectClipboard();

snippet source | anchor

The 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
  • Universal Windows Platform version 10.0.16299 and up
  • Blazor WebAssembly 5.0 and up

Blazor WebAssembly

Due to the dependency on JSInterop the static ClipboardService is not supported on Blazor.

Instead inject an IClipboard:

var builder = WebAssemblyHostBuilder.CreateDefault();
var serviceCollection = builder.Services;
serviceCollection.InjectClipboard();
builder.RootComponents.Add<App>("app");

snippet source | anchor

Then consume it:

public partial class IndexModel :
    ComponentBase
{
    [Inject]
    public IClipboard Clipboard { get; set; }

    public string Content { get; set; }

    public Task CopyTextToClipboard()
    {
        return Clipboard.SetTextAsync(Content);
    }

    public async Task ReadTextFromClipboard()
    {
        Content = await Clipboard.GetTextAsync();
    }
}

snippet source | anchor

Blazor support requires the browser APIs clipboard.readText and clipboard.writeText.

Linux

Linux uses xsel to access the clipboard. As such it needs to be installed and callable.

Icon

Clone designed by Wes Breazell from The Noun Project.

textcopy's People

Contributors

dependabot-preview[bot] avatar simoncropp avatar dependabot[bot] avatar dependabot-support avatar actions-user avatar haikujock avatar mcon avatar aliwoto avatar cyberboss avatar rexcfnghk avatar duncanawoods avatar mfkl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.