wl-copy / wl-paste
wardlib.app.wlcopy is a thin wrapper around Wayland clipboard tools:
wl-copywl-paste
This module constructs
ward.process.cmd(...)invocations; it does not parse output. consumers can usewardlib.tools.out(or their own parsing) on the:output()result.
Notes:
wl-copyreads data from stdin. This module only builds the command; feeding stdin is the caller’s responsibility.- Use
wardlib.tools.outif you want predictable parsing ofwl-pasteoutput.
Import
local Clipboard = require("wardlib.app.wlcopy").Clipboard
API
Clipboard.copy(opts)
Builds: wl-copy <opts...>
Clipboard.clear(opts)
Convenience: Clipboard.copy({ clear = true, selection = ... }).
Clipboard.paste(opts)
Builds: wl-paste <opts...>
Options
ClipboardSelectionOpts
selection: "clipboard"|"primary"|nilnil/"clipboard"uses the default clipboard"primary"sets--primary
ClipboardCopyOpts (extends ClipboardSelectionOpts)
type: string?— MIME type (--type <mime>)foreground: boolean?—--foregroundpaste_once: boolean?—--paste-onceclear: boolean?—--clearextra: string[]?— extra argv appended
ClipboardPasteOpts (extends ClipboardSelectionOpts)
type: string?— MIME type (--type <mime>)no_newline: boolean?—--no-newlineextra: string[]?— extra argv appended
Examples
Copy from stdin (default clipboard)
local Clipboard = require("wardlib.app.wlcopy").Clipboard
-- wl-copy
local cmd = Clipboard.copy()
-- Example (pseudo; feeding stdin depends on your Ward build):
-- cmd:stdin("hello\n"):run()
Copy to primary selection, set MIME type
local Clipboard = require("wardlib.app.wlcopy").Clipboard
-- wl-copy --primary --type text/plain
local cmd = Clipboard.copy({ selection = "primary", type = "text/plain" })
Copy and keep wl-copy in foreground until paste
local Clipboard = require("wardlib.app.wlcopy").Clipboard
-- wl-copy --foreground
local cmd = Clipboard.copy({ foreground = true })
Paste (no trailing newline)
local Clipboard = require("wardlib.app.wlcopy").Clipboard
local out = require("wardlib.tools.out")
-- wl-paste --no-newline
local text = out.cmd(Clipboard.paste({ no_newline = true }))
:trim()
:line()
Clear selection
local Clipboard = require("wardlib.app.wlcopy").Clipboard
-- wl-copy --clear
local cmd = Clipboard.clear()
-- wl-copy --primary --clear
local cmd2 = Clipboard.clear({ selection = "primary" })
Extra flags pass-through
local Clipboard = require("wardlib.app.wlcopy").Clipboard
-- Example: wl-paste --primary --type text/plain --watch
local cmd = Clipboard.paste({
selection = "primary",
type = "text/plain",
extra = { "--watch" }, -- if supported by your wl-paste build
})