clipboard 1.3.5 → 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: 892729b3fc00a3f989dfa1c3c5e1c05062b94a2f01af23a358d519a09b737f33
4
- data.tar.gz: 38f17ac7f06b2ff302b9498c3a3ad81bc2e7c9418f700f485569d8b8f15a18c9
3
+ metadata.gz: bce074b10a99ccac1cae0b51ab4a896cd366409376f54a93f39d3405fca795a7
4
+ data.tar.gz: 0676b27cf0ab8ecb7ba8eed63c72e7785c5d1c786546ade903a2e59e093dcf61
5
5
  SHA512:
6
- metadata.gz: 5920c4e55b0322ac05a0df5c36e7d3c2dca41a31a481aab7ed3df6f838a10c0d4592910617c4e95b5878d5133d1b628b46cecef236118abecab608dc64b31827
7
- data.tar.gz: 4ff5e2aba0b87384d16941ed3b85ba61382c7e28bc3a07e922328e3a9faf8a23f0524b797d8a729fd34cbb11720d6271890b6d772597444793dc66dd9443ad27
6
+ metadata.gz: 8a81a237755008ec1f8ea650b585d0f751e50b5e53e14db7e0490514e5f6894fe04333ebff7f0f4a2106d23c552ac2a84c7696f37bfba6c3e3361aaee89d8391
7
+ data.tar.gz: 97099eb3b2ac762e79d4aa63da3bc3c6c4c8bcd510f3d846c551bb9ff3312c3e85466bd3edc332cc421be8f9dff319035a59f8ec6195bae91e3780eb36b06200
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.6
4
+ * Fix Windows implementation (so it works on more recent Windows), patch by @P3t3rU5
5
+
3
6
  ## 1.3.5
4
7
  * Fix missing String#+@ method on Ruby <2.3, patch by @AaronC81
5
8
 
@@ -7,7 +10,6 @@
7
10
  * Don't break on Ruby 2.1, patch by @grosser
8
11
 
9
12
  ## 1.3.3
10
-
11
13
  * Fix Cygwin implementation to work when File constant is loaded, fix by @ntachino
12
14
 
13
15
  ## 1.3.2
data/MIT-LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2020 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,14 +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: **2.7**, **2.6**, **2.5**
13
+ Supported Rubies: **3.0**, **2.7**, **2.6**
14
14
 
15
- Unsupported, but might still work: **2.4**, **2.3**, **2.2**, **2.1**, **2.0**
15
+ Unsupported, but might still work: **2.5**, **2.4**, **2.3**, **2.2**, **2.1**, **2.0**
16
16
 
17
17
  ## Usage
18
18
 
19
19
  * `Clipboard.copy` - Copies a string to system clipboard
20
- * `Clipboard.paste` - Paste contents from system clipboard as string
20
+ * `Clipboard.paste` - Paste text contents from system clipboard as string
21
21
  * `Clipboard.clear` - Empties the system clipboard
22
22
 
23
23
  ## Setup
@@ -86,6 +86,13 @@ $ blip FILE_NAME
86
86
 
87
87
  Without any arguments, it will just paste the contents of the clipboard.
88
88
 
89
- ### MIT
89
+ ## Further Development
90
90
 
91
- Copyright (c) 2010-2020 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)
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
97
+
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)
@@ -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.5"
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 = "".dup
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
@@ -2,6 +2,8 @@
2
2
 
3
3
  require_relative "spec_helper"
4
4
 
5
+ require "fileutils"
6
+
5
7
  describe 'Clipboard::File' do
6
8
  before :all do
7
9
  Clipboard.implementation = Clipboard::File
@@ -9,31 +9,37 @@ os_to_restore = RbConfig::CONFIG['host_os']
9
9
  describe Clipboard do
10
10
  before do
11
11
  RbConfig::CONFIG['host_os'] = os_to_restore
12
+ @is_windows = Clipboard.implementation.name == 'Clipboard::Windows'
12
13
  end
13
14
 
15
+ let(:expected) { ->(text) { @is_windows ? text.encode(Encoding::UTF_16LE) : text } }
16
+
14
17
  it "has a VERSION" do
15
18
  expect( Clipboard::VERSION ).to match /^\d+\.\d+\.\d+$/
16
19
  end
17
20
 
18
21
  it "can copy & paste" do
19
- Clipboard.copy("FOO\nBAR")
20
- 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
21
25
  end
22
26
 
23
27
  it "can copy & paste with multibyte char" do
24
- Encoding.default_external = "utf-8"
25
- Clipboard.copy("日本語")
26
- 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)
27
32
  end
28
33
 
29
34
  it "returns data on copy" do
30
- expect( Clipboard.copy('xxx') ).to eq 'xxx'
35
+ text = 'xxx'
36
+ expect( Clipboard.copy(text) ).to eq expected.(text)
31
37
  end
32
38
 
33
39
  it "can clear" do
34
40
  Clipboard.copy('xxx')
35
41
  Clipboard.clear
36
- expect( Clipboard.paste ).to eq ''
42
+ expect( Clipboard.paste ).to eq expected.('')
37
43
  end
38
44
 
39
45
  describe "when included" do
@@ -43,10 +49,11 @@ describe Clipboard do
43
49
 
44
50
  it "can copy & paste & clear" do
45
51
  a = A.new
46
- expect( a.send(:copy, "XXX") ).to eq 'XXX'
47
- 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)
48
55
  a.send(:clear)
49
- expect( a.send(:paste) ).to eq ''
56
+ expect( a.send(:paste) ).to eq expected.('')
50
57
  end
51
58
  end
52
59
 
@@ -56,13 +63,13 @@ describe Clipboard do
56
63
  data1 = Random.new.bytes(2**14).unpack("H*").first
57
64
  data2 = Clipboard.copy(data1)
58
65
 
59
- expect(data2).to eq data1
66
+ expect(data2).to eq expected.(data1)
60
67
 
61
68
  # second batch
62
69
  data1 = Random.new.bytes(2**14).unpack("H*").first
63
70
  data2 = Clipboard.copy(data1)
64
71
 
65
- expect(data2).to eq data1
72
+ expect(data2).to eq expected.(data1)
66
73
  end
67
74
 
68
75
  describe :implementation do
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.5
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: 2020-09-05 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
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - 'Linux: You need xclip or xsel. On debian/ubuntu run: sudo apt-get install xsel'
88
88
  - 'Windows: You need the ffi gem'
89
- rubygems_version: 3.1.2
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.