3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/rage_flip/clipboard.rb', line 3
def self.copy(text)
case RUBY_PLATFORM
when /darwin/
system("echo #{text.shellescape} | pbcopy")
when /linux/
if system("which xclip > /dev/null 2>&1")
system("echo #{text.shellescape} | xclip -selection clipboard")
elsif system("which xsel > /dev/null 2>&1")
system("echo #{text.shellescape} | xsel --clipboard --input")
else
puts "Error: No clipboard utility found. Please install xclip or xsel."
return false
end
when /mswin|mingw|cygwin/
require 'tempfile'
Tempfile.create(['clipboard', '.txt'], binmode: true) do |temp_file|
utf16_text = "\uFEFF#{text}".encode('UTF-16LE')
temp_file.write(utf16_text)
temp_file.flush
system("clip < \"#{temp_file.path}\"")
end
else
puts "Error: Unsupported platform for clipboard operations."
return false
end
true
end
|