clipboard 0.9.3 → 0.9.4
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.
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/LICENSE +1 -1
- data/README.rdoc +9 -2
- data/Rakefile +6 -0
- data/VERSION +1 -1
- data/clipboard.gemspec +2 -11
- data/lib/clipboard.rb +11 -137
- data/lib/clipboard/linux.rb +28 -0
- data/lib/clipboard/mac.rb +14 -0
- data/lib/clipboard/windows.rb +89 -0
- data/spec/clipboard_spec.rb +16 -0
- data/spec/spec_helper.rb +2 -0
- metadata +16 -22
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
rake (0.8.7)
|
6
|
+
rspec (2.4.0)
|
7
|
+
rspec-core (~> 2.4.0)
|
8
|
+
rspec-expectations (~> 2.4.0)
|
9
|
+
rspec-mocks (~> 2.4.0)
|
10
|
+
rspec-core (2.4.0)
|
11
|
+
rspec-expectations (2.4.0)
|
12
|
+
diff-lcs (~> 1.1.2)
|
13
|
+
rspec-mocks (2.4.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
rake
|
20
|
+
rspec (>= 2)
|
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -11,7 +11,7 @@ You have <tt>Clipboard.copy</tt>,
|
|
11
11
|
Have fun ;)
|
12
12
|
|
13
13
|
==== Multiple clipboards
|
14
|
-
On Linux, you can choose, from which clipboard you want to +paste+, default is
|
14
|
+
On Linux, you can choose, from which clipboard you want to +paste+, default is CLIPBOARD.
|
15
15
|
|
16
16
|
+copy+ copies to all clipboards in Clipboard::CLIPBOARDS.
|
17
17
|
|
@@ -29,7 +29,14 @@ Copying with 1.8 will fallback to the +clip+ utility, which is installed by defa
|
|
29
29
|
|
30
30
|
Feel free to report bugs or to implement one of the Todo entries ;)
|
31
31
|
|
32
|
+
=== blip
|
33
|
+
|
34
|
+
Copy and paste from the commandline (like xclip, pbpaste/pbcopy), but even easier? {blip}[http://rubygems.org/gems/blip]!
|
35
|
+
|
32
36
|
=== Copyright
|
33
|
-
Copyright (c) 2010 Jan Lelis, http://rbjl.net, released under the MIT license
|
37
|
+
Copyright (c) 2010-2011 Jan Lelis, http://rbjl.net, released under the MIT license
|
38
|
+
|
39
|
+
Contributions by
|
40
|
+
* Michael Grosser
|
34
41
|
|
35
42
|
J-_-L
|
data/Rakefile
CHANGED
@@ -2,6 +2,12 @@ require 'rake'
|
|
2
2
|
require 'rake/rdoctask'
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
|
+
task :default => :spec
|
6
|
+
require "rspec/core/rake_task"
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
|
+
t.rspec_opts = '--backtrace --color'
|
9
|
+
end
|
10
|
+
|
5
11
|
def gemspec
|
6
12
|
@gemspec ||= eval(File.read('clipboard.gemspec'), binding, 'clipboard.gemspec')
|
7
13
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.4
|
data/clipboard.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.version = File.read('VERSION').chomp
|
7
7
|
|
8
8
|
s.authors = ["Jan Lelis"]
|
9
|
-
s.date = '
|
9
|
+
s.date = '2011-01-16'
|
10
10
|
s.summary = 'Access the clipboard on all systems.'
|
11
11
|
s.description = 'Access the clipboard on all systems (Clipboard.copy & Clipboard.paste).'
|
12
12
|
s.email = 'mail@janlelis.de'
|
@@ -14,14 +14,5 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.rubygems_version = %q{1.3.7}
|
15
15
|
s.requirements = ["On Linux (or other X), you need xclip. Install it on debian/ubuntu with sudo apt-get install xclip"]
|
16
16
|
s.requirements << ["On Windows, you need the ffi gem."]
|
17
|
-
s.files = %w[
|
18
|
-
LICENSE
|
19
|
-
README.rdoc
|
20
|
-
Rakefile
|
21
|
-
VERSION
|
22
|
-
clipboard.gemspec
|
23
|
-
lib/clipboard.rb
|
24
|
-
]
|
25
|
-
s.extra_rdoc_files = %w[LICENSE README.rdoc]
|
26
|
-
s.add_dependency 'zucker', '>= 8'
|
17
|
+
s.files = Dir.glob(%w[{lib,spec}/**/*.rb [A-Z]* [A-Z]*.rdoc]) + %w{clipboard.gemspec}
|
27
18
|
end
|
data/lib/clipboard.rb
CHANGED
@@ -1,144 +1,18 @@
|
|
1
|
-
require 'zucker/os'
|
2
|
-
require 'zucker/version'
|
3
|
-
|
4
1
|
module Clipboard
|
5
2
|
extend self
|
6
3
|
VERSION = File.read( (File.dirname(__FILE__) + '/../VERSION') ).chomp
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
raise LoadError, 'Could not load the required ffi gem, install it with: gem install ffi'
|
18
|
-
end
|
19
|
-
|
20
|
-
module User32
|
21
|
-
extend FFI::Library
|
22
|
-
ffi_lib "user32"
|
23
|
-
ffi_convention :stdcall
|
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
|
30
|
-
end
|
31
|
-
|
32
|
-
module Kernel32
|
33
|
-
extend FFI::Library
|
34
|
-
ffi_lib 'kernel32'
|
35
|
-
ffi_convention :stdcall
|
36
|
-
|
37
|
-
attach_function :lock, :GlobalLock, [ :long ], :pointer
|
38
|
-
attach_function :unlock, :GlobalUnlock, [ :long ], :long
|
39
|
-
attach_function :alloc, :GlobalAlloc, [ :long, :long ], :long
|
40
|
-
end
|
41
|
-
|
42
|
-
# see http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx
|
43
|
-
def paste(_=nil)
|
44
|
-
ret = ""
|
45
|
-
if 0 != User32.open( 0 )
|
46
|
-
hclip = User32.get( CF_UNICODETEXT )
|
47
|
-
if hclip && 0 != hclip
|
48
|
-
pointer_to_data = Kernel32.lock( hclip )
|
49
|
-
data = ""
|
50
|
-
# Windows Unicode is ended by to null bytes, so get the whole string
|
51
|
-
current_byte = 0
|
52
|
-
until data.size >= 2 && data[-1].ord == 0 && data[-2].ord == 0
|
53
|
-
data << pointer_to_data.get_bytes( current_byte, 1 )
|
54
|
-
current_byte += 1
|
55
|
-
end
|
56
|
-
if RubyVersion >= 1.9
|
57
|
-
ret = data.chop.force_encoding("UTF-16LE").encode(Encoding.default_external) # TODO catch bad encodings
|
58
|
-
else # 1.8: fallback to simple CP850 encoding
|
59
|
-
require 'iconv'
|
60
|
-
utf8 = Iconv.iconv( "UTF-8", "UTF-16LE", data.chop)[0]
|
61
|
-
ret = Iconv.iconv( "CP850", "UTF-8", utf8)[0]
|
62
|
-
end
|
63
|
-
if data && 0 != data
|
64
|
-
Kernel32.unlock( hclip )
|
65
|
-
end
|
66
|
-
end
|
67
|
-
User32.close( )
|
68
|
-
end
|
69
|
-
ret || ""
|
70
|
-
end
|
71
|
-
|
72
|
-
def clear
|
73
|
-
if 0 != User32.open( 0 )
|
74
|
-
User32.empty( )
|
75
|
-
User32.close( )
|
76
|
-
end
|
77
|
-
paste
|
78
|
-
end
|
79
|
-
|
80
|
-
def copy(data_to_copy)
|
81
|
-
if RubyVersion >= 1.9 && 0 != User32.open( 0 )
|
82
|
-
User32.empty( )
|
83
|
-
data = data_to_copy.encode("UTF-16LE") # TODO catch bad encodings
|
84
|
-
data << 0 << 0
|
85
|
-
handler = Kernel32.alloc( GMEM_MOVEABLE, data.bytesize )
|
86
|
-
pointer_to_data = Kernel32.lock( handler )
|
87
|
-
pointer_to_data.put_bytes( 0, data, 0, data.bytesize )
|
88
|
-
Kernel32.unlock( handler )
|
89
|
-
User32.set( CF_UNICODETEXT, handler )
|
90
|
-
User32.close( )
|
91
|
-
else # don't touch anything
|
92
|
-
IO.popen( 'clip', 'w' ){ |input| input << data_to_copy } # depends on clip (available by default since Vista)
|
93
|
-
end
|
94
|
-
paste
|
95
|
-
end
|
96
|
-
else #non-windows
|
97
|
-
require 'open3'
|
98
|
-
|
99
|
-
if OS.mac?
|
100
|
-
CLIPBOARDS = []
|
101
|
-
WriteCommands = ['pbcopy']
|
102
|
-
ReadCommand = 'pbpaste'
|
103
|
-
else # linuX
|
104
|
-
CLIPBOARDS = %w[clipboard primary secondary]
|
105
|
-
WriteCommands = CLIPBOARDS.map{|cb| 'xclip -selection ' + cb }
|
106
|
-
ReadCommand = 'xclip -o'
|
107
|
-
|
108
|
-
# catch dependency errors
|
109
|
-
begin
|
110
|
-
Open3.popen3( "xclip -version" ){ |_, _, error|
|
111
|
-
unless error.read =~ /^xclip version/
|
112
|
-
raise LoadError
|
113
|
-
end
|
114
|
-
}
|
115
|
-
rescue Exception
|
116
|
-
raise LoadError, "clipboard -\n" +
|
117
|
-
"Could not find required prgram xclip\n" +
|
118
|
-
"You can install it (on debian/ubuntu) with sudo apt-get install xclip"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def paste(which = nil)
|
123
|
-
selection_string = if CLIPBOARDS.include?(which.to_s)
|
124
|
-
" -selection #{which}"
|
125
|
-
else
|
126
|
-
''
|
127
|
-
end
|
128
|
-
%x[#{ ReadCommand + selection_string }]
|
129
|
-
end
|
130
|
-
|
131
|
-
def clear
|
132
|
-
copy ''
|
133
|
-
end
|
134
|
-
|
135
|
-
def copy(data)
|
136
|
-
WriteCommands.each{ |cmd|
|
137
|
-
IO.popen( cmd, 'w' ){ |input| input << data }
|
138
|
-
}
|
139
|
-
paste
|
5
|
+
os = proc do
|
6
|
+
case RbConfig::CONFIG['host_os']
|
7
|
+
when /mac|darwin/ then 'mac'
|
8
|
+
when /linux|cygwin/ then 'linux'
|
9
|
+
when /mswin|mingw/ then 'windows'
|
10
|
+
when /bsd/ then 'linux'
|
11
|
+
# when /solaris|sunos/ then 'linux' # needs testing..
|
12
|
+
else
|
13
|
+
raise "You OS is not supported -> fork me"
|
140
14
|
end
|
141
15
|
end
|
142
|
-
end
|
143
16
|
|
144
|
-
|
17
|
+
require "clipboard/#{os.call}"
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Clipboard
|
2
|
+
CLIPBOARDS = %w[clipboard primary secondary]
|
3
|
+
WriteCommands = CLIPBOARDS.map{|cb| 'xclip -selection ' + cb }
|
4
|
+
ReadCommand = 'xclip -o'
|
5
|
+
|
6
|
+
# catch dependency errors
|
7
|
+
if `which xclip`.empty?
|
8
|
+
raise LoadError, "clipboard:\n" +
|
9
|
+
"Could not find required prgram xclip\n" +
|
10
|
+
"On debian/ubuntu, you can install it with: sudo apt-get install xclip"
|
11
|
+
end
|
12
|
+
|
13
|
+
def paste(which = nil)
|
14
|
+
which ||= CLIPBOARDS.first
|
15
|
+
`#{ReadCommand} -selection #{which}`
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear
|
19
|
+
copy ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy(data)
|
23
|
+
WriteCommands.each{ |cmd|
|
24
|
+
IO.popen( cmd, 'w' ){ |input| input << data }
|
25
|
+
}
|
26
|
+
paste
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Clipboard
|
2
|
+
CF_TEXT = 1
|
3
|
+
CF_UNICODETEXT = 13
|
4
|
+
GMEM_MOVEABLE = 2
|
5
|
+
|
6
|
+
# get ffi function handlers
|
7
|
+
begin
|
8
|
+
require 'ffi'
|
9
|
+
rescue LoadError
|
10
|
+
raise LoadError, 'Could not load the required ffi gem, install it with: gem install ffi'
|
11
|
+
end
|
12
|
+
|
13
|
+
module User32
|
14
|
+
extend FFI::Library
|
15
|
+
ffi_lib "user32"
|
16
|
+
ffi_convention :stdcall
|
17
|
+
|
18
|
+
attach_function :open, :OpenClipboard, [ :long ], :long
|
19
|
+
attach_function :close, :CloseClipboard, [ ], :long
|
20
|
+
attach_function :empty, :EmptyClipboard, [ ], :long
|
21
|
+
attach_function :get, :GetClipboardData, [ :long ], :long
|
22
|
+
attach_function :set, :SetClipboardData, [ :long, :long ], :long
|
23
|
+
end
|
24
|
+
|
25
|
+
module Kernel32
|
26
|
+
extend FFI::Library
|
27
|
+
ffi_lib 'kernel32'
|
28
|
+
ffi_convention :stdcall
|
29
|
+
|
30
|
+
attach_function :lock, :GlobalLock, [ :long ], :pointer
|
31
|
+
attach_function :unlock, :GlobalUnlock, [ :long ], :long
|
32
|
+
attach_function :alloc, :GlobalAlloc, [ :long, :long ], :long
|
33
|
+
end
|
34
|
+
|
35
|
+
# see http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx
|
36
|
+
def paste(_=nil)
|
37
|
+
ret = ""
|
38
|
+
if 0 != User32.open( 0 )
|
39
|
+
hclip = User32.get( CF_UNICODETEXT )
|
40
|
+
if hclip && 0 != hclip
|
41
|
+
pointer_to_data = Kernel32.lock( hclip )
|
42
|
+
data = ""
|
43
|
+
# Windows Unicode is ended by to null bytes, so get the whole string
|
44
|
+
current_byte = 0
|
45
|
+
until data.size >= 2 && data[-1].ord == 0 && data[-2].ord == 0
|
46
|
+
data << pointer_to_data.get_bytes( current_byte, 1 )
|
47
|
+
current_byte += 1
|
48
|
+
end
|
49
|
+
if RubyVersion >= 1.9
|
50
|
+
ret = data.chop.force_encoding("UTF-16LE").encode(Encoding.default_external) # TODO catch bad encodings
|
51
|
+
else # 1.8: fallback to simple CP850 encoding
|
52
|
+
require 'iconv'
|
53
|
+
utf8 = Iconv.iconv( "UTF-8", "UTF-16LE", data.chop)[0]
|
54
|
+
ret = Iconv.iconv( "CP850", "UTF-8", utf8)[0]
|
55
|
+
end
|
56
|
+
if data && 0 != data
|
57
|
+
Kernel32.unlock( hclip )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
User32.close( )
|
61
|
+
end
|
62
|
+
ret || ""
|
63
|
+
end
|
64
|
+
|
65
|
+
def clear
|
66
|
+
if 0 != User32.open( 0 )
|
67
|
+
User32.empty( )
|
68
|
+
User32.close( )
|
69
|
+
end
|
70
|
+
paste
|
71
|
+
end
|
72
|
+
|
73
|
+
def copy(data_to_copy)
|
74
|
+
if RubyVersion >= 1.9 && 0 != User32.open( 0 )
|
75
|
+
User32.empty( )
|
76
|
+
data = data_to_copy.encode("UTF-16LE") # TODO catch bad encodings
|
77
|
+
data << 0 << 0
|
78
|
+
handler = Kernel32.alloc( GMEM_MOVEABLE, data.bytesize )
|
79
|
+
pointer_to_data = Kernel32.lock( handler )
|
80
|
+
pointer_to_data.put_bytes( 0, data, 0, data.bytesize )
|
81
|
+
Kernel32.unlock( handler )
|
82
|
+
User32.set( CF_UNICODETEXT, handler )
|
83
|
+
User32.close( )
|
84
|
+
else # don't touch anything
|
85
|
+
IO.popen( 'clip', 'w' ){ |input| input << data_to_copy } # depends on clip (available by default since Vista)
|
86
|
+
end
|
87
|
+
paste
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
|
+
|
3
|
+
describe Clipboard do
|
4
|
+
it "has a VERSION" do
|
5
|
+
Clipboard::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
6
|
+
end
|
7
|
+
|
8
|
+
it "can copy & paste" do
|
9
|
+
Clipboard.copy("FOO\nBAR")
|
10
|
+
Clipboard.paste.should == "FOO\nBAR"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns data on copy" do
|
14
|
+
Clipboard.copy('xxx').should == 'xxx'
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 4
|
9
|
+
version: 0.9.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jan Lelis
|
@@ -14,38 +14,32 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-16 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
name: zucker
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 8
|
30
|
-
version: "8"
|
31
|
-
type: :runtime
|
32
|
-
version_requirements: *id001
|
19
|
+
dependencies: []
|
20
|
+
|
33
21
|
description: Access the clipboard on all systems (Clipboard.copy & Clipboard.paste).
|
34
22
|
email: mail@janlelis.de
|
35
23
|
executables: []
|
36
24
|
|
37
25
|
extensions: []
|
38
26
|
|
39
|
-
extra_rdoc_files:
|
40
|
-
|
41
|
-
- README.rdoc
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
42
29
|
files:
|
30
|
+
- lib/clipboard.rb
|
31
|
+
- lib/clipboard/mac.rb
|
32
|
+
- lib/clipboard/linux.rb
|
33
|
+
- lib/clipboard/windows.rb
|
34
|
+
- spec/spec_helper.rb
|
35
|
+
- spec/clipboard_spec.rb
|
36
|
+
- Gemfile
|
37
|
+
- Rakefile
|
43
38
|
- LICENSE
|
39
|
+
- Gemfile.lock
|
44
40
|
- README.rdoc
|
45
|
-
- Rakefile
|
46
41
|
- VERSION
|
47
42
|
- clipboard.gemspec
|
48
|
-
- lib/clipboard.rb
|
49
43
|
has_rdoc: true
|
50
44
|
homepage: http://github.com/janlelis/clipboard
|
51
45
|
licenses: []
|