clipboard 1.2.1 → 1.3.0
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/MIT-LICENSE.txt +1 -1
- data/README.md +58 -37
- data/clipboard.gemspec +3 -1
- data/lib/clipboard.rb +3 -0
- data/lib/clipboard/cygwin.rb +2 -0
- data/lib/clipboard/file.rb +2 -0
- data/lib/clipboard/gtk.rb +47 -0
- data/lib/clipboard/java.rb +2 -0
- data/lib/clipboard/linux.rb +20 -12
- data/lib/clipboard/mac.rb +4 -2
- data/lib/clipboard/utils.rb +22 -0
- data/lib/clipboard/version.rb +3 -1
- data/lib/clipboard/windows.rb +4 -2
- data/lib/clipboard/wsl.rb +4 -2
- data/spec/clipboard_linux_spec.rb +20 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db9702c7b8ca48e95e26e612cf294b78d4eb188a4e74a72a002fb064e6c61e3
|
4
|
+
data.tar.gz: 6abd7baac11e392fa41997d771504c6b104350f8049693735f233dee6bba8915
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4b5ff54912337f98f1918375e8839b6eae786b9aa464bfa1b1aacf4bff3e30967f9104fa520f8fe6f343e7273c5982db1c109705884f4426b23166f02a8ec37
|
7
|
+
data.tar.gz: cbe9164425d0f9f1ab7f0efd270a8adcf9e65ba472a644afab3301e100e9fab9d27a400c0e8964200898edec99a2fa91259d877dc0219549778f35625d594295
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.3.0
|
4
|
+
### Bug Fixes
|
5
|
+
* Conditionally read or don't read the output stream of external commands, fixes #32
|
6
|
+
* Special thanks to @orange-kao for the bug report + PR
|
7
|
+
|
8
|
+
### New Features
|
9
|
+
* Add a GTK based clipboard
|
10
|
+
|
11
|
+
### Internal changes
|
12
|
+
* Use frozen string literals
|
13
|
+
|
3
14
|
## 1.2.1
|
4
15
|
* Add WSL to autoloaded constants
|
5
16
|
|
data/MIT-LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,66 +1,87 @@
|
|
1
|
-
# Ruby
|
1
|
+
# Clipboard Ruby Gem [](https://badge.fury.io/rb/clipboard) [<img src="https://travis-ci.org/janlelis/clipboard.svg" />](https://travis-ci.org/janlelis/clipboard)
|
2
2
|
|
3
|
-
Lets you access the clipboard
|
3
|
+
Lets you access the clipboard from everywhere. Currently supported platforms:
|
4
|
+
|
5
|
+
- Linux
|
6
|
+
- MacOS
|
7
|
+
- Windows
|
8
|
+
- Cygwin (POSIX environment for Windows)
|
9
|
+
- WSL (Windows Subsystem for Linux)
|
10
|
+
- Gtk+ (Cross Platform Widget Toolkit)
|
11
|
+
- Java (on JRuby)
|
4
12
|
|
5
13
|
## Usage
|
6
14
|
|
7
|
-
* `Clipboard.copy`
|
8
|
-
* `Clipboard.paste`
|
9
|
-
* `Clipboard.clear`
|
15
|
+
* `Clipboard.copy` - Copies a string to system clipboard
|
16
|
+
* `Clipboard.paste` - Paste contents from system clipboard as string
|
17
|
+
* `Clipboard.clear` - Empties the system clipboard
|
10
18
|
|
11
19
|
## Setup
|
12
20
|
|
13
|
-
Add to `Gemfile`:
|
21
|
+
Add the following lines to your `Gemfile`:
|
14
22
|
|
15
23
|
```ruby
|
16
24
|
gem 'clipboard'
|
17
25
|
gem 'ffi', :platforms => [:mswin, :mingw]
|
18
26
|
```
|
19
27
|
|
20
|
-
- **Linux
|
21
|
-
this is: `sudo apt-get install xclip`
|
28
|
+
- Important note for **Linux** users: The clipboard requires the *xclip* or the *xsel* command-line program. On debian and ubuntu, xclip can be installed with: `sudo apt-get install xclip`
|
22
29
|
|
23
|
-
##
|
24
|
-
### Multiple Clipboards
|
30
|
+
## Clipboard Implementations
|
25
31
|
|
26
|
-
|
27
|
-
passing it as an argument. The default is CLIPBOARD.
|
32
|
+
In most environments, the appropriate clipboard implementation can be detected automatically. If none is found, the gem will fallback to a file based one, which will just write to/read from `~/.clipboard` instead of the system clipboard.
|
28
33
|
|
29
|
-
|
34
|
+
You can check the implementation used with: `Clipboard.implementation`
|
30
35
|
|
31
|
-
###
|
36
|
+
### Alternative Clipboard Providers
|
32
37
|
|
33
|
-
|
34
|
-
encoding, so pasted strings will always come in UTF-16LE. You can manually
|
35
|
-
convert them to your desired encoding (e.g. UTF-8) using the
|
36
|
-
[String#encode](ruby-doc.org/core-2.3.0/String.html#method-i-encode) method:
|
38
|
+
There are two implementations included in this gem, which are not used by default. You can opt-in to use them if you think they are a better fit for your application environment:
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
#### Java
|
41
|
+
|
42
|
+
Activate with: `Clipboard.implementation = Clipboard::Java`
|
43
|
+
|
44
|
+
This is an option for [JRuby users](https://www.jruby.org/) which will use the clipboard functionality from the Java standard library.
|
45
|
+
|
46
|
+
#### GTK+
|
47
|
+
|
48
|
+
Activate with: `Clipboard.implementation = Clipboard::Gtk`
|
49
|
+
|
50
|
+
This utilizes the **GTK+** library. See [Ruby-GNOME2](https://github.com/ruby-gnome2/ruby-gnome2#ruby-gnome2) for more info.
|
51
|
+
|
52
|
+
Requires the `gtk3` or `gtk2` gem to be installed.
|
41
53
|
|
42
|
-
|
54
|
+
## Tips & Tricks
|
43
55
|
|
44
|
-
|
45
|
-
and connect via `ssh -X` or `ssh -Y`. Please note that some server settings
|
46
|
-
restrict this feature.
|
56
|
+
### Linux: Using Clipboard via SSH
|
47
57
|
|
48
|
-
|
58
|
+
To be able to use the clipboard through SSH, you need to install `xauth` on your server and connect via `ssh -X` or `ssh -Y`. Please note that some server settings restrict this feature.
|
49
59
|
|
50
|
-
|
51
|
-
JRuby. On Linux, it always operates only on the CLIPBOARD clipboard.
|
60
|
+
### Linux: Paste From Specific X11 Selection
|
52
61
|
|
53
|
-
|
62
|
+
The clipboard on Linux is divided into multiple clipboard selections. You can choose from which clipboard you want to `paste` from by
|
63
|
+
passing it as an argument. The default is *:clipboard*, other options are *:primary* and *:secondary*.
|
54
64
|
|
55
|
-
|
65
|
+
`Clipboard.copy` always copies to all three clipboards.
|
56
66
|
|
57
|
-
###
|
67
|
+
### Windows: Encoding Info
|
68
|
+
|
69
|
+
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:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Clipboard.paste.encode('UTF-8')
|
73
|
+
```
|
74
|
+
|
75
|
+
### CLI Utility: blip
|
76
|
+
|
77
|
+
The [blip gem]((https://gist.github.com/janlelis/781835)) is a handy command-line wrapper for the clipboard gem. It lets you quickly copy file content to your clipboard:
|
78
|
+
|
79
|
+
```
|
80
|
+
$ blip FILE_NAME
|
81
|
+
```
|
58
82
|
|
59
|
-
|
60
|
-
content to your clipboard: [blip](https://gist.github.com/janlelis/781835)!
|
83
|
+
Without any arguments, it will just paste the contents of the clipboard.
|
61
84
|
|
62
|
-
###
|
85
|
+
### MIT
|
63
86
|
|
64
|
-
Copyright (c) 2010-
|
65
|
-
license. Contributions by and thanks to Michael Grosser and [all the other
|
66
|
-
contributors!](https://github.com/janlelis/clipboard/graphs/contributors)
|
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)
|
data/clipboard.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.summary = "Access to the clipboard on Linux, MacOS, Windows, and Cygwin."
|
10
10
|
s.description = "Access to the clipboard on Linux, MacOS, Windows, and Cygwin: Clipboard.copy, Clipboard.paste, Clipboard.clear"
|
11
11
|
s.email = "mail@janlelis.de"
|
12
|
-
s.homepage = "
|
12
|
+
s.homepage = "https://github.com/janlelis/clipboard"
|
13
13
|
s.license = "MIT"
|
14
14
|
s.requirements = [
|
15
15
|
"On Linux (or other X), you will need xclip. On debian/ubuntu this is: sudo apt-get install xclip",
|
@@ -20,4 +20,6 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.required_ruby_version = '>= 1.9.3'
|
21
21
|
s.add_development_dependency 'rake', '~> 11'
|
22
22
|
s.add_development_dependency 'rspec', '~> 3'
|
23
|
+
# s.add_development_dependency 'ffi', '~> 1.9'
|
24
|
+
# s.add_development_dependency 'gtk3', '~> 3'
|
23
25
|
end
|
data/lib/clipboard.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rbconfig'
|
2
4
|
require File.dirname(__FILE__) + '/clipboard/version'
|
3
5
|
|
@@ -13,6 +15,7 @@ module Clipboard
|
|
13
15
|
autoload :Java, 'clipboard/java'
|
14
16
|
autoload :Cygwin, 'clipboard/cygwin'
|
15
17
|
autoload :Wsl, 'clipboard/wsl'
|
18
|
+
autoload :Gtk, 'clipboard/gtk'
|
16
19
|
end
|
17
20
|
autoload :Windows, 'clipboard/windows'
|
18
21
|
autoload :File, 'clipboard/file'
|
data/lib/clipboard/cygwin.rb
CHANGED
data/lib/clipboard/file.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Ruby-Gnome2 based implementation
|
4
|
+
# Requires either the gtk3 or the gtk2 gem
|
5
|
+
|
6
|
+
module Clipboard
|
7
|
+
module Gtk
|
8
|
+
extend self
|
9
|
+
|
10
|
+
CLIPBOARDS = %w[CLIPBOARD PRIMARY SECONDARY].freeze
|
11
|
+
|
12
|
+
unless defined? ::Gtk
|
13
|
+
begin
|
14
|
+
require 'gtk3'
|
15
|
+
rescue LoadError
|
16
|
+
begin
|
17
|
+
require 'gtk2'
|
18
|
+
rescue LoadError
|
19
|
+
raise LoadError, 'Could not load the required gtk3 or gtk2 gem, please install it with: gem install gtk3'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy(text)
|
25
|
+
CLIPBOARDS.each{ |which|
|
26
|
+
::Gtk::Clipboard.get(Gdk::Selection.const_get(which)).set_text(text).store
|
27
|
+
}
|
28
|
+
paste
|
29
|
+
end
|
30
|
+
|
31
|
+
def paste(which = nil)
|
32
|
+
if !which || !CLIPBOARDS.include?(which_normalized = which.to_s.upcase)
|
33
|
+
which_normalized = CLIPBOARDS.first
|
34
|
+
end
|
35
|
+
|
36
|
+
::Gtk::Clipboard.get(
|
37
|
+
Gdk::Selection.const_get(which_normalized)
|
38
|
+
).wait_for_text || ""
|
39
|
+
end
|
40
|
+
|
41
|
+
def clear
|
42
|
+
CLIPBOARDS.each{ |which|
|
43
|
+
::Gtk::Clipboard.get(Gdk::Selection.const_get(which)).clear
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/clipboard/java.rb
CHANGED
data/lib/clipboard/linux.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "utils"
|
4
4
|
|
5
5
|
module Clipboard
|
6
6
|
module Linux
|
@@ -10,23 +10,31 @@ module Clipboard
|
|
10
10
|
|
11
11
|
# check which backend to use
|
12
12
|
if Utils.executable_installed?('xclip')
|
13
|
-
WriteCommand = 'xclip'
|
14
|
-
ReadCommand = 'xclip -o'
|
15
|
-
|
13
|
+
WriteCommand = 'xclip'
|
14
|
+
ReadCommand = 'xclip -o'
|
15
|
+
ReadOutputStream = false
|
16
|
+
Selection = proc{ |x|
|
17
|
+
"-selection #{x}"
|
18
|
+
}.freeze
|
16
19
|
elsif Utils.executable_installed?('xsel')
|
17
|
-
WriteCommand = 'xsel -i'
|
18
|
-
ReadCommand = 'xsel -o'
|
19
|
-
|
20
|
+
WriteCommand = 'xsel -i'
|
21
|
+
ReadCommand = 'xsel -o'
|
22
|
+
ReadOutputStream = true
|
23
|
+
Selection = {
|
24
|
+
'clipboard' => '-b',
|
25
|
+
'primary' => '-p',
|
26
|
+
'secondary' => '-s'
|
27
|
+
}.freeze
|
20
28
|
else
|
21
29
|
raise Clipboard::ClipboardLoadError, "clipboard: Could not find required program xclip or xsel\n" \
|
22
30
|
"On debian/ubuntu, you can install it with: sudo apt-get install xclip"
|
23
31
|
end
|
24
32
|
|
25
33
|
def paste(which = nil)
|
26
|
-
if !which || !CLIPBOARDS.include?(which.to_s.downcase)
|
27
|
-
|
34
|
+
if !which || !CLIPBOARDS.include?(which_normalized = which.to_s.downcase)
|
35
|
+
which_normalized = CLIPBOARDS.first
|
28
36
|
end
|
29
|
-
`#{ReadCommand} #{Selection[
|
37
|
+
`#{ReadCommand} #{Selection[which_normalized]} 2> /dev/null`
|
30
38
|
end
|
31
39
|
|
32
40
|
def clear
|
@@ -35,7 +43,7 @@ module Clipboard
|
|
35
43
|
|
36
44
|
def copy(data)
|
37
45
|
CLIPBOARDS.each{ |which|
|
38
|
-
|
46
|
+
Utils.popen "#{WriteCommand} #{Selection[which]}", data, ReadOutputStream
|
39
47
|
}
|
40
48
|
paste
|
41
49
|
end
|
data/lib/clipboard/mac.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
2
4
|
|
3
5
|
module Clipboard
|
4
6
|
module Mac
|
@@ -9,7 +11,7 @@ module Clipboard
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def copy(data)
|
12
|
-
|
14
|
+
Utils.popen "pbcopy", data
|
13
15
|
paste
|
14
16
|
end
|
15
17
|
|
data/lib/clipboard/utils.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
|
1
5
|
module Clipboard
|
2
6
|
module Utils
|
3
7
|
extend self
|
@@ -7,5 +11,23 @@ module Clipboard
|
|
7
11
|
::File.executable?(::File.join(path, cmd))
|
8
12
|
end
|
9
13
|
end
|
14
|
+
|
15
|
+
# Utility to call external command
|
16
|
+
# - pure .popen2 becomes messy with xsel when not reading the output stream
|
17
|
+
# - xclip doesn't like to have output stream read
|
18
|
+
def popen(cmd, data, read_output_stream = false)
|
19
|
+
Open3.popen2(cmd) { |input, output, waiter_thread|
|
20
|
+
output_thread = Thread.new { output.read } if read_output_stream
|
21
|
+
|
22
|
+
begin
|
23
|
+
input.write data
|
24
|
+
rescue Errno::EPIPE
|
25
|
+
end
|
26
|
+
|
27
|
+
input.close
|
28
|
+
output_thread.value if read_output_stream
|
29
|
+
waiter_thread.value
|
30
|
+
}
|
31
|
+
end
|
10
32
|
end
|
11
33
|
end
|
data/lib/clipboard/version.rb
CHANGED
data/lib/clipboard/windows.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
2
4
|
|
3
5
|
module Clipboard
|
4
6
|
module Windows
|
@@ -76,7 +78,7 @@ module Clipboard
|
|
76
78
|
User32.set( CF_UNICODETEXT, handler )
|
77
79
|
User32.close( )
|
78
80
|
else # don't touch anything
|
79
|
-
|
81
|
+
Utils.popen "clip", data_to_copy # depends on clip (available by default since Vista)
|
80
82
|
end
|
81
83
|
paste
|
82
84
|
end
|
data/lib/clipboard/wsl.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
2
4
|
|
3
5
|
module Clipboard
|
4
6
|
module Wsl
|
@@ -9,7 +11,7 @@ module Clipboard
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def copy(data)
|
12
|
-
|
14
|
+
Utils.popen "clip.exe", data
|
13
15
|
paste
|
14
16
|
end
|
15
17
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require "clipboard/linux"
|
4
|
+
|
5
|
+
describe Clipboard::Linux do
|
6
|
+
# See https://github.com/janlelis/clipboard/issues/32 by @orange-kao
|
7
|
+
it "can copy more than 8192 bytes" do
|
8
|
+
# first batch
|
9
|
+
data1 = Random.new.bytes(2**14).unpack("H*").first
|
10
|
+
data2 = Clipboard.copy(data1)
|
11
|
+
|
12
|
+
expect(data2).to eq data1
|
13
|
+
|
14
|
+
# second batch
|
15
|
+
data1 = Random.new.bytes(2**14).unpack("H*").first
|
16
|
+
data2 = Clipboard.copy(data1)
|
17
|
+
|
18
|
+
expect(data2).to eq data1
|
19
|
+
end
|
20
|
+
end
|
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.
|
4
|
+
version: 1.3.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: 2018-12-
|
11
|
+
date: 2018-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/clipboard.rb
|
54
54
|
- lib/clipboard/cygwin.rb
|
55
55
|
- lib/clipboard/file.rb
|
56
|
+
- lib/clipboard/gtk.rb
|
56
57
|
- lib/clipboard/java.rb
|
57
58
|
- lib/clipboard/linux.rb
|
58
59
|
- lib/clipboard/mac.rb
|
@@ -60,9 +61,10 @@ files:
|
|
60
61
|
- lib/clipboard/version.rb
|
61
62
|
- lib/clipboard/windows.rb
|
62
63
|
- lib/clipboard/wsl.rb
|
64
|
+
- spec/clipboard_linux_spec.rb
|
63
65
|
- spec/clipboard_spec.rb
|
64
66
|
- spec/spec_helper.rb
|
65
|
-
homepage:
|
67
|
+
homepage: https://github.com/janlelis/clipboard
|
66
68
|
licenses:
|
67
69
|
- MIT
|
68
70
|
metadata: {}
|