No description
Find a file
Laszlo Szathmary 842e0863f3
Merge pull request #1 from gokrtrustly/patch-1
Update macos.nim so that it compiles
2025-09-08 14:19:14 +02:00
example initial commit 2025-02-13 21:04:19 +01:00
src/libclip Update macos.nim so that it compiles 2025-09-08 13:00:46 +02:00
tests initial commit 2025-02-13 21:04:19 +01:00
.gitignore initial commit 2025-02-13 21:04:19 +01:00
config.nims initial commit 2025-02-13 21:04:19 +01:00
libclip.nimble initial commit 2025-02-13 21:04:19 +01:00
LICENSE initial commit 2025-02-13 21:04:19 +01:00
Makefile initial commit 2025-02-13 21:04:19 +01:00
README.md README 2025-02-14 06:59:21 +01:00

libclip

A Nim clipboard library.

libclip is a cross-platform Nim library for reading text from the clipboard and writing text to the clipboard.

Installation

# 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"

Usage

After importing libclip/clipboard, you get two functions:

# copy text to clipboard
proc setClipboardText(text: string): bool

# read text from clipboard
proc getClipboardText(): string

Example

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()

Supported platforms

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.