Module: Clipboard

Extended by:
Clipboard
Included in:
Clipboard
Defined in:
lib/clipboard/gtk.rb,
lib/clipboard.rb,
lib/clipboard/mac.rb,
lib/clipboard/wsl.rb,
lib/clipboard/file.rb,
lib/clipboard/java.rb,
lib/clipboard/linux.rb,
lib/clipboard/utils.rb,
lib/clipboard/cygwin.rb,
lib/clipboard/version.rb,
lib/clipboard/windows.rb,
lib/clipboard/linux_wayland.rb

Overview

Ruby-Gnome2 based implementation Requires either the gtk3 or the gtk2 gem

Defined Under Namespace

Modules: Cygwin, File, Gtk, Java, Linux, LinuxWayland, Mac, Utils, Windows, Wsl Classes: ClipboardLoadError

Constant Summary collapse

VERSION =
"1.4.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.implementationObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/clipboard.rb', line 26

def self.implementation
  return @implementation if @implementation

  os = case RbConfig::CONFIG['host_os']
  when /mac|darwin/        then :Mac
  when /linux|bsd/         then :Linux
  when /mswin|mingw/       then :Windows
  when /cygwin/            then :Cygwin
  else
    raise ClipboardLoadError, "Your OS(#{ RbConfig::CONFIG['host_os'] }) is not supported"
  end

  # Running additional check to detect if running in Microsoft WSL or Wayland
  if os == :Linux
    require "etc"
    if Etc.respond_to?(:uname) && Etc.uname[:release] =~ /Microsoft/ # uname was added in ruby 2.2
      os = :Wsl
    # Only choose Wayland implementation if wl-copy is found, since xclip / xsel *might* work
    elsif ENV["XDG_SESSION_TYPE"] == "wayland" && Utils.executable_installed?("wl-copy")
      os = :LinuxWayland
    end
  end

  @implementation = Clipboard.const_get(os)
rescue ClipboardLoadError => e
  $stderr.puts "#{e.message}\nUsing file-based (fake) clipboard" unless $VERBOSE == nil
  @implementation = Clipboard::File
end

.implementation=(val) ⇒ Object



55
56
57
# File 'lib/clipboard.rb', line 55

def self.implementation=(val)
  @implementation = val
end

Instance Method Details

#clear(*args) ⇒ Object



63
64
65
# File 'lib/clipboard.rb', line 63

def clear(*args)
  Clipboard.implementation.clear(*args)
end

#copy(*args) ⇒ Object



67
68
69
# File 'lib/clipboard.rb', line 67

def copy(*args)
  Clipboard.implementation.copy(*args)
end

#paste(*args) ⇒ Object



59
60
61
# File 'lib/clipboard.rb', line 59

def paste(*args)
  Clipboard.implementation.paste(*args)
end