Class: Diakonos::ClipboardXClip
- Defined in:
- lib/diakonos/clipboard-xclip.rb
Overview
Same interface as Diakonos::Clipboard, except interacts with xclip
Instance Method Summary collapse
-
#add_clip(text) ⇒ Object
text is an array of Strings Returns true iff a clip was added, and only non-nil text can be added.
-
#append_to_clip(text) ⇒ Object
text is an array of Strings (lines) Appends the lines to the current clip.
-
#clip ⇒ Object
——————————.
-
#each ⇒ Object
no-op.
-
#initialize ⇒ ClipboardXClip
constructor
A new instance of ClipboardXClip.
-
#send_to_xclip(text) ⇒ Object
Returns true iff some text was copied to xclip.
- #write_to_clip_file(text) ⇒ Object
Constructor Details
#initialize ⇒ ClipboardXClip
Returns a new instance of ClipboardXClip.
6 7 |
# File 'lib/diakonos/clipboard-xclip.rb', line 6 def initialize end |
Instance Method Details
#add_clip(text) ⇒ Object
text is an array of Strings Returns true iff a clip was added, and only non-nil text can be added.
38 39 40 41 |
# File 'lib/diakonos/clipboard-xclip.rb', line 38 def add_clip( text ) return false if text.nil? send_to_xclip text end |
#append_to_clip(text) ⇒ Object
text is an array of Strings (lines) Appends the lines to the current clip. If no current clip, then a new clip is created. Returns true iff the text was successfully appended.
51 52 53 54 55 56 57 |
# File 'lib/diakonos/clipboard-xclip.rb', line 51 def append_to_clip( text ) return false if text.nil? last_clip = clip last_clip.pop if last_clip[ -1 ] == "" send_to_xclip last_clip + text end |
#clip ⇒ Object
31 32 33 |
# File 'lib/diakonos/clipboard-xclip.rb', line 31 def clip `xclip -o`.split( "\n", -1 ) end |
#send_to_xclip(text) ⇒ Object
Returns true iff some text was copied to xclip.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/diakonos/clipboard-xclip.rb', line 10 def send_to_xclip( text ) return false if text.nil? clip_filename = write_to_clip_file( text.join( "\n" ) ) t = Thread.new do `xclip -i #{clip_filename}` end `xclip -o` # Unfreeze xclip t.terminate true end |
#write_to_clip_file(text) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/diakonos/clipboard-xclip.rb', line 21 def write_to_clip_file( text ) clip_filename = $diakonos.diakonos_home + "/clip.txt" File.open( clip_filename, "w" ) do |f| f.print text end clip_filename end |