How to copy text to / from clipboard in Go?

Sandeep Raju Prabhakar

In my Go language command line application, I need the ability to copy certain snippets of text to the system clipboard using Go. Basically something like PyperClip, but for Go.

I'm looking for a platform agnostic solution! Any help would be great :)

VonC

One project (just for Windows and Mac) seems approaching what you want: atotto/clipboard.

Provide copying and pasting to the Clipboard for Go.

func ReadAll() (string, error)
func WriteAll(text string) error

Linux support is in this clipboard_linux.go class: a simple wrapper to xsel --output/input --clipboard system command.


Another approach: try and take advantage of third-party libraries, like GLFW:

a free, Open Source, multi-platform library for opening a window, creating an OpenGL context and managing input

Its Go wrapper glfw3 does provide a clipboard.go file, with supposedly multi-platform methods.

func (w *Window) SetClipboardString(str string)
func (w *Window) GetClipboardString() (string, error)

But that would be in the context of GLFW windows, not any shell window of course.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to copy text from a div to clipboard

From Dev

How to copy text from pentadactyl to system clipboard?

From Dev

How to copy text to Clipboard from TextField in Android

From Dev

Copy text from CardView to Clipboard

From Dev

How to copy HTML formatted text on to Clipboard from Google Chrome extension?

From Dev

How to copy text from command line to clipboard without using the mouse?

From Dev

How to copy all text in edited file from PuTTY to clipboard?

From Dev

How can I copy text from the chat to the clipboard in BlueJeans?

From Dev

How do I copy text from the program "screen" to my clipboard?

From Dev

Copy text from Αce editor to clipboard

From Dev

Copy text to clipboard from a JTextfield with press of a button

From Dev

copy text from WSL to windows clipboard

From Dev

Copy text from Αce editor to clipboard

From Dev

Android - Get text from clipboard whenever user copy to clipboard

From Java

How to copy text to clipboard in Vaadin without addon

From Java

How to copy text to clipboard/pasteboard with Swift

From Dev

how to copy selected text to the clipboard using javascript

From Dev

How Best to Copy Formatted Text Into Clipboard

From Dev

How to get content of a text file and copy it to clipboard?

From Dev

How can I copy the text of a Button in the clipboard?

From Dev

How to copy text to the clipboard when using Wayland?

From Dev

How to copy data in a text file to the clipboard?

From Dev

Copy text to Clipboard in MFC

From Dev

Copy to clipboard as plain text

From Dev

copy text in clipboard

From Dev

Autoselect text with clipboard copy

From Dev

Copy text and html to clipboard

From Dev

Copy text js to clipboard

From Dev

How to copy a image from clipboard in Python?

Related Related

  1. 1

    How to copy text from a div to clipboard

  2. 2

    How to copy text from pentadactyl to system clipboard?

  3. 3

    How to copy text to Clipboard from TextField in Android

  4. 4

    Copy text from CardView to Clipboard

  5. 5

    How to copy HTML formatted text on to Clipboard from Google Chrome extension?

  6. 6

    How to copy text from command line to clipboard without using the mouse?

  7. 7

    How to copy all text in edited file from PuTTY to clipboard?

  8. 8

    How can I copy text from the chat to the clipboard in BlueJeans?

  9. 9

    How do I copy text from the program "screen" to my clipboard?

  10. 10

    Copy text from Αce editor to clipboard

  11. 11

    Copy text to clipboard from a JTextfield with press of a button

  12. 12

    copy text from WSL to windows clipboard

  13. 13

    Copy text from Αce editor to clipboard

  14. 14

    Android - Get text from clipboard whenever user copy to clipboard

  15. 15

    How to copy text to clipboard in Vaadin without addon

  16. 16

    How to copy text to clipboard/pasteboard with Swift

  17. 17

    how to copy selected text to the clipboard using javascript

  18. 18

    How Best to Copy Formatted Text Into Clipboard

  19. 19

    How to get content of a text file and copy it to clipboard?

  20. 20

    How can I copy the text of a Button in the clipboard?

  21. 21

    How to copy text to the clipboard when using Wayland?

  22. 22

    How to copy data in a text file to the clipboard?

  23. 23

    Copy text to Clipboard in MFC

  24. 24

    Copy to clipboard as plain text

  25. 25

    copy text in clipboard

  26. 26

    Autoselect text with clipboard copy

  27. 27

    Copy text and html to clipboard

  28. 28

    Copy text js to clipboard

  29. 29

    How to copy a image from clipboard in Python?

HotTag

Archive