Module: Clogs::Clipboard
- Defined in:
- lib/clogs/clipboard.rb
Overview
libui has no clipboard API at all, so Clogs shells out to whatever the platform provides. If nothing is available, copy and paste quietly do nothing rather than raising in the middle of someone's keystroke.
Class Method Summary collapse
Class Method Details
.read ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/clogs/clipboard.rb', line 10 def read cmd = read_command return @fallback.to_s unless cmd out = `#{cmd} 2>/dev/null` $?.success? ? out : @fallback.to_s rescue StandardError @fallback.to_s end |
.read_command ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/clogs/clipboard.rb', line 30 def read_command @read_command ||= case RUBY_PLATFORM when /darwin/ then "pbpaste" when /mingw|mswin/ then "powershell -command Get-Clipboard" else if system("which xclip > /dev/null 2>&1") "xclip -selection clipboard -o" elsif system("which xsel > /dev/null 2>&1") "xsel --clipboard --output" end end end |
.write(text) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/clogs/clipboard.rb', line 20 def write(text) @fallback = text cmd = write_command return unless cmd IO.popen(cmd, "w") { |io| io.write(text) } rescue StandardError nil end |
.write_command ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/clogs/clipboard.rb', line 43 def write_command @write_command ||= case RUBY_PLATFORM when /darwin/ then "pbcopy" when /mingw|mswin/ then "clip" else if system("which xclip > /dev/null 2>&1") "xclip -selection clipboard -i" elsif system("which xsel > /dev/null 2>&1") "xsel --clipboard --input" end end end |