Scoop API

scoop:scoop.terminal:0.1.0

src/clipboard/copy.scoop

Selected production source · src/clipboard/copy.scoop

1package scoop.terminal.clipboard
3import scoop.io.encoding.Base64
4import scoop.terminal.Command
6/**
7 * Emits an OSC 52 clipboard-copy command with base64-encoded content and selected destinations.
8 * The terminal decides whether clipboard access is supported.
9 */
10public struct CopyToClipboard(
11 val content: Array<Byte>,
12 val destination: ClipboardSelection = ClipboardSelection.clipboard
13) : Command {
14 /**
15 * Writes this command's ANSI representation to the supplied writer without flushing it.
16 * Parameter validation happens before or during serialization.
17 */
18 public override fun writeAnsi(writer: TextWriter) {
19 val selected = destination.toString()
20 val encoded = Base64.Default.encode(content)
21 writer.write("\u001b]52;" + selected + ";" + encoded + "\u001b\\")
22 }
24 /**
25 * Convenience construction of clipboard commands from Unicode text.
26 */
27 public companion object {
28 /**
29 * Encodes text as UTF-8 for an OSC 52 clipboard-copy command.
30 */
31 public fun fromText(text: String,
32 destination: ClipboardSelection = ClipboardSelection.clipboard): CopyToClipboard =
33 CopyToClipboard(text.toByteArray(), destination)
34 }