A Nim clipboard library.
libclip
is a cross-platform Nim library for reading text from the clipboard and writing text to the clipboard.
# install:
$ nimble install libclip
# remove:
$ nimble uninstall libclip
To install the latest development version:
# install:
$ nimble install "https://github.com/jabbalaci/libclip@#head"
# remove:
$ nimble uninstall "https://github.com/jabbalaci/libclip@#head"
After importing libclip/clipboard
, you get two
functions:
# copy text to clipboard
proc setClipboardText(text: string): bool
# read text from clipboard
proc getClipboardText(): string
import strformat
import libclip/clipboard
proc main() =
let text = "hello nim"
let backup = getClipboardText()
#
echo &"Original content of the clipboard: '{backup}'"
echo "---"
echo &"Writing the following text to the clipboard: '{text}'"
discard setClipboardText(text)
let content = getClipboardText()
echo &"Current content of the clipboard: '{content}'"
#
echo &"Restoring the original content of the clipboard: '{backup}'"
if setClipboardText(backup):
echo "# success"
else:
echo "# failed"
# ########################################
when isMainModule:
main()
It was tested under Linux and Windows. Under Linux
you must have the command xsel
(install it with your
package manager).
I also added MacOS support, but I couldn't try it.
Please send me a feedback if it works under Mac.
Under Mac you must have the programs pbcopy
and
pbpaste
.
This clipboard library was extracted from my larger NimPyKot library.