Module: Clipboard::Linux

Extended by:
Linux
Includes:
Implementation
Included in:
Linux
Defined in:
lib/clipboard/linux.rb

Constant Summary collapse

CLIPBOARDS =
%w[clipboard primary secondary].freeze
WRITE_COMMAND =
'xclip'
READ_COMMAND =
'xclip -o'
READ_OUTPUT_STREAM =
false
SELECTION =
proc{ |x|
  "-selection #{x}"
}.freeze

Instance Method Summary collapse

Methods included from Implementation

#clear

Instance Method Details

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



44
45
46
47
48
49
50
51
52
53
# File 'lib/clipboard/linux.rb', line 44

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

    Utils.popen "#{WRITE_COMMAND} #{SELECTION[selection]}", data, READ_OUTPUT_STREAM
  }

  true
end

#paste(which = nil, clipboard: "clipboard") ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
# File 'lib/clipboard/linux.rb', line 37

def paste(which = nil, clipboard: "clipboard")
  selection = which || clipboard
  raise ArgumentError, "unknown clipboard selection" unless CLIPBOARDS.include?(selection)

  `#{READ_COMMAND} #{SELECTION[selection]} 2> /dev/null`
end