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 :)
Pasting Text from the ClipboardPress CTRL+V to paste what you just copied to the clipboard into the edit box at the insertion point where the cursor is. Press the keystroke to read the current line, INSERT+UP ARROW, to verify that it is there.
The Clipboard task pane holds many of the last images and text you copied or cut. Note: You can still do simple cut, copy, and paste the way you're used to, either by using the buttons on the ribbon or the keyboard shortcuts CTRL+X (Cut), CTRL+C (Copy), or CTRL+V (Paste).
To quickly copy selected text or images to the clipboard, use hotkeys Ctrl+C or Ctrl+Insert. These hotkeys work in all Windows programs. Alternatively, you can invoke a pop-up menu by right-clicking on the selected text, and then click Copy.
To do this, select the item you wish to copy to your PC clipboard, then click "Windows Clipboard". Now, you can right-click > Paste the copied text from clipboard into a document on your PC.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With