clipboard 0.9.0 → 0.9.1
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/README.rdoc +5 -5
- data/VERSION +1 -1
- data/clipboard.gemspec +2 -2
- data/lib/clipboard.rb +31 -14
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -16,15 +16,15 @@ On Linux, you can choose, from which clipboard you want to +paste+, default is P
|
|
16
16
|
+copy+ copies to all clipboards in Clipboard::CLIPBOARDS.
|
17
17
|
|
18
18
|
==== Windows Encoding note
|
19
|
-
|
20
|
-
|
19
|
+
If you paste with 1.9, the Clipboard encoding will be translated to your <tt>Encoding.default_external</tt>.
|
20
|
+
|
21
|
+
If you paste with 1.8, it will fallback to CP850 encoding.
|
22
|
+
Copying with 1.8 will fallback to the +clip+ utility, which is installed by default since Vista
|
21
23
|
|
22
24
|
=== Non-gem requirements
|
23
|
-
* *Linux*: +xclip
|
24
|
-
* *Windows*: +clip+ (installed by default since Vista)
|
25
|
+
* *Linux*: +xclip+, you can install it on debian/ubuntu with <tt>sudo apt-get install xclip</tt>
|
25
26
|
|
26
27
|
=== Todo
|
27
|
-
* Don't depend on +clip+
|
28
28
|
* Don't depend on +xclip+
|
29
29
|
|
30
30
|
Feel free to report bugs or to implement one of the Todo entries ;)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.1
|
data/clipboard.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{clipboard}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jan Lelis"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-14}
|
13
13
|
s.description = %q{Access the clipboard on all systems (Clipboard.copy & Clipboard.paste)}
|
14
14
|
s.email = %q{mail@janlelis.de}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/clipboard.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'zucker/os'
|
2
2
|
require 'zucker/version'
|
3
|
-
|
4
|
-
require 'stringio'
|
3
|
+
|
5
4
|
require File.expand_path '../../version', __FILE__
|
6
5
|
|
7
6
|
module Clipboard
|
8
7
|
if OS.windows?
|
9
|
-
WriteCommands = ['clip']
|
10
8
|
CF_TEXT = 1
|
11
9
|
CF_UNICODETEXT = 13
|
10
|
+
GMEM_MOVEABLE = 2
|
12
11
|
|
13
12
|
# get ffi function handlers
|
14
13
|
require 'ffi'
|
@@ -22,6 +21,7 @@ module Clipboard
|
|
22
21
|
attach_function :close, :CloseClipboard, [ ], :long
|
23
22
|
attach_function :empty, :EmptyClipboard, [ ], :long
|
24
23
|
attach_function :get, :GetClipboardData, [ :long ], :long
|
24
|
+
attach_function :set, :SetClipboardData, [ :long, :long ], :long
|
25
25
|
end
|
26
26
|
|
27
27
|
module Kernel32
|
@@ -31,9 +31,9 @@ module Clipboard
|
|
31
31
|
|
32
32
|
attach_function :lock, :GlobalLock, [ :long ], :pointer
|
33
33
|
attach_function :unlock, :GlobalUnlock, [ :long ], :long
|
34
|
+
attach_function :alloc, :GlobalAlloc, [ :long, :long ], :long
|
34
35
|
end
|
35
36
|
|
36
|
-
# paste & clear
|
37
37
|
# see http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx
|
38
38
|
def self.paste(_=nil)
|
39
39
|
ret = ""
|
@@ -49,7 +49,7 @@ module Clipboard
|
|
49
49
|
current_byte += 1
|
50
50
|
end
|
51
51
|
if RubyVersion >= 1.9
|
52
|
-
ret = data.chop.force_encoding("UTF-16LE").encode(
|
52
|
+
ret = data.chop.force_encoding("UTF-16LE").encode(Encoding.default_external) # TODO catch bad encodings
|
53
53
|
else # 1.8: fallback to simple CP850 encoding
|
54
54
|
require 'iconv'
|
55
55
|
utf8 = Iconv.iconv( "UTF-8", "UTF-16LE", data.chop)[0]
|
@@ -65,11 +65,29 @@ module Clipboard
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def self.clear
|
68
|
-
User32.open( 0 )
|
68
|
+
if 0 != User32.open( 0 )
|
69
|
+
User32.empty( )
|
70
|
+
User32.close( )
|
71
|
+
end
|
72
|
+
paste
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.copy(data_to_copy)
|
76
|
+
if RubyVersion >= 1.9 && 0 != User32.open( 0 )
|
69
77
|
User32.empty( )
|
78
|
+
data = data_to_copy.encode("UTF-16LE") # TODO catch bad encodings
|
79
|
+
data << 0 << 0
|
80
|
+
handler = Kernel32.alloc( GMEM_MOVEABLE, data.bytesize )
|
81
|
+
pointer_to_data = Kernel32.lock( handler )
|
82
|
+
pointer_to_data.put_bytes( 0, data, 0, data.bytesize )
|
83
|
+
Kernel32.unlock( handler )
|
84
|
+
User32.set( CF_UNICODETEXT, handler )
|
70
85
|
User32.close( )
|
71
|
-
|
86
|
+
else # don't touch anything
|
87
|
+
IO.popen( 'clip', 'w' ){ |input| input << data_to_copy } # depends on clip (available by default since Vista)
|
72
88
|
end
|
89
|
+
paste
|
90
|
+
end
|
73
91
|
else #non-windows
|
74
92
|
require 'open3'
|
75
93
|
|
@@ -108,14 +126,13 @@ module Clipboard
|
|
108
126
|
def self.clear
|
109
127
|
copy ''
|
110
128
|
end
|
111
|
-
end
|
112
129
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
130
|
+
def self.copy(data)
|
131
|
+
WriteCommands.each{ |cmd|
|
132
|
+
IO.popen( cmd, 'w' ){ |input| input << data }
|
133
|
+
}
|
134
|
+
paste
|
135
|
+
end
|
119
136
|
end
|
120
137
|
end
|
121
138
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clipboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 57
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 1
|
10
|
+
version: 0.9.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan Lelis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-14 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|