Class: Diakonos::ClipboardKlipperDBus
- Defined in:
- lib/diakonos/clipboard-klipper-dbus.rb
Overview
Same interface as Diakonos::Clipboard, except interacts with Klipper in KDE4 (via dbus)
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 ⇒ ClipboardKlipperDBus
constructor
A new instance of ClipboardKlipperDBus.
-
#send_to_klipper(text) ⇒ Object
Returns true iff some text was copied to klipper.
- #write_to_clip_file(text) ⇒ Object
Constructor Details
#initialize ⇒ ClipboardKlipperDBus
Returns a new instance of ClipboardKlipperDBus.
6 7 |
# File 'lib/diakonos/clipboard-klipper-dbus.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.
40 41 42 43 |
# File 'lib/diakonos/clipboard-klipper-dbus.rb', line 40 def add_clip( text ) return false if text.nil? send_to_klipper 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.
53 54 55 56 57 58 59 |
# File 'lib/diakonos/clipboard-klipper-dbus.rb', line 53 def append_to_clip( text ) return false if text.nil? last_clip = clip last_clip.pop if last_clip[ -1 ] == "" send_to_klipper last_clip + text end |
#clip ⇒ Object
30 31 32 33 34 35 |
# File 'lib/diakonos/clipboard-klipper-dbus.rb', line 30 def clip text = `dbus-send --print-reply --dest=org.kde.klipper /klipper org.kde.klipper.klipper.getClipboardContents | awk 'BEGIN { output = ""; } { if ( NR > 1 ) { output = output $0 "\\n"; } } END { print substr(output, 12, length(output) - 13); }'`.split( "\n", -1 ) # getClipboardContents puts an extra newline on end; pop it off. text.pop text end |
#send_to_klipper(text) ⇒ Object
Returns true iff some text was copied to klipper.
10 11 12 13 14 15 16 17 18 |
# File 'lib/diakonos/clipboard-klipper-dbus.rb', line 10 def send_to_klipper( text ) return false if text.nil? clip_filename = write_to_clip_file( text.join( "\n" ) ) # A little shell sorcery to ensure the shell doesn't strip off trailing newlines. `clipping=$(cat #{clip_filename};printf "_"); dbus-send --type=method_call --dest=org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents string:"${clipping%_}"` true end |
#write_to_clip_file(text) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/diakonos/clipboard-klipper-dbus.rb', line 20 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 |