clipboard 1.3.2 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ebc144bb289821cb40c971f1b702fb60a453625883d7efd38585ae1a62e65f0
4
- data.tar.gz: 90bad53653b32b65cffe04dce43d1374a9a88932036320f704235e47aa405899
3
+ metadata.gz: bce074b10a99ccac1cae0b51ab4a896cd366409376f54a93f39d3405fca795a7
4
+ data.tar.gz: 0676b27cf0ab8ecb7ba8eed63c72e7785c5d1c786546ade903a2e59e093dcf61
5
5
  SHA512:
6
- metadata.gz: 994fe1e4db10204285de7603867055a30aa07731894c5a77f52309e5c176b52afcb6a332c2e7b90fdc4b7f89bbd714a44fe4aac3e52548f584375c234597876e
7
- data.tar.gz: c4be192c4b275b83150050d6947a79431dd167de8e62c0abcfda46617bf488707abf7e4805df642f06752c6c805a18f820466457cd8fb48bd0dbeb51ee5be819
6
+ metadata.gz: 8a81a237755008ec1f8ea650b585d0f751e50b5e53e14db7e0490514e5f6894fe04333ebff7f0f4a2106d23c552ac2a84c7696f37bfba6c3e3361aaee89d8391
7
+ data.tar.gz: 97099eb3b2ac762e79d4aa63da3bc3c6c4c8bcd510f3d846c551bb9ff3312c3e85466bd3edc332cc421be8f9dff319035a59f8ec6195bae91e3780eb36b06200
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.6
4
+ * Fix Windows implementation (so it works on more recent Windows), patch by @P3t3rU5
5
+
6
+ ## 1.3.5
7
+ * Fix missing String#+@ method on Ruby <2.3, patch by @AaronC81
8
+
9
+ ## 1.3.4
10
+ * Don't break on Ruby 2.1, patch by @grosser
11
+
12
+ ## 1.3.3
13
+ * Fix Cygwin implementation to work when File constant is loaded, fix by @ntachino
14
+
3
15
  ## 1.3.2
4
16
  * Windows version actually mutates a string, fix by @scivola
5
17
 
data/MIT-LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2018 Jan Lelis
1
+ Copyright (c) 2010-2021 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
@@ -1,4 +1,4 @@
1
- # Clipboard Ruby Gem [![version](https://badge.fury.io/rb/clipboard.svg)](https://badge.fury.io/rb/clipboard) [<img src="https://travis-ci.org/janlelis/clipboard.svg" />](https://travis-ci.org/janlelis/clipboard)
1
+ # Clipboard Ruby Gem [![version](https://badge.fury.io/rb/clipboard.svg)](https://badge.fury.io/rb/clipboard) [![[ci]](https://github.com/janlelis/clipboard/workflows/Test/badge.svg)](https://github.com/janlelis/clipboard/actions?query=workflow%3ATest)
2
2
 
3
3
  Lets you access the clipboard from everywhere. Currently supported platforms:
4
4
 
@@ -10,10 +10,14 @@ Lets you access the clipboard from everywhere. Currently supported platforms:
10
10
  - Gtk+ (Cross Platform Widget Toolkit)
11
11
  - Java (on JRuby)
12
12
 
13
+ Supported Rubies: **3.0**, **2.7**, **2.6**
14
+
15
+ Unsupported, but might still work: **2.5**, **2.4**, **2.3**, **2.2**, **2.1**, **2.0**
16
+
13
17
  ## Usage
14
18
 
15
19
  * `Clipboard.copy` - Copies a string to system clipboard
16
- * `Clipboard.paste` - Paste contents from system clipboard as string
20
+ * `Clipboard.paste` - Paste text contents from system clipboard as string
17
21
  * `Clipboard.clear` - Empties the system clipboard
18
22
 
19
23
  ## Setup
@@ -21,11 +25,11 @@ Lets you access the clipboard from everywhere. Currently supported platforms:
21
25
  Add the following lines to your `Gemfile`:
22
26
 
23
27
  ```ruby
24
- gem 'clipboard'
25
- gem 'ffi', :platforms => [:mswin, :mingw]
28
+ gem "clipboard"
29
+ gem "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
26
30
  ```
27
31
 
