Module: Clipboard::Osc52

Extended by:
Osc52
Includes:
Implementation
Included in:
Osc52
Defined in:
lib/clipboard/osc52.rb

Constant Summary collapse

CLIPBOARDS =
%w[clipboard primary].freeze
OSC52 =
"]52;%<selection_option>s;%<data_base64>s"

Instance Method Summary collapse

Methods included from Implementation

#paste

Instance Method Details

#clear(clipboard: "all") ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/clipboard/osc52.rb', line 27

def clear(clipboard: "all")
  selections = clipboard.to_s == "all" ? CLIPBOARDS : [clipboard]
  selections.each{ |selection|
    raise ArgumentError, "unknown clipboard selection" unless CLIPBOARDS.include?(selection)

    print OSC52 % {
      selection_option: selection == "primary" ? "p" : "c",
      data_base64: ?! # anything non-base64 / question mark clears
    }
  }

  true
end

#copy(data, clipboard: "all") ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/clipboard/osc52.rb', line 13

def copy(data, clipboard: "all")
  selections = clipboard.to_s == "all" ? CLIPBOARDS : [clipboard]
  selections.each{ |selection|
    raise ArgumentError, "unknown clipboard selection" unless CLIPBOARDS.include?(selection)

    print OSC52 % {
      selection_option: selection == "primary" ? "p" : "c",
      data_base64: [data].pack("m0"),
    }
  }

  true
end