Class: PerfectWorld::Clipboard
- Inherits:
-
Object
- Object
- PerfectWorld::Clipboard
- Defined in:
- lib/perfect_world/clipboard.rb
Overview
Writes/Reads data from/to the users clipboard.
Works in graphical environments only. So it is not available via SSH and stuff.
Constant Summary collapse
- COMMANDS =
Common clipboard tools.
[{ read: 'xclip -selection clipboard -o', write: 'xclip -selection clipboard' }, { read: 'xsel -b -o', write: 'xsel -b' }, { read: 'pbpaste', write: 'pbcopy' }]
- CMD =
Find a working clipboard tool.
COMMANDS.find { |c| system("#{c[:read]} &>/dev/null") }
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns true if the clipboard is available, else false.
-
.read ⇒ Object
Reads a string from the clipboard.
-
.write(s) ⇒ Object
(also: <<)
Writes a string to the clipboard.
Class Method Details
.available? ⇒ Boolean
Returns true if the clipboard is available, else false.
28 29 30 |
# File 'lib/perfect_world/clipboard.rb', line 28 def available? ! CMD.nil? end |
.read ⇒ Object
Reads a string from the clipboard.
42 43 44 |
# File 'lib/perfect_world/clipboard.rb', line 42 def read run { `#{CMD[:read]}` } end |
.write(s) ⇒ Object Also known as: <<
Writes a string to the clipboard.
33 34 35 36 37 |
# File 'lib/perfect_world/clipboard.rb', line 33 def write(s) run do IO.popen(CMD[:write], 'w') { |io| io << s } end end |