clipboard 1.3.6 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bce074b10a99ccac1cae0b51ab4a896cd366409376f54a93f39d3405fca795a7
4
- data.tar.gz: 0676b27cf0ab8ecb7ba8eed63c72e7785c5d1c786546ade903a2e59e093dcf61
3
+ metadata.gz: 36dbdb09b06bc41833ad82b692560179ea1dde1a061db1dfab093d6ddea64cb7
4
+ data.tar.gz: 2fc4772e208ee387887ba3558b4acfdc810132877664f59d30fe5605c0218c2e
5
5
  SHA512:
6
- metadata.gz: 8a81a237755008ec1f8ea650b585d0f751e50b5e53e14db7e0490514e5f6894fe04333ebff7f0f4a2106d23c552ac2a84c7696f37bfba6c3e3361aaee89d8391
7
- data.tar.gz: 97099eb3b2ac762e79d4aa63da3bc3c6c4c8bcd510f3d846c551bb9ff3312c3e85466bd3edc332cc421be8f9dff319035a59f8ec6195bae91e3780eb36b06200
6
+ metadata.gz: 73d188dcf4b8ce431da705feaa6cdf71889ab48679d584450cdf88e871f19fb0ff15b7c1d325ca65f104bdc4195c8bdbdfb01ff477e4fef8f2ab20a12ff8bd4f
7
+ data.tar.gz: c7d4e4c0e7ca463c4d3799bfbe7a15b1c1cb67aaca4fa1b84aacb9ea39794b8d64eb264d86ab773806049a1a5c6abe766c7ccb87211ebb4afb64fc7faf313259
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.4.0
4
+ * Add Wayland support via `wl-copy`, patch by @cramt
5
+ * Only silence clipboard warnings when $VERBOSE is nil
6
+
3
7
  ## 1.3.6
4
8
  * Fix Windows implementation (so it works on more recent Windows), patch by @P3t3rU5
5
9
 
data/MIT-LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2021 Jan Lelis
1
+ Copyright (c) 2010-2024 Jan Lelis
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Lets you access the clipboard from everywhere. Currently supported platforms:
4
4
 
5
- - Linux
5
+ - Linux (X11)
6
+ - Linux (Wayland)
6
7
  - MacOS
7
8
  - Windows
8
9
  - Cygwin (POSIX environment for Windows)
@@ -10,9 +11,9 @@ Lets you access the clipboard from everywhere. Currently supported platforms:
10
11
  - Gtk+ (Cross Platform Widget Toolkit)
11
12
  - Java (on JRuby)
12
13
 
13
- Supported Rubies: **3.0**, **2.7**, **2.6**
14
+ Supported Rubies: **3.3**, **3.2**, **3.1**, **3.0**
14
15
 
15
- Unsupported, but might still work: **2.5**, **2.4**, **2.3**, **2.2**, **2.1**, **2.0**
16
+ Unsupported, but might still work: **2.X**
16
17
 
17
18
  ## Usage
18
19
 
@@ -29,7 +30,7 @@ gem "clipboard"
29
30
  gem "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
30
31
  ```
31
32
 
32
- - **Important note for Linux** users: The clipboard requires the *xsel* or the *xclip* command-line program. On debian and ubuntu, *xsel* can be installed with: `sudo apt-get install xsel`
33
+ - **Important note for Linux** users: The clipboard requires the *xsel* or the *xclip* command-line program (X11), or the *wl-copy* / *wl-paste* command-line programs (Wayland). On debian and ubuntu, *xsel* can be installed with: `sudo apt-get install xsel` and *wl-copy* / *wl-paste* with `sudo apt-get install wl-clipboard`.
33
34
 
34
35
  ## Clipboard Implementations
35
36
 
@@ -70,7 +71,7 @@ passing it as an argument. The default is *:clipboard*, other options are *:prim
70
71
 
71
72
  ### Windows: Encoding Info
72
73
 
73
- Windows uses [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16) as its default encoding, so pasted strings will always come in UTF-16. You can then manually convert them to your desired encoding, for example, UTF-8, using the [String#encode](ruby-doc.org/core-2.3.0/String.html#method-i-encode) method:
74
+ Windows uses [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16) as its default encoding, so pasted strings will always come in UTF-16. You can then manually convert them to your desired encoding, for example, UTF-8, using the [String#encode](https://rubyapi.org/o/string#method-i-encode) method:
74
75
 
75
76
  ```ruby
76
77
  Clipboard.paste.encode('UTF-8')
@@ -90,9 +91,10 @@ Without any arguments, it will just paste the contents of the clipboard.
90
91
 
91
92
  This is a list of nice-to-have features - feel free to open a PR or let me know if you want to work on one of these:
92
93
 
