clipboard 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,31 @@
1
1
  = clipboard
2
- Access the clipboard and do not care if the OS is linux, mac or windows.
2
+ Access the clipboard and do not care if the OS is Linux, MacOS or Windows.
3
3
 
4
4
  === Usage
5
- You have <tt>Clipboard.write</tt> [+copy+],
5
+ You have <tt>Clipboard.copy</tt>,
6
6
 
7
- <tt>Clipboard.read</tt> [+paste+] and
7
+ <tt>Clipboard.paste</tt> and
8
8
 
9
9
  <tt>Clipboard.clear</tt>
10
10
 
11
11
  Have fun ;)
12
12
 
13
- === Requirements
14
- * *Linux*: +xclip+ (you can install it on ubuntu with <tt>sudo apt-get install xclip</tt>)
15
- * *Windows*: <tt>win32-clipboard</tt> gem
16
- * +Zucker+ gem
13
+ ==== Multiple clipboards
14
+ On Linux, you can choose, from which clipboard you want to +paste+, default is PRIMARY.
17
15
 
18
- === TODO
19
- * Don't depend on +xclip+
20
- * Don't depend on the <tt>win32-clipboard</tt> gem (or fix the 1.9 issues with the gem)
16
+ +copy+ copies to all clipboards in Clipboard::CLIPBOARDS.
21
17
 
22
- Feel free to report bugs or to implement one of the above features ;)
18
+ === Non-gem requirements
19
+ * *Linux*: +xclip+ (you can install it on debian/ubuntu with <tt>sudo apt-get install xclip</tt>)
20
+ * *Windows*: +clip+ (installed by default since Vista)
23
21
 
24
- == Copyright
22
+ === Bugs / TODO
23
+ * Fix 1.9 and Encoding issues on Windows
24
+ * Don't depend on +xclip+ ?
25
+
26
+ Feel free to report bugs or to implement one of the TODO entries ;)
27
+
28
+ === Copyright
25
29
  Copyright (c) 2010 Jan Lelis, http://rbjl.net, released under the MIT license
30
+
31
+ J-_-L
data/Rakefile CHANGED
@@ -6,14 +6,13 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "clipboard"
8
8
  gem.summary = %Q{Access the clipboard on all systems}
9
- gem.description = %Q{Access the clipboard on all systems (Clipboard.write & Clipboard.read)}
9
+ gem.description = %Q{Access the clipboard on all systems (Clipboard.copy & Clipboard.paste)}
10
10
  gem.email = "mail@janlelis.de"
11
11
  gem.homepage = "http://github.com/janlelis/clipboard"
12
12
  gem.authors = ["Jan Lelis"]
13
13
  gem.add_development_dependency "jeweler", ">= 0"
14
14
  gem.add_dependency('zucker', '>= 4')
15
15
  gem.requirements << 'on linux (or other X), you need xclip'
16
- gem.requirements << 'on windows, you need the win32-clipboard gem'
17
16
 
18
17
  end