28
- - Important note for **Linux** users: The clipboard requires the *xclip* or the *xsel* command-line program. On debian and ubuntu, *xsel* can be installed with: `sudo apt-get install xsel`
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`
29
33
 
30
34
  ## Clipboard Implementations
31
35
 
@@ -82,6 +86,13 @@ $ blip FILE_NAME
82
86
 
83
87
  Without any arguments, it will just paste the contents of the clipboard.
84
88
 
85
- ### MIT
89
+ ## Further Development
90
+
91
+ 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
+ - Wayland support (via FFI?)
94
+ - Support clipboard meta data
95
+
96
+ ## MIT
86
97
 
87
- Copyright (c) 2010-2018 Jan Lelis <http://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)
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)
data/clipboard.gemspec CHANGED
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $:.unshift File.expand_path("../lib", __FILE__)
2
4
  require 'clipboard/version'
3
5
 
4
6
  Gem::Specification.new do |s|
5
- s.name = 'clipboard'
6
- s.version = Clipboard::VERSION
7
-
8
- s.authors = ["Jan Lelis"]
9
- s.summary = "Access to the clipboard on Linux, MacOS, Windows, and Cygwin."
7
+ s.name = 'clipboard'
8
+ s.version = Clipboard::VERSION
9
+ s.authors = ["Jan Lelis"]
10
+ s.email = ["hi@ruby.consulting"]
11
+ s.summary = "Access to the clipboard on Linux, MacOS, Windows, and Cygwin."
10
12
  s.description = "Access to the clipboard on Linux, MacOS, Windows, and Cygwin: Clipboard.copy, Clipboard.paste, Clipboard.clear"
11
- s.email = "mail@janlelis.de"
12
13
  s.homepage = "https://github.com/janlelis/clipboard"
13
- s.license = "MIT"
14
+ s.license = "MIT"
14
15
  s.requirements = [
15
16
  "Linux: You need xclip or xsel. On debian/ubuntu run: sudo apt-get install xsel",
16
17
  "Windows: You need the ffi gem",
@@ -18,7 +19,7 @@ Gem::Specification.new do |s|
18
19
  s.files = Dir.glob(%w[{lib,spec}/**/*.rb [A-Z]*.txt [A-Z]*.md]) + %w{clipboard.gemspec}
19
20
 
20
21
  s.required_ruby_version = '>= 1.9.3'
21
- s.add_development_dependency 'rake', '~> 11'
22
+ s.add_development_dependency 'rake', '~> 13.0'
22
23
  s.add_development_dependency 'rspec', '~> 3'
23
24
  # s.add_development_dependency 'ffi', '~> 1.9'
24
25
  # s.add_development_dependency 'gtk3', '~> 3'
data/lib/clipboard.rb CHANGED
@@ -35,7 +35,7 @@ module Clipboard
35
35
  # Running additional check to detect if running in Microsoft WSL
36
36
  if os == :Linux
37
37
  require "etc"
38
- if Etc.uname[:release] =~ /Microsoft/
38
+ if Etc.respond_to?(:uname) && Etc.uname[:release] =~ /Microsoft/ # uname was added in ruby 2.2
39
39
  os = :Wsl
40
40
  end
41
41
  end
@@ -5,11 +5,11 @@ module Clipboard
5
5
  extend self
6
6
 
7
7
  def paste(_ = nil)
8
- File.read("/dev/clipboard")
8
+ ::File.read("/dev/clipboard")
9
9
  end
10
10
 
11
11
  def copy(data)
12
- File.open("/dev/clipboard", "w"){ |f| f.write(data) }
12
+ ::File.open("/dev/clipboard", "w"){ |f| f.write(data) }
13
13
  paste
14
14
  end
15
15
 
@@ -27,7 +27,7 @@ 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"
31
31
  end
32
32
 
33
33
  def paste(which = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clipboard
4
- VERSION = "1.3.2"
4
+ VERSION = "1.3.6"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "utils"
3
+ require_relative 'utils'
4
4
 
5
5
  module Clipboard
6
6
  module Windows
@@ -19,14 +19,14 @@ module Clipboard
19
19
 
20
20
  module User32
21
21
  extend FFI::Library
22
- ffi_lib "user32"
22
+ ffi_lib 'user32'
23
23
  ffi_convention :stdcall
24
24
 
25
- attach_function :open, :OpenClipboard, [ :long ], :long
26
- attach_function :close, :CloseClipboard, [ ], :long
27
- attach_function :empty, :EmptyClipboard, [ ], :long
28
- attach_function :get, :GetClipboardData, [ :long ], :long
29
- attach_function :set, :SetClipboardData, [ :long, :long ], :long
25
+ attach_function :open, :OpenClipboard, [ :pointer ], :bool
26
+ attach_function :close, :CloseClipboard, [ ], :bool
27
+ attach_function :empty, :EmptyClipboard, [ ], :bool
28
+ attach_function :get, :GetClipboardData, [ :long ], :pointer
29
+ attach_function :set, :SetClipboardData, [ :long, :pointer ], :pointer
30
30
  end
31
31
 
32
32
  module Kernel32
@@ -34,53 +34,56 @@ module Clipboard
34
34
  ffi_lib 'kernel32'
35
35
  ffi_convention :stdcall
36
36
 
37
- attach_function :lock, :GlobalLock, [ :long ], :pointer
38
- attach_function :unlock, :GlobalUnlock, [ :long ], :long
39
- attach_function :size, :GlobalSize, [ :long ], :long
40
- attach_function :alloc, :GlobalAlloc, [ :long, :long ], :long
37
+ attach_function :lock, :GlobalLock, [ :pointer ], :pointer
38
+ attach_function :unlock, :GlobalUnlock, [ :pointer ], :bool
39
+ attach_function :size, :GlobalSize, [ :pointer ], :long
40
+ attach_function :alloc, :GlobalAlloc, [ :long, :long ], :pointer
41
41
  end
42
42
 
43
43
  # see http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx
44
44
  def paste(_ = nil)
45
- data = +""
46
- if 0 != User32.open( 0 )
47
- hclip = User32.get( CF_UNICODETEXT )
48
- if hclip && 0 != hclip
49
- pointer_to_data = Kernel32.lock( hclip )
50
- # Windows Unicode is ended by two null bytes, so get the whole string
51
- size = Kernel32.size( hclip )
52
- data << pointer_to_data.get_bytes( 0, size - 2 )
53
- data.force_encoding("UTF-16LE")
54
- Kernel32.unlock( hclip )
55
- end
56
- User32.close( )
57
- end
58
- data
45
+ return String.new unless User32.open(nil)
46
+
47
+ hclip = User32.get( CF_UNICODETEXT )
48
+ return String.new if hclip.null?
49
+
50
+ pointer_to_data = Kernel32.lock( hclip )
51
+ # Windows Unicode is ended by two null bytes, so get the whole string
52
+ size = Kernel32.size( hclip )
53
+ data = pointer_to_data.read_string( size - 2 )
54
+ data.force_encoding(Encoding::UTF_16LE)
55
+ ensure
56
+ Kernel32.unlock(hclip) if hclip && !hclip.null?
57
+ User32.close
59
58
  end
60
59
 
61
60
  def clear
62
- if 0 != User32.open( 0 )
63
- User32.empty( )
64
- User32.close( )
65
- end
61
+ User32.empty if User32.open(nil)
66
62
  paste
63
+ ensure
64
+ User32.close
67
65
  end
68
66
 
69
67
  def copy(data_to_copy)
70
- if 0 != User32.open( 0 )
71
- User32.empty( )
72
- data = data_to_copy.encode("UTF-16LE") # TODO: catch bad encodings
68
+ if User32.open(nil)
69
+ User32.empty
70
+ data = data_to_copy.encode(Encoding::UTF_16LE) # TODO: catch bad encodings
73
71
  data << 0
74
72
  handler = Kernel32.alloc( GMEM_MOVEABLE, data.bytesize )
75
73
  pointer_to_data = Kernel32.lock( handler )
76
- pointer_to_data.put_bytes( 0, data, 0, data.bytesize )
77
- Kernel32.unlock( handler )
74
+ begin
75
+ pointer_to_data.write_string( data )
76
+ ensure
77
+ Kernel32.unlock( handler )
78
+ end
78
79
  User32.set( CF_UNICODETEXT, handler )
79
- User32.close( )
80
+ data.chop
80
81
  else # don't touch anything
81
82
  Utils.popen "clip", data_to_copy # depends on clip (available by default since Vista)
83
+ paste
82
84
  end
83
- paste
85
+ ensure
86
+ User32.close
84
87
  end
85
88
  end
86
89
  end
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "spec_helper"
2
4
 
5
+ require "fileutils"
6
+
3
7
  describe 'Clipboard::File' do
4
8
  before :all do
5
9
  Clipboard.implementation = Clipboard::File
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Please note: cannot test, if it really accesses your platform clipboard.
2
4
 
3
5
  require_relative "spec_helper"
@@ -7,31 +9,37 @@ os_to_restore = RbConfig::CONFIG['host_os']
7
9
  describe Clipboard do
8
10
  before do
9
11
  RbConfig::CONFIG['host_os'] = os_to_restore
12
+ @is_windows = Clipboard.implementation.name == 'Clipboard::Windows'
10
13
  end
11
14
 
15
+ let(:expected) { ->(text) { @is_windows ? text.encode(Encoding::UTF_16LE) : text } }
16
+
12
17
  it "has a VERSION" do
13
18
  expect( Clipboard::VERSION ).to match /^\d+\.\d+\.\d+$/
14
19
  end
15
20
 
16
21
  it "can copy & paste" do
17
- Clipboard.copy("FOO\nBAR")
18
- expect( Clipboard.paste ).to eq "FOO\nBAR"
22
+ text = "FOO\nBAR"
23
+ Clipboard.copy(text)
24
+ expect( Clipboard.paste.bytes ).to eq expected.(text).bytes
19
25
  end
20
26
 
21
27
  it "can copy & paste with multibyte char" do
22
- Encoding.default_external = "utf-8"
23
- Clipboard.copy("日本語")
24
- expect( Clipboard.paste ).to eq "日本語"
28
+ Encoding.default_external = 'utf-8'
29
+ text = '日本語'
30
+ Clipboard.copy(text)
31
+ expect( Clipboard.paste ).to eq expected.(text)
25
32
  end
26
33
 
27
34
  it "returns data on copy" do
28
- expect( Clipboard.copy('xxx') ).to eq 'xxx'
35
+ text = 'xxx'
36
+ expect( Clipboard.copy(text) ).to eq expected.(text)
29
37
  end
30
38
 
31
39
  it "can clear" do
32
40
  Clipboard.copy('xxx')
33
41
  Clipboard.clear
34
- expect( Clipboard.paste ).to eq ''
42
+ expect( Clipboard.paste ).to eq expected.('')
35
43
  end
36
44
 
37
45
  describe "when included" do
@@ -41,10 +49,11 @@ describe Clipboard do
41
49
 
42
50
  it "can copy & paste & clear" do
43
51
  a = A.new
44
- expect( a.send(:copy, "XXX") ).to eq 'XXX'
45
- expect( a.send(:paste) ).to eq "XXX"
52
+ text = 'XXX'
53
+ expect( a.send(:copy, text) ).to eq expected.(text)
54
+ expect( a.send(:paste) ).to eq expected.(text)
46
55
  a.send(:clear)
47
- expect( a.send(:paste) ).to eq ''
56
+ expect( a.send(:paste) ).to eq expected.('')
48
57
  end
49
58
  end
50
59
 
@@ -54,13 +63,13 @@ describe Clipboard do
54
63
  data1 = Random.new.bytes(2**14).unpack("H*").first
55
64
  data2 = Clipboard.copy(data1)
56
65
 
57
- expect(data2).to eq data1
66
+ expect(data2).to eq expected.(data1)
58
67
 
59
68
  # second batch
60
69
  data1 = Random.new.bytes(2**14).unpack("H*").first
61
70
  data2 = Clipboard.copy(data1)
62
71
 
63
- expect(data2).to eq data1
72
+ expect(data2).to eq expected.(data1)
64
73
  end
65
74
 
66
75
  describe :implementation do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift 'lib'
2
4
  require 'clipboard'
3
5
  require 'clipboard/file'
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.2
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-14 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '11'
19
+ version: '13.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '11'
26
+ version: '13.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,8 @@ dependencies:
40
40
  version: '3'
41
41
  description: 'Access to the clipboard on Linux, MacOS, Windows, and Cygwin: Clipboard.copy,
42
42
  Clipboard.paste, Clipboard.clear'
43
- email: mail@janlelis.de
43
+ email:
44
+ - hi@ruby.consulting
44
45
  executables: []
45
46
  extensions: []
46
47
  extra_rdoc_files: []
@@ -85,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - 'Linux: You need xclip or xsel. On debian/ubuntu run: sudo apt-get install xsel'
87
88
  - 'Windows: You need the ffi gem'
88
- rubyforge_project:
89
- rubygems_version: 2.7.7
89
+ rubygems_version: 3.2.3
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Access to the clipboard on Linux, MacOS, Windows, and Cygwin.