93
- - Wayland support (via FFI?)
94
+ - Native support for clipboard on X11 or Wayland
95
+ - Support more platforms
94
96
  - Support clipboard meta data
95
97
 
96
98
  ## MIT
97
99
 
98
- Copyright (c) 2010-2021 Jan Lelis <https://janlelis.com> released under the MIT license. Contributions by and thanks to [Michael Grosser and all the other contributors!](https://github.com/janlelis/clipboard/graphs/contributors)
100
+ Copyright (c) 2010-2024 Jan Lelis <https://janlelis.com> released under the MIT license. Contributions by and thanks to [Michael Grosser and all the other contributors!](https://github.com/janlelis/clipboard/graphs/contributors)
data/clipboard.gemspec CHANGED
@@ -12,8 +12,9 @@ Gem::Specification.new do |s|
12
12
  s.description = "Access to the clipboard on Linux, MacOS, Windows, and Cygwin: Clipboard.copy, Clipboard.paste, Clipboard.clear"
13
13
  s.homepage = "https://github.com/janlelis/clipboard"
14
14
  s.license = "MIT"
15
+ s.metadata = { "rubygems_mfa_required" => "true" }
15
16
  s.requirements = [
16
- "Linux: You need xclip or xsel. On debian/ubuntu run: sudo apt-get install xsel",
17
+ "Linux: You need xclip / xsel (X11) or wl-clipboard (Wayland)",
17
18
  "Windows: You need the ffi gem",
18
19
  ]
19
20
  s.files = Dir.glob(%w[{lib,spec}/**/*.rb [A-Z]*.txt [A-Z]*.md]) + %w{clipboard.gemspec}
@@ -27,7 +27,8 @@ module Clipboard
27
27
  }.freeze
28
28
  else
29
29
  raise Clipboard::ClipboardLoadError, "clipboard: Could not find required program xclip or xsel\n" \
30
- "On debian/ubuntu, you can install it with: sudo apt-get install xsel"
30
+ "On debian/ubuntu, you can install it with: sudo apt-get install xsel\n" \
31
+ "If your system is Wayland-based, please install wl-clipboard"
31
32
  end
32
33
 
33
34
  def paste(which = nil)
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "utils"
4
+
5
+ module Clipboard
6
+ module LinuxWayland
7
+ extend self
8
+
9
+ WRITE_COMMAND = "wl-copy"
10
+ READ_COMMAND = "wl-paste"
11
+
12
+ if !Utils.executable_installed?(WRITE_COMMAND)
13
+ raise Clipboard::ClipboardLoadError, "clipboard: Could not find required program wl-copy\n" \
14
+ "Please install it or try a different implementation"
15
+ end
16
+
17
+ def paste(might_select_primary_clipboard = nil)
18
+ if might_select_primary_clipboard == "primary"
19
+ `#{READ_COMMAND} -p`
20
+ else
21
+ `#{READ_COMMAND}`
22
+ end
23
+ end
24
+
25
+ def copy(data)
26
+ Utils.popen WRITE_COMMAND, data
27
+ paste
28
+ end
29
+
30
+ def clear
31
+ `#{WRITE_COMMAND} -c`
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clipboard
4
- VERSION = "1.3.6"
4
+ VERSION = "1.4.0"
5
5
  end
data/lib/clipboard.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rbconfig'
4
- require File.dirname(__FILE__) + '/clipboard/version'
4
+
5
+ require_relative 'clipboard/version'
6
+ require_relative 'clipboard/utils'
5
7
 
6
8
  module Clipboard
7
9
  extend self
@@ -10,12 +12,13 @@ module Clipboard
10
12
  end
11
13
 
12
14
  unless defined? Ocra # see gh#9
13
- autoload :Linux, 'clipboard/linux'
14
- autoload :Mac, 'clipboard/mac'
15
- autoload :Java, 'clipboard/java'
16
- autoload :Cygwin, 'clipboard/cygwin'
17
- autoload :Wsl, 'clipboard/wsl'
18
- autoload :Gtk, 'clipboard/gtk'
15
+ autoload :Linux, 'clipboard/linux'
16
+ autoload :LinuxWayland, 'clipboard/linux_wayland'
17
+ autoload :Mac, 'clipboard/mac'
18
+ autoload :Java, 'clipboard/java'
19
+ autoload :Cygwin, 'clipboard/cygwin'
20
+ autoload :Wsl, 'clipboard/wsl'
21
+ autoload :Gtk, 'clipboard/gtk'
19
22
  end
20
23
  autoload :Windows, 'clipboard/windows'
21
24
  autoload :File, 'clipboard/file'
@@ -29,20 +32,23 @@ module Clipboard
29
32
  when /mswin|mingw/ then :Windows
30
33
  when /cygwin/ then :Cygwin
31
34
  else
32
- raise ClipboardLoadError, "Your OS(#{ RbConfig::CONFIG['host_os'] }) is not supported, using file-based (fake) clipboard"
35
+ raise ClipboardLoadError, "Your OS(#{ RbConfig::CONFIG['host_os'] }) is not supported"
33
36
  end
34
37
 
35
- # Running additional check to detect if running in Microsoft WSL
38
+ # Running additional check to detect if running in Microsoft WSL or Wayland
36
39
  if os == :Linux
37
40
  require "etc"
38
41
  if Etc.respond_to?(:uname) && Etc.uname[:release] =~ /Microsoft/ # uname was added in ruby 2.2
39
42
  os = :Wsl
43
+ # Only choose Wayland implementation if wl-copy is found, since xclip / xsel *might* work
44
+ elsif ENV["XDG_SESSION_TYPE"] == "wayland" && Utils.executable_installed?("wl-copy")
45
+ os = :LinuxWayland
40
46
  end
41
47
  end
42
48
 
43
49
  @implementation = Clipboard.const_get(os)
44
50
  rescue ClipboardLoadError => e
45
- $stderr.puts e.message if $VERBOSE
51
+ $stderr.puts "#{e.message}\nUsing file-based (fake) clipboard" unless $VERBOSE == nil
46
52
  @implementation = Clipboard::File
47
53
  end
48
54
 
@@ -8,7 +8,7 @@ describe 'Clipboard::File' do
8
8
  before :all do
9
9
  Clipboard.implementation = Clipboard::File
10
10
  cache = Clipboard::File::FILE
11
- FileUtils.rm cache if File.exist?(cache)
11
+ FileUtils.rm_f cache
12
12
  end
13
13
 
14
14
  it "can paste with empty file" do
@@ -74,12 +74,13 @@ describe Clipboard do
74
74
 
75
75
  describe :implementation do
76
76
  before do
77
- $VERBOSE = true
77
+ $VERBOSE = false
78
78
  Clipboard.implementation = nil
79
79
  end
80
80
 
81
81
  it "does not warn on normal detection" do
82
- if system('which xclip >/dev/null 2>&1') || system('which xsel >/dev/null 2>&1')
82
+ if ( ENV["XDG_SESSION_TYPE"] != "wayland" && (system('which xclip >/dev/null 2>&1') || system('which xsel >/dev/null 2>&1') ) ) ||
83
+ ( ENV["XDG_SESSION_TYPE"] == "wayland" && system('which wl-copy >/dev/null 2>&1') )
83
84
  expect( $stderr ).not_to receive(:puts)
84
85
  end
85
86
  Clipboard.implementation
@@ -91,8 +92,8 @@ describe Clipboard do
91
92
  expect( Clipboard.implementation ).to eq Clipboard::File
92
93
  end
93
94
 
94
- it "does not warn when $VERBOSE is false" do
95
- $VERBOSE = false
95
+ it "does not warn when $VERBOSE is nil" do
96
+ $VERBOSE = nil
96
97
  RbConfig::CONFIG['host_os'] = 'Fooo OS'
97
98
  expect( $stderr ).not_to receive(:puts)
98
99
  Clipboard.implementation
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-25 00:00:00.000000000 Z
11
+ date: 2024-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -57,6 +57,7 @@ files:
57
57
  - lib/clipboard/gtk.rb
58
58
  - lib/clipboard/java.rb
59
59
  - lib/clipboard/linux.rb
60
+ - lib/clipboard/linux_wayland.rb
60
61
  - lib/clipboard/mac.rb
61
62
  - lib/clipboard/utils.rb
62
63
  - lib/clipboard/version.rb
@@ -68,7 +69,8 @@ files:
68
69
  homepage: https://github.com/janlelis/clipboard
69
70
  licenses:
70
71
  - MIT
71
- metadata: {}
72
+ metadata:
73
+ rubygems_mfa_required: 'true'
72
74
  post_install_message:
73
75
  rdoc_options: []
74
76
  require_paths:
@@ -84,9 +86,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  - !ruby/object:Gem::Version
85
87
  version: '0'
86
88
  requirements:
87
- - 'Linux: You need xclip or xsel. On debian/ubuntu run: sudo apt-get install xsel'
89
+ - 'Linux: You need xclip / xsel (X11) or wl-clipboard (Wayland)'
88
90
  - 'Windows: You need the ffi gem'
89
- rubygems_version: 3.2.3
91
+ rubygems_version: 3.5.3
90
92
  signing_key:
91
93
  specification_version: 4
92
94
  summary: Access to the clipboard on Linux, MacOS, Windows, and Cygwin.