19
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.8.0
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{clipboard}
8
- s.version = "0.7.0"
8
+ s.version = "0.8.0"
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-01}
13
- s.description = %q{Access the clipboard on all systems (Clipboard.write & Clipboard.read)}
12
+ s.date = %q{2010-10-03}
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 = [
16
16
  "LICENSE",
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "clipboard.gemspec",
28
- "doc/Clipboard||= Module.new.html",
28
+ "doc/Clipboard.html",
29
29
  "doc/README_rdoc.html",
30
30
  "doc/created.rid",
31
31
  "doc/images/brick.png",
@@ -61,7 +61,7 @@ Gem::Specification.new do |s|
61
61
  s.homepage = %q{http://github.com/janlelis/clipboard}
62
62
  s.rdoc_options = ["--charset=UTF-8"]
63
63
  s.require_paths = ["lib"]
64
- s.requirements = ["on linux (or other X), you need xclip", "on windows, you need the win32-clipboard gem"]
64
+ s.requirements = ["on linux (or other X), you need xclip"]
65
65
  s.rubygems_version = %q{1.3.7}
66
66
  s.summary = %q{Access the clipboard on all systems}
67
67
 
@@ -5,7 +5,7 @@
5
5
  <head>
6
6
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
7
 
8
- <title>Module: Clipboard||= Module.new</title>
8
+ <title>Module: Clipboard</title>
9
9
 
10
10
  <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
11
 
@@ -66,13 +66,11 @@
66
66
 
67
67
  <li><a href="#method-c-clear">::clear</a></li>
68
68
 
69
- <li><a href="#method-c-read">::read</a></li>
69
+ <li><a href="#method-c-copy">::copy</a></li>
70
70
 
71
- <li><a href="#method-c-read">::read</a></li>
71
+ <li><a href="#method-c-paste">::paste</a></li>
72
72
 
73
- <li><a href="#method-c-write">::write</a></li>
74
-
75
- <li><a href="#method-c-write">::write</a></li>
73
+ <li><a href="#method-c-paste">::paste</a></li>
76
74
 
77
75
  </ul>
78
76
  </div>
@@ -110,7 +108,7 @@
110
108
 
111
109
  <ul class="link-list">
112
110
 
113
- <li><a href="./Clipboard||= Module.new.html">Clipboard||= Module.new</a></li>
111
+ <li><a href="./Clipboard.html">Clipboard</a></li>
114
112
 
115
113
  </ul>
116
114
  <div id="no-class-search-results" style="display: none;">No matching classes.</div>
@@ -121,7 +119,7 @@
121
119
  </div>
122
120
 
123
121
  <div id="documentation">
124
- <h1 class="module">Clipboard||= Module.new</h1>
122
+ <h1 class="module">Clipboard</h1>
125
123
 
126
124
  <div id="description">
127
125
 
@@ -133,7 +131,17 @@
133
131
  <h3 class="section-header">Constants</h3>
134
132
  <dl>
135
133
 
136
- <dt><a name="WriteCommand">WriteCommand</a></dt>
134
+ <dt><a name="WriteCommands">WriteCommands</a></dt>
135
+
136
+ <dd class="description"></dd>
137
+
138
+
139
+ <dt><a name="CF_TEXT">CF_TEXT</a></dt>
140
+
141
+ <dd class="description"></dd>
142
+
143
+
144
+ <dt><a name="WriteCommands">WriteCommands</a></dt>
137
145
 
138
146
  <dd class="description"></dd>
139
147
 
@@ -143,7 +151,12 @@
143
151
  <dd class="description"></dd>
144
152
 
145
153
 
146
- <dt><a name="WriteCommand">WriteCommand</a></dt>
154
+ <dt><a name="Clipboards">Clipboards</a></dt>
155
+
156
+ <dd class="description"></dd>
157
+
158
+
159
+ <dt><a name="WriteCommands">WriteCommands</a></dt>
147
160
 
148
161
  <dd class="description"></dd>
149
162
 
@@ -186,11 +199,10 @@
186
199
  <div class="method-source-code"
187
200
  id="clear-source">
188
201
  <pre>
189
- <span class="ruby-comment cmt"># File lib/clipboard.rb, line 43</span>
190
- 43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
191
- 44: <span class="ruby-constant">Win32</span><span class="ruby-operator">::</span><span class="ruby-constant">Clipboard</span>.<span class="ruby-identifier">empty</span>
192
- 45: <span class="ruby-constant">Win32</span><span class="ruby-operator">::</span><span class="ruby-constant">Clipboard</span>.<span class="ruby-identifier">data</span>
193
- 46: <span class="ruby-keyword kw">end</span></pre>
202
+ <span class="ruby-comment cmt"># File lib/clipboard.rb, line 78</span>
203
+ 78: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">clear</span>
204
+ 79: <span class="ruby-identifier">copy</span> <span class="ruby-value str">''</span>
205
+ 80: <span class="ruby-keyword kw">end</span></pre>
194
206
  </div>
195
207
 
196
208
  </div>
@@ -221,44 +233,13 @@
221
233
  <div class="method-source-code"
222
234
  id="clear-source">
223
235
  <pre>
224
- <span class="ruby-comment cmt"># File lib/clipboard.rb, line 28</span>
225
- 28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
226
- 29: <span class="ruby-identifier">write</span> <span class="ruby-value str">''</span>
227
- 30: <span class="ruby-keyword kw">end</span></pre>
228
- </div>
229
-
230
- </div>
231
-
232
-
233
-
234
-
235
- </div>
236
-
237
-
238
- <div id="read-method" class="method-detail ">
239
- <a name="method-c-read"></a>
240
-
241
- <div class="method-heading">
242
-
243
- <span class="method-name">read</span><span
244
- class="method-args">()</span>
245
- <span class="method-click-advice">click to toggle source</span>
246
-
247
- </div>
248
-
249
- <div class="method-description">
250
-
251
-
252
-
253
-
254
-
255
- <div class="method-source-code"
256
- id="read-source">
257
- <pre>
258
- <span class="ruby-comment cmt"># File lib/clipboard.rb, line 24</span>
259
- 24: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read</span>
260
- 25: <span class="ruby-node">%[#{ ReadCommand }]</span>
261
- 26: <span class="ruby-keyword kw">end</span></pre>
236
+ <span class="ruby-comment cmt"># File lib/clipboard.rb, line 42</span>
237
+ 42: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">clear</span>
238
+ 43: <span class="ruby-ivar">@open</span>[<span class="ruby-value">0</span>]
239
+ 44: <span class="ruby-ivar">@empty</span>[]
240
+ 45: <span class="ruby-ivar">@close</span>[]
241
+ 46: <span class="ruby-identifier">paste</span>
242
+ 47: <span class="ruby-keyword kw">end</span></pre>
262
243
  </div>
263
244
 
264
245
  </div>
@@ -269,13 +250,13 @@
269
250
  </div>
270
251
 
271
252
 
272
- <div id="read-method" class="method-detail ">
273
- <a name="method-c-read"></a>
253
+ <div id="copy-method" class="method-detail ">
254
+ <a name="method-c-copy"></a>
274
255
 
275
256
  <div class="method-heading">
276
257
 
277
- <span class="method-name">read</span><span
278
- class="method-args">()</span>
258
+ <span class="method-name">copy</span><span
259
+ class="method-args">(data)</span>
279
260
  <span class="method-click-advice">click to toggle source</span>
280
261
 
281
262
  </div>
@@ -287,12 +268,15 @@
287
268
 
288
269
 
289
270
  <div class="method-source-code"
290
- id="read-source">
271
+ id="copy-source">
291
272
  <pre>
292
- <span class="ruby-comment cmt"># File lib/clipboard.rb, line 39</span>
293
- 39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read</span>
294
- 40: <span class="ruby-constant">Win32</span><span class="ruby-operator">::</span><span class="ruby-constant">Clipboard</span>.<span class="ruby-identifier">data</span>
295
- 41: <span class="ruby-keyword kw">end</span></pre>
273
+ <span class="ruby-comment cmt"># File lib/clipboard.rb, line 83</span>
274
+ 83: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">copy</span>(<span class="ruby-identifier">data</span>)
275
+ 84: <span class="ruby-constant">WriteCommands</span>.<span class="ruby-identifier">each</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">cmd</span><span class="ruby-operator">|</span>
276
+ 85: <span class="ruby-constant">IO</span>.<span class="ruby-identifier">popen</span>( <span class="ruby-identifier">cmd</span>, <span class="ruby-value str">'w'</span> ){ <span class="ruby-operator">|</span><span class="ruby-identifier">input</span><span class="ruby-operator">|</span> <span class="ruby-identifier">input</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">data</span> }
277
+ 86: }
278
+ 87: <span class="ruby-identifier">paste</span>
279
+ 88: <span class="ruby-keyword kw">end</span></pre>
296
280
  </div>
297
281
 
298
282
  </div>
@@ -303,13 +287,13 @@
303
287
  </div>
304
288
 
305
289
 
306
- <div id="write-method" class="method-detail ">
307
- <a name="method-c-write"></a>
290
+ <div id="paste-method" class="method-detail ">
291
+ <a name="method-c-paste"></a>
308
292
 
309
293
  <div class="method-heading">
310
294
 
311
- <span class="method-name">write</span><span
312
- class="method-args">(data)</span>
295
+ <span class="method-name">paste</span><span
296
+ class="method-args">(which = nil)</span>
313
297
  <span class="method-click-advice">click to toggle source</span>
314
298
 
315
299
  </div>
@@ -321,13 +305,17 @@
321
305
 
322
306
 
323
307
  <div class="method-source-code"
324
- id="write-source">
308
+ id="paste-source">
325
309
  <pre>
326
- <span class="ruby-comment cmt"># File lib/clipboard.rb, line 34</span>
327
- 34: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write</span>(<span class="ruby-identifier">data</span>)
328
- 35: <span class="ruby-constant">Win32</span><span class="ruby-operator">::</span><span class="ruby-constant">Clipboard</span>.<span class="ruby-identifier">set_data</span>( <span class="ruby-identifier">data</span> )
329
- 36: <span class="ruby-constant">Win32</span><span class="ruby-operator">::</span><span class="ruby-constant">Clipboard</span>.<span class="ruby-identifier">data</span>
330
- 37: <span class="ruby-keyword kw">end</span></pre>
310
+ <span class="ruby-comment cmt"># File lib/clipboard.rb, line 69</span>
311
+ 69: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">paste</span>(<span class="ruby-identifier">which</span> = <span class="ruby-keyword kw">nil</span>)
312
+ 70: <span class="ruby-identifier">selection_string</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Clipboards</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">which</span>.<span class="ruby-identifier">to_s</span>)
313
+ 71: <span class="ruby-node">&quot; -selection #{which}&quot;</span>
314
+ 72: <span class="ruby-keyword kw">else</span>
315
+ 73: <span class="ruby-value str">''</span>
316
+ 74: <span class="ruby-keyword kw">end</span>
317
+ 75: <span class="ruby-node">%[#{ ReadCommand + selection_string }]</span>
318
+ 76: <span class="ruby-keyword kw">end</span></pre>
331
319
  </div>
332
320
 
333
321
  </div>
@@ -338,31 +326,44 @@
338
326
  </div>
339
327
 
340
328
 
341
- <div id="write-method" class="method-detail ">
342
- <a name="method-c-write"></a>
329
+ <div id="paste-method" class="method-detail ">
330
+ <a name="method-c-paste"></a>
343
331
 
344
332
  <div class="method-heading">
345
333
 
346
- <span class="method-name">write</span><span
347
- class="method-args">(data)</span>
334
+ <span class="method-name">paste</span><span
335
+ class="method-args">(_=nil)</span>
348
336
  <span class="method-click-advice">click to toggle source</span>
349
337
 
350
338
  </div>
351
339
 
352
340
  <div class="method-description">
353
341
 
354
-
342
+ <p>
343
+ paste &amp; clear inspired by segment7.net and <a
344
+ href="http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx">www.codeproject.com/KB/clipboard/archerclipboard1.aspx</a>
345
+ does not work on 1.9, has probably something to do with utf8 strings ?
346
+ </p>
355
347
 
356
348
 
357
349
 
358
350
  <div class="method-source-code"
359
- id="write-source">
351
+ id="paste-source">
360
352
  <pre>
361
- <span class="ruby-comment cmt"># File lib/clipboard.rb, line 19</span>
362
- 19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">write</span>(<span class="ruby-identifier">data</span>)
363
- 20: <span class="ruby-constant">Open3</span>.<span class="ruby-identifier">popen3</span>( <span class="ruby-constant">WriteCommand</span> ){ <span class="ruby-operator">|</span><span class="ruby-identifier">input</span>, <span class="ruby-identifier">_</span>, <span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-identifier">input</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">data</span> }
364
- 21: <span class="ruby-identifier">read</span> <span class="ruby-comment cmt"># or true or nil?</span>
365
- 22: <span class="ruby-keyword kw">end</span></pre>
353
+ <span class="ruby-comment cmt"># File lib/clipboard.rb, line 28</span>
354
+ 28: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">paste</span>(<span class="ruby-identifier">_</span>=<span class="ruby-keyword kw">nil</span>)
355
+ 29: <span class="ruby-identifier">data</span> = <span class="ruby-value str">&quot;&quot;</span>
356
+ 30: <span class="ruby-keyword kw">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">!=</span> <span class="ruby-ivar">@open</span>[ <span class="ruby-value">0</span> ]
357
+ 31: <span class="ruby-identifier">hclip</span> = <span class="ruby-ivar">@get</span>[ <span class="ruby-constant">CF_TEXT</span> ]
358
+ 32: <span class="ruby-keyword kw">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">hclip</span>
359
+ 33: <span class="ruby-keyword kw">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">data</span> = <span class="ruby-ivar">@lock</span>[ <span class="ruby-identifier">hclip</span> ]
360
+ 34: <span class="ruby-ivar">@unlock</span>[ <span class="ruby-identifier">hclip</span> ]
361
+ 35: <span class="ruby-keyword kw">end</span>
362
+ 36: <span class="ruby-keyword kw">end</span>
363
+ 37: <span class="ruby-ivar">@close</span>[]
364
+ 38: <span class="ruby-keyword kw">end</span>
365
+ 39: <span class="ruby-identifier">data</span> <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;&quot;</span>
366
+ 40: <span class="ruby-keyword kw">end</span></pre>
366
367
  </div>
367
368
 
368
369
  </div>
@@ -6,7 +6,7 @@
6
6
  <head>
7
7
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8
8
 
9
- <title>File: README.rdoc [clipboard 0.6.0
9
+ <title>File: README.rdoc [clipboard 0.7.0
10
10
  ]</title>
11
11
 
12
12
  <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet" />
@@ -61,7 +61,7 @@
61
61
 
62
62
  <ul class="link-list">
63
63
 
64
- <li><a href="./Clipboard||= Module.new.html">Clipboard||= Module.new</a></li>
64
+ <li><a href="./Clipboard.html">Clipboard</a></li>
65
65
 
66
66
  </ul>
67
67
  <div id="no-class-search-results" style="display: none;">No matching classes.</div>
@@ -74,14 +74,14 @@
74
74
  <div id="documentation">
75
75
  <h1>clipboard</h1>
76
76
  <p>
77
- Access the clipboard and do not care if the OS is linux, mac or windows.
77
+ Access the clipboard and do not care if the OS is Linux, MacOS or Windows.
78
78
  </p>
79
79
  <h3>Usage</h3>
80
80
  <p>
81
- You have <tt>Clipboard.write</tt> [<tt>copy</tt>],
81
+ You have <tt>Clipboard.copy</tt>,
82
82
  </p>
83
83
  <p>
84
- <tt>Clipboard.read</tt> [<tt>paste</tt>] and
84
+ <tt>Clipboard.paste</tt> and
85
85
  </p>
86
86
  <p>
87
87
  <tt>Clipboard.clear</tt>
@@ -89,50 +89,47 @@ You have <tt>Clipboard.write</tt> [<tt>copy</tt>],
89
89
  <p>
90
90
  Have fun ;)
91
91
  </p>
92
- <h3>Requirements</h3>
93
- <ul>
94
- <li><p>
95
- <b>Linux</b>: <tt>xclip</tt> (you can install it on ubuntu with <tt>sudo
96
- apt-get install xclip</tt>)
97
- </p>
98
- </li>
99
- <li><p>
100
- <b>Windows</b>: <tt>win32-clipboard</tt> gem
92
+ <h4>Multiple clipboards</h4>
93
+ <p>
94
+ On Linux, you can choose, from which clipboard you want to <tt>paste</tt>,
95
+ default is PRIMARY.
101
96
  </p>
102
- </li>
103
- <li><p>
104
- <tt>Zucker</tt> gem
97
+ <p>
98
+ <tt>copy</tt> copies to all clipboards in Clipboard::CLIPBOARDS.
105
99
  </p>
106
- </li>
107
- </ul>
108
- <h3>TODO</h3>
100
+ <h3>Non-gem requirements</h3>
109
101
  <ul>
110
102
  <li><p>
111
- Automatically require the <tt>win32-clipboard</tt> gem - but only on
112
- windows!
103
+ <b>Linux</b>: <tt>xclip</tt> (you can install it on debian/ubuntu with
104
+ <tt>sudo apt-get install xclip</tt>)
113
105
  </p>
114
106
  </li>
115
107
  <li><p>
116
- Don&#8217;t depend on <tt>xclip</tt>
108
+ <b>Windows</b>: <tt>clip</tt> (installed by default since Vista)
117
109
  </p>
118
110
  </li>
111
+ </ul>
112
+ <h3>Bugs / TODO</h3>
113
+ <ul>
119
114
  <li><p>
120
- Don&#8217;t depend on the <tt>win32-clipboard</tt> gem (or fix the 1.9
121
- issues with the gem)
115
+ Fix 1.9 and Encoding issues on Windows
122
116
  </p>
123
117
  </li>
124
118
  <li><p>
125
- Error management?
119
+ Don&#8217;t depend on <tt>xclip</tt> ?
126
120
  </p>
127
121
  </li>
128
122
  </ul>
129
123
  <p>
130
- Feel free to report bugs or to implement one of the above features ;)
124
+ Feel free to report bugs or to implement one of the TODO entries ;)
131
125
  </p>
132
- <h2>Copyright</h2>
126
+ <h3>Copyright</h3>
133
127
  <p>
134
128
  Copyright &#169; 2010 Jan Lelis, <a href="http://rbjl.net">rbjl.net</a>,
135
129
  released under the MIT license
130
+ </p>
131
+ <p>
132
+ J-_-L
136
133
  </p>
137
134
 
138
135
  </div>
@@ -1,3 +1,3 @@
1
- Fri, 01 Oct 2010 14:55:01 +0200
2
- README.rdoc Fri, 01 Oct 2010 14:53:14 +0200
3
- lib/clipboard.rb Fri, 01 Oct 2010 13:09:46 +0200
1
+ Sun, 03 Oct 2010 06:06:40 +0200
2
+ README.rdoc Sun, 03 Oct 2010 06:03:31 +0200
3
+ lib/clipboard.rb Sun, 03 Oct 2010 06:06:25 +0200
@@ -6,7 +6,7 @@
6
6
  <head>
7
7
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8
8
 
9
- <title>clipboard 0.6.0
9
+ <title>clipboard 0.7.0
10
10
  </title>
11
11
 
12
12
  <link type="text/css" media="screen" href="rdoc.css" rel="stylesheet" />
@@ -20,11 +20,11 @@
20
20
  <body class="indexpage">
21
21
 
22
22
 
23
- <h1>clipboard 0.6.0
23
+ <h1>clipboard 0.7.0
24
24
  </h1>
25
25
 
26
26
 
27
- <p>This is the API documentation for 'clipboard 0.6.0
27
+ <p>This is the API documentation for 'clipboard 0.7.0
28
28
  '.</p>
29
29
 
30
30
 
@@ -41,24 +41,22 @@
41
41
  <h2 id="classes">Classes/Modules</h2>
42
42
  <ul>
43
43
 
44
- <li class="module"><a href="Clipboard||= Module.new.html">Clipboard||= Module.new</a></li>
44
+ <li class="module"><a href="Clipboard.html">Clipboard</a></li>
45
45
 
46
46
  </ul>
47
47
 
48
48
  <h2 id="methods">Methods</h2>
49
49
  <ul>
50
50
 
51
- <li><a href="Clipboard||= Module.new.html#method-c-clear">::clear &mdash; Clipboard||= Module.new</a></li>
51
+ <li><a href="Clipboard.html#method-c-clear">::clear &mdash; Clipboard</a></li>
52
52
 
53
- <li><a href="Clipboard||= Module.new.html#method-c-clear">::clear &mdash; Clipboard||= Module.new</a></li>
53
+ <li><a href="Clipboard.html#method-c-clear">::clear &mdash; Clipboard</a></li>
54
54
 
55
- <li><a href="Clipboard||= Module.new.html#method-c-read">::read &mdash; Clipboard||= Module.new</a></li>
55
+ <li><a href="Clipboard.html#method-c-copy">::copy &mdash; Clipboard</a></li>
56
56
 
57
- <li><a href="Clipboard||= Module.new.html#method-c-read">::read &mdash; Clipboard||= Module.new</a></li>
57
+ <li><a href="Clipboard.html#method-c-paste">::paste &mdash; Clipboard</a></li>
58
58
 
59
- <li><a href="Clipboard||= Module.new.html#method-c-write">::write &mdash; Clipboard||= Module.new</a></li>
60
-
61
- <li><a href="Clipboard||= Module.new.html#method-c-write">::write &mdash; Clipboard||= Module.new</a></li>
59
+ <li><a href="Clipboard.html#method-c-paste">::paste &mdash; Clipboard</a></li>
62
60
 
63
61
  </ul>
64
62
 
@@ -6,7 +6,7 @@
6
6
  <head>
7
7
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8
8
 
9
- <title>File: clipboard.rb [clipboard 0.6.0
9
+ <title>File: clipboard.rb [clipboard 0.7.0
10
10
  ]</title>
11
11
 
12
12
  <link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet" />
@@ -25,7 +25,7 @@
25
25
  <div id="metadata">
26
26
  <dl>
27
27
  <dt class="modified-date">Last Modified</dt>
28
- <dd class="modified-date">2010-10-01 13:09:46 +0200</dd>
28
+ <dd class="modified-date">2010-10-03 06:06:25 +0200</dd>
29
29
 
30
30
 
31
31
  <dt class="requires">Requires</dt>
@@ -36,9 +36,11 @@
36
36
 
37
37
  <li>zucker/alias_for</li>
38
38
 
39
- <li>open3</li>
39
+ <li>stringio</li>
40
+
41
+ <li>Win32API</li>
40
42
 
41
- <li>win32/clipboard</li>
43
+ <li>open3</li>
42
44
 
43
45
  </ul>
44
46
  </dd>
@@ -1,90 +1,91 @@
1
1
  require 'zucker/os'
2
2
  require 'zucker/alias_for'
3
3
  require 'stringio'
4
-
5
4
  require File.expand_path '../../version', __FILE__
6
5
 
7
- def capture_stderr
8
- capture = StringIO.new
9
- restore, $stderr = $stderr, capture
10
- yield
11
- $stderr = restore
12
- capture.string
13
- end
6
+ module Clipboard
7
+ if OS.windows?
8
+ WriteCommands = ['clip']
9
+ CF_TEXT = 1
10
+
11
+ require 'Win32API'
12
+ # init api handlers
13
+ @open = Win32API.new("user32", "OpenClipboard",['L'],'L')
14
+ @close = Win32API.new("user32", "CloseClipboard",[],'L')
15
+ @empty = Win32API.new("user32", "EmptyClipboard",[],'L')
16
+ @get = Win32API.new("user32", "GetClipboardData", ['L'], 'L')
17
+ @lock = Win32API.new("kernel32", "GlobalLock", ['L'], 'P')
18
+ @unlock = Win32API.new("kernel32", "GlobalUnlock", ['L'], 'L')
19
+ instance_variables.each{ |handler|
20
+ instance_variable_get(handler).instance_eval do
21
+ alias [] call
22
+ end
23
+ }
24
+
25
+ # paste & clear
26
+ # inspired by segment7.net and http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx
27
+ # does not work on 1.9, has probably something to do with utf8 strings ?
28
+ def self.paste(_=nil)
29
+ data = ""
30
+ if 0 != @open[ 0 ]
31
+ hclip = @get[ CF_TEXT ]
32
+ if 0 != hclip
33
+ if 0 != data = @lock[ hclip ]
34
+ @unlock[ hclip ]
35
+ end
36
+ end
37
+ @close[]
38
+ end
39
+ data || ""
40
+ end
14
41
 
15
- class << Clipboard ||= Module.new
16
- case # OS
17
- when OS.linux? || OS.mac? || OS.bsd? || OS.posix?
42
+ def self.clear
43
+ @open[0]
44
+ @empty[]
45
+ @close[]
46
+ paste
47
+ end
48
+ else #non-windows
18
49
  require 'open3'
19
50
 
20
51
  if OS.mac?
21
- WriteCommand = 'pbcopy'
52
+ WriteCommands = ['pbcopy']
22
53
  ReadCommand = 'pbpaste'
23
54
  else # linuX
24
- WriteCommand = 'xclip'
55
+ Clipboards = %w[clipboard primary secondary]
56
+ WriteCommands = Clipboards.map{|cb| 'xclip -selection ' + cb }
25
57
  ReadCommand = 'xclip -o'
26
58
 
27
59
  # catch dependency errors
28
60
  Open3.popen3( "xclip -version" ){ |_, _, error|
29
61
  unless error.read =~ /^xclip version/
30
- raise "clipboard -\n" +
31
- "Could not find required prgram xclip\n" +
62
+ raise "clipboard -\n" +
63
+ "Could not find required prgram xclip\n" +
32
64
  "You can install it (on debian/ubuntu) with sudo apt-get install xclip"
33
65
  end
34
66
  }
35
67
  end
36
68
 
37
- def write(data)
38
- Open3.popen3( WriteCommand ){ |input, _, _|
39
- input << data
40
- }
41
- read # or true or nil?
69
+ def self.paste(which = nil)
70
+ selection_string = if Clipboards.include?(which.to_s)
71
+ " -selection #{which}"
72
+ else
73
+ ''
74
+ end
75
+ %x[#{ ReadCommand + selection_string }]
42
76
  end
43
77
 
44
- def read
45
- %x[#{ ReadCommand }]
46
- end
47
-
48
- def clear
49
- write ''
50
- end
51
- when OS.windows?
52
- begin
53
- require 'win32/clipboard'
54
- rescue LoadError
55
- raise "clipboard -\n" +
56
- "Could not load the required win32-clipboard gem\n"
57
- "You can install it with gem install win32-clipboard"
78
+ def self.clear
79
+ copy ''
58
80
  end
59
-
60
- def write(data)
61
- Win32::Clipboard.set_data( data )
62
- Win32::Clipboard.data
63
- end
64
-
65
- def read
66
- Win32::Clipboard.data
67
- end
68
-
69
- def clear
70
- Win32::Clipboard.empty
71
- Win32::Clipboard.data
72
- end
73
- end#case
74
-
75
- alias_for :write, :copy
76
- alias_for :read, :paste
77
-
78
- # private
79
-
80
- def capture_stdout
81
- capture = StringIO.new
82
- restore, $stdout = $stdout, capture
83
- yield
84
- $stdout = restore
85
- capture.string
86
81
  end
87
82
 
83
+ def self.copy(data)
84
+ WriteCommands.each{ |cmd|
85
+ IO.popen( cmd, 'w' ){ |input| input << data }
86
+ }
87
+ paste
88
+ end
88
89
  end
89
90
 
90
91
  # J-_-L
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipboard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 7
7
+ - 8
9
8
  - 0
10
- version: 0.7.0
9
+ version: 0.8.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jan Lelis
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-01 00:00:00 +02:00
17
+ date: 2010-10-03 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,13 +38,12 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 11
44
41
  segments:
45
42
  - 4
46
43
  version: "4"
47
44
  type: :runtime
48
45
  version_requirements: *id002
49
- description: Access the clipboard on all systems (Clipboard.write & Clipboard.read)
46
+ description: Access the clipboard on all systems (Clipboard.copy & Clipboard.paste)
50
47
  email: mail@janlelis.de
51
48
  executables: []
52
49
 
@@ -64,7 +61,7 @@ files:
64
61
  - Rakefile
65
62
  - VERSION
66
63
  - clipboard.gemspec
67
- - doc/Clipboard||= Module.new.html
64
+ - doc/Clipboard.html
68
65
  - doc/README_rdoc.html
69
66
  - doc/created.rid
70
67
  - doc/images/brick.png
@@ -110,7 +107,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
107
  requirements:
111
108
  - - ">="
112
109
  - !ruby/object:Gem::Version
113
- hash: 3
114
110
  segments:
115
111
  - 0
116
112
  version: "0"
@@ -119,13 +115,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
115
  requirements:
120
116
  - - ">="
121
117
  - !ruby/object:Gem::Version
122
- hash: 3
123
118
  segments:
124
119
  - 0
125
120
  version: "0"
126
121
  requirements:
127
122
  - on linux (or other X), you need xclip
128
- - on windows, you need the win32-clipboard gem
129
123
  rubyforge_project:
130
124
  rubygems_version: 1.3.7
131
125
  signing_key: