clipboard 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ == 0.9.5
2
+ * Fallback to Clipboard::File, if no other clipboard is available
3
+ * Also check for xsel if using linux implementation
4
+ * Fix for jruby copying
5
+ * You can directly use a specific implementation, e.g.: require 'clipboard/file' # gives you Clipboard::File
6
+
7
+ == < 0.9.4
8
+ See https://github.com/janlelis/clipboard/commits/0.9.4
data/README.rdoc CHANGED
@@ -21,22 +21,28 @@ If you paste with 1.9, the Clipboard encoding will be translated to your <tt>Enc
21
21
  If you paste with 1.8, it will fallback to CP850 encoding.
22
22
  Copying with 1.8 will fallback to the +clip+ utility, which is installed by default since Vista
23
23
 
24
+ ==== SSH note
25
+ To you use the clipboard through ssh, you need to install <tt>xauth</tt> on your server and connect via <tt>ssh -X</tt> or <tt>ssh -Y</tt>.
26
+
24
27
  === Non-gem requirements
25
28
  * *Linux*: +xclip+, you can install it on debian/ubuntu with <tt>sudo apt-get install xclip</tt>
26
29
 
27
30
  === Todo
28
31
  * Don't depend on +xclip+
29
32
 
30
- Feel free to report bugs or to implement one of the Todo entries ;)
33
+ ...if there is enough demand or motivation for me °_°
31
34
 
32
- === blip
35
+ ==== Planned for 0.9.5
36
+ * Fallback to <tt>~/.clipboard</tt> if the real clipboard can't be accessed.
37
+ * Also check for +xsel+ on linux
33
38
 
39
+ === blip
34
40
  Copy and paste from the commandline (like xclip, pbpaste/pbcopy), but even easier? {blip}[http://rubygems.org/gems/blip]!
35
41
 
36
42
  === Copyright
37
43
  Copyright (c) 2010-2011 Jan Lelis, http://rbjl.net, released under the MIT license
38
44
 
39
- Contributions by
45
+ Contributions by and thanks to
40
46
  * Michael Grosser
41
47
 
42
48
  J-_-L
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
data/clipboard.gemspec CHANGED
@@ -6,12 +6,12 @@ Gem::Specification.new do |s|
6
6
  s.version = File.read('VERSION').chomp
7
7
 
8
8
  s.authors = ["Jan Lelis"]
9
- s.date = '2011-01-16'
9
+ s.date = '2011-02-28'
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'
13
13
  s.homepage = %q{http://github.com/janlelis/clipboard}
14
- s.rubygems_version = %q{1.3.7}
14
+ s.required_rubygems_version = ">= 1.3.6"
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
17
  s.files = Dir.glob(%w[{lib,spec}/**/*.rb [A-Z]* [A-Z]*.rdoc]) + %w{clipboard.gemspec}
data/lib/clipboard.rb CHANGED
@@ -1,18 +1,49 @@
1
1
  module Clipboard
2
2
  extend self
3
+
3
4
  VERSION = File.read( (File.dirname(__FILE__) + '/../VERSION') ).chomp
4
5
 
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..
6
+ class ClipboardLoadError < Exception
7
+ end
8
+
9
+ autoload :Linux, 'clipboard/linux'
10
+ autoload :Mac, 'clipboard/mac'
11
+ autoload :Windows, 'clipboard/windows'
12
+ autoload :File, 'clipboard/file'
13
+
14
+ def self.implementation
15
+ return @implementation if @implementation
16
+
17
+ os = case RbConfig::CONFIG['host_os']
18
+ when /mac|darwin/ then :Mac
19
+ when /linux|bsd|cygwin/ then :Linux
20
+ when /mswin|mingw/ then :Windows
21
+ # when /solaris|sunos/ then :Linux # needs testing..
12
22
  else
13
- raise "You OS is not supported -> fork me"
23
+ raise ClipboardLoadError, "Your OS(#{ RbConfig::CONFIG['host_os'] }) is not supported, using file-based (fake) clipboard"
14
24
  end
25
+
26
+ @implementation = Clipboard.const_get os
27
+ rescue ClipboardLoadError => e
28
+ $stderr.puts e.message if $VERBOSE
29
+ @implementation = Clipboard::File
30
+ end
31
+
32
+ def self.implementation=(val)
33
+ @implementation = val
34
+ end
35
+
36
+ def paste(*args)
37
+ Clipboard.implementation.paste(*args)
15
38
  end
16
39
 
17
- require "clipboard/#{os.call}"
40
+ def clear(*args)
41
+ Clipboard.implementation.clear(*args)
42
+ end
43
+
44
+ def copy(*args)
45
+ Clipboard.implementation.copy(*args)
46
+ end
18
47
  end
48
+
49
+ Clipboard.implementation # TODO remove this?
@@ -0,0 +1,20 @@
1
+ module Clipboard; end
2
+
3
+ module Clipboard::File
4
+ extend self
5
+
6
+ FILE = File.expand_path("~/.clipboard")
7
+
8
+ def copy(text)
9
+ File.open(FILE,'w'){|f| f.write(text) } rescue ''
10
+ paste
11
+ end
12
+
13
+ def paste(_ = nil)
14
+ File.read(FILE) rescue ''
15
+ end
16
+
17
+ def clear
18
+ copy ''
19
+ end
20
+ end
@@ -1,18 +1,32 @@
1
- module Clipboard
1
+ require 'open3'
2
+
3
+ module Clipboard; end
4
+
5
+ module Clipboard::Linux
6
+ extend self
7
+
2
8
  CLIPBOARDS = %w[clipboard primary secondary]
3
- WriteCommands = CLIPBOARDS.map{|cb| 'xclip -selection ' + cb }
4
- ReadCommand = 'xclip -o'
5
9
 
6
- # catch dependency errors
7
- if `which xclip`.empty?
8
- raise LoadError, "clipboard:\n" +
9
- "Could not find required prgram xclip\n" +
10
+ # check which backend to use
11
+ if !`which xclip`.empty?
12
+ WriteCommand = 'xclip'
13
+ ReadCommand = 'xclip -o'
14
+ Selection = proc{|x| "-selection #{x}"}
15
+ elsif !`which xsel`.empty?
16
+ WriteCommand = 'xsel'
17
+ ReadCommand = 'xsel -o'
18
+ Selection = {'clipboard' => '-b', 'primary' => '-p', 'secondary' => '-s'}
19
+ else
20
+ raise Clipboard::ClipboardLoadError, "clipboard:\n" \
21
+ "Could not find required program xclip (or xsel)\n" \
10
22
  "On debian/ubuntu, you can install it with: sudo apt-get install xclip"
11
23
  end
12
24
 
13
25
  def paste(which = nil)
14
- which ||= CLIPBOARDS.first
15
- `#{ReadCommand} -selection #{which}`
26
+ if !which || !CLIPBOARDS.include?(which.to_s.downcase)
27
+ which = CLIPBOARDS.first
28
+ end
29
+ `#{ReadCommand} #{Selection[which.to_s.downcase]}`
16
30
  end
17
31
 
18
32
  def clear
@@ -20,8 +34,8 @@ module Clipboard
20
34
  end
21
35
 
22
36
  def copy(data)
23
- WriteCommands.each{ |cmd|
24
- IO.popen( cmd, 'w' ){ |input| input << data }
37
+ CLIPBOARDS.each{ |which|
38
+ Open3.popen3( "#{WriteCommand} #{Selection[which.to_s.downcase]}" ){ |input,_,_| input << data }
25
39
  }
26
40
  paste
27
41
  end
data/lib/clipboard/mac.rb CHANGED
@@ -1,10 +1,16 @@
1
- module Clipboard
1
+ require 'open3'
2
+
3
+ module Clipboard; end
4
+
5
+ module Clipboard::Mac
6
+ extend self
7
+
2
8
  def paste(_ = nil)
3
9
  `pbpaste`
4
10
  end
5
11
 
6
12
  def copy(data)
7
- IO.popen('pbcopy', 'w'){|input| input << data }
13
+ Open3.popen3( 'pbcopy' ){ |input,_,_| input << data }
8
14
  paste
9
15
  end
10
16
 
@@ -1,4 +1,10 @@
1
- module Clipboard
1
+ require 'open3'
2
+
3
+ module Clipboard; end
4
+
5
+ module Clipboard::Windows
6
+ extend self
7
+
2
8
  CF_TEXT = 1
3
9
  CF_UNICODETEXT = 13
4
10
  GMEM_MOVEABLE = 2
@@ -33,7 +39,7 @@ module Clipboard
33
39
  end
34
40
 
35
41
  # see http://www.codeproject.com/KB/clipboard/archerclipboard1.aspx
36
- def paste(_=nil)
42
+ def paste(_ = nil)
37
43
  ret = ""
38
44
  if 0 != User32.open( 0 )
39
45
  hclip = User32.get( CF_UNICODETEXT )
@@ -82,7 +88,7 @@ module Clipboard
82
88
  User32.set( CF_UNICODETEXT, handler )
83
89
  User32.close( )
84
90
  else # don't touch anything
85
- IO.popen( 'clip', 'w' ){ |input| input << data_to_copy } # depends on clip (available by default since Vista)
91
+ Open3.popen3( 'clip' ){ |input,_,_| input << data_to_copy } # depends on clip (available by default since Vista)
86
92
  end
87
93
  paste
88
94
  end
@@ -1,6 +1,12 @@
1
1
  require File.expand_path('spec/spec_helper')
2
2
 
3
+ $os = RbConfig::CONFIG['host_os']
4
+
3
5
  describe Clipboard do
6
+ before do
7
+ RbConfig::CONFIG['host_os'] = $os
8
+ end
9
+
4
10
  it "has a VERSION" do
5
11
  Clipboard::VERSION.should =~ /^\d+\.\d+\.\d+$/
6
12
  end
@@ -13,4 +19,72 @@ describe Clipboard do
13
19
  it "returns data on copy" do
14
20
  Clipboard.copy('xxx').should == 'xxx'
15
21
  end
16
- end
22
+
23
+ it "can clear" do
24
+ Clipboard.copy('xxx')
25
+ Clipboard.clear
26
+ Clipboard.paste.should == ''
27
+ end
28
+
29
+ describe "when included" do
30
+ class A
31
+ include Clipboard
32
+ end
33
+
34
+ it "can copy & paste & clear" do
35
+ a = A.new
36
+ a.send(:copy, "XXX").should == 'XXX'
37
+ a.send(:paste).should == "XXX"
38
+ a.send(:clear)
39
+ a.send(:paste).should == ''
40
+ end
41
+ end
42
+
43
+ describe 'Clipboard::File' do
44
+ before :all do
45
+ Clipboard.implementation = Clipboard::File
46
+ cache = Clipboard::File::FILE
47
+ FileUtils.rm cache if File.exist?(cache)
48
+ end
49
+
50
+ it "can paste with empty file" do
51
+ Clipboard.paste.should == ''
52
+ end
53
+
54
+ it "can copy & paste" do
55
+ Clipboard.copy('xxx').should == 'xxx'
56
+ Clipboard.paste.should == 'xxx'
57
+ end
58
+
59
+ it "can clear" do
60
+ Clipboard.copy('xxx').should == 'xxx'
61
+ Clipboard.clear
62
+ Clipboard.paste.should == ''
63
+ end
64
+ end
65
+
66
+ describe :implementation do
67
+ before do
68
+ $VERBOSE = true
69
+ Clipboard.implementation = nil
70
+ end
71
+
72
+ it "does not warn on normal detection" do
73
+ $stderr.should_not_receive(:puts)
74
+ Clipboard.implementation
75
+ end
76
+
77
+ it "warns when OS is unknown" do
78
+ RbConfig::CONFIG['host_os'] = 'Fooo OS'
79
+ $stderr.should_receive(:puts)
80
+ Clipboard.implementation.should == Clipboard::File
81
+ end
82
+
83
+ it "does not warn when $VERBOSE is false" do
84
+ $VERBOSE = false
85
+ RbConfig::CONFIG['host_os'] = 'Fooo OS'
86
+ $stderr.should_not_receive(:puts)
87
+ Clipboard.implementation
88
+ end
89
+ end
90
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  $LOAD_PATH.unshift 'lib'
2
- require 'clipboard'
2
+ require 'clipboard'
3
+ require 'clipboard/file'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 4
9
- version: 0.9.4
8
+ - 5
9
+ version: 0.9.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Lelis
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-16 00:00:00 +01:00
17
+ date: 2011-02-28 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -28,17 +28,19 @@ extra_rdoc_files: []
28
28
 
29
29
  files:
30
30
  - lib/clipboard.rb
31
- - lib/clipboard/mac.rb
32
31
  - lib/clipboard/linux.rb
32
+ - lib/clipboard/mac.rb
33
+ - lib/clipboard/file.rb
33
34
  - lib/clipboard/windows.rb
34
- - spec/spec_helper.rb
35
35
  - spec/clipboard_spec.rb
36
- - Gemfile
36
+ - spec/spec_helper.rb
37
37
  - Rakefile
38
- - LICENSE
39
- - Gemfile.lock
40
38
  - README.rdoc
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE
41
42
  - VERSION
43
+ - CHANGELOG.rdoc
42
44
  - clipboard.gemspec
43
45
  has_rdoc: true
44
46
  homepage: http://github.com/janlelis/clipboard
@@ -63,8 +65,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
65
  - - ">="
64
66
  - !ruby/object:Gem::Version
65
67
  segments:
66
- - 0
67
- version: "0"
68
+ - 1
69
+ - 3
70
+ - 6
71
+ version: 1.3.6
68
72
  requirements:
69
73
  - On Linux (or other X), you need xclip. Install it on debian/ubuntu with sudo apt-get install xclip
70
74
  - - On Windows, you need the ffi gem.