irb_rocket 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +19 -0
  2. data/Rakefile +56 -0
  3. data/lib/irb_rocket.rb +98 -0
  4. metadata +90 -0
data/README ADDED
@@ -0,0 +1,19 @@
1
+ irb_rocket
2
+ ==========
3
+
4
+ INSTALL
5
+
6
+ You must install Wirble and ruby-terminfo in advance. And then, you can
7
+ install the plugin like this:
8
+
9
+ sudo gem install irb_rocket --source http://merbi.st
10
+
11
+ USAGE
12
+
13
+ In your ~/.irbrc
14
+
15
+ require 'rubygems'
16
+ require 'irb_rocket'
17
+
18
+ That's all!
19
+ let's try new style of irb
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ GEM_NAME = "irb_rocket"
5
+ GEM_VERSION = "0.1.4"
6
+ AUTHOR = "Genki Takiuchi"
7
+ EMAIL = "genki@s21g.com"
8
+ HOMEPAGE = "http://blog.s21g.com/genki"
9
+ SUMMARY = "irb plugin that makes irb #=> rocket"
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.rubyforge_project = 'irb_rocket'
13
+ s.name = GEM_NAME
14
+ s.version = GEM_VERSION
15
+ s.platform = Gem::Platform::RUBY
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ["README"]
18
+ s.summary = SUMMARY
19
+ s.description = s.summary
20
+ s.author = AUTHOR
21
+ s.email = EMAIL
22
+ s.homepage = HOMEPAGE
23
+ s.add_dependency('wirble', '>= 0.1.2')
24
+ s.add_dependency('ruby-terminfo', '>= 0.1')
25
+ s.require_path = 'lib'
26
+ s.files = %w(README Rakefile) + Dir.glob("{lib,spec}/**/*")
27
+ end
28
+
29
+ Rake::GemPackageTask.new(spec) do |pkg|
30
+ pkg.gem_spec = spec
31
+ end
32
+
33
+ desc "install the plugin as a gem"
34
+ task :install => :gemspec do
35
+ sh "gem build #{GEM_NAME}.gemspec"
36
+ sh "sudo gem install #{GEM_NAME}-#{GEM_VERSION}.gem"
37
+ end
38
+
39
+ desc "Uninstall the gem"
40
+ task :uninstall => :gemspec do
41
+ sh "sudo gem uninstall #{GEM_NAME} -v #{GEM_VERSION}"
42
+ end
43
+
44
+ desc "Create a gemspec file"
45
+ task :gemspec do
46
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
47
+ file.puts spec.to_ruby
48
+ end
49
+ end
50
+
51
+ desc "Run specs"
52
+ task :spec do
53
+ sh "spec --color spec"
54
+ end
55
+
56
+ task :default => :spec
data/lib/irb_rocket.rb ADDED
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'terminfo'
3
+ require 'wirble'
4
+
5
+ Wirble.init
6
+
7
+ module IRB
8
+ class CaptureIO
9
+ def initialize
10
+ @sin, @sout = IO.pipe
11
+ @ein, @eout = IO.pipe
12
+ @out, @err = STDOUT.dup, STDERR.dup
13
+ end
14
+
15
+ def self.original_streams
16
+ {
17
+ :stdout => @@current_capture.instance_variable_get( :@out ),
18
+ :stderr => @@current_capture.instance_variable_get( :@err ),
19
+ }
20
+ end
21
+
22
+ def capture(&block)
23
+ @@current_capture = self
24
+ STDOUT.reopen(@sout)
25
+ STDERR.reopen(@eout)
26
+ block.call
27
+ ensure
28
+ play
29
+ STDOUT.reopen(@out)
30
+ STDERR.reopen(@err)
31
+ end
32
+
33
+ def print(*args)
34
+ @out.print(*args)
35
+ end
36
+
37
+ def play
38
+ play_io(@ein) do |buf|
39
+ @err.print Wirble::Colorize::Color.escape(:red) + buf + "\e[m"
40
+ end
41
+ play_io(@sin) do |buf|
42
+ @out.print buf
43
+ end
44
+ end
45
+
46
+ private
47
+ def play_io(io, &block)
48
+ buf = ""
49
+ buf << io.read_nonblock(1024) while true
50
+ rescue Errno::EAGAIN
51
+ block[buf]
52
+ rescue Exception => e
53
+ @out.print Wirble::Colorize::Color.escape(:yellow) + e.inspect
54
+ end
55
+ end
56
+
57
+ class Irb
58
+ alias :original_signal_status :signal_status
59
+ def signal_status(name, *args, &block)
60
+ if name == :IN_EVAL
61
+ print sc
62
+ @last_line = eval('line', block.binding)
63
+ @io = CaptureIO.new
64
+ @io.capture do
65
+ original_signal_status(name, *args, &block)
66
+ end
67
+ else
68
+ original_signal_status(name, *args, &block)
69
+ end
70
+ end
71
+
72
+ def output_value
73
+ return ' ' if @io.nil?
74
+ last = @context.io.prompt + @last_line.split("\n").last
75
+ @io.print(rc + cuu1 + (cuf1*last.length) + " " +
76
+ Wirble::Colorize::Color.escape(:blue) + "#=>" + sgr0 +
77
+ " " + Wirble::Colorize.colorize(@context.last_value.inspect) + cud1)
78
+ end
79
+
80
+ private
81
+ def terminfo; @terminfo ||= TermInfo.new end
82
+ def cuu1; terminfo.tigetstr('cuu1') end
83
+ def cud1; terminfo.tigetstr('cud1') end
84
+ def cuf1; terminfo.tigetstr('cuf1') end
85
+ def sgr0; terminfo.tigetstr('sgr0') end
86
+ def sc; terminfo.tigetstr('sc') end
87
+ def rc; terminfo.tigetstr('rc') end
88
+ end
89
+ end
90
+
91
+ module Kernel
92
+ alias original_exec exec
93
+ def exec(*args)
94
+ STDOUT.reopen(IRB::CaptureIO.original_streams[:stdout])
95
+ STDERR.reopen(IRB::CaptureIO.original_streams[:stderr])
96
+ original_exec *args
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irb_rocket
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 4
9
+ version: 0.1.4
10
+ platform: ruby
11
+ authors:
12
+ - Genki Takiuchi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-06 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: wirble
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 2
31
+ version: 0.1.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: ruby-terminfo
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 1
44
+ version: "0.1"
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ description: "irb plugin that makes irb #=> rocket"
48
+ email: genki@s21g.com
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files:
54
+ - README
55
+ files:
56
+ - README
57
+ - Rakefile
58
+ - lib/irb_rocket.rb
59
+ has_rdoc: true
60
+ homepage: http://blog.s21g.com/genki
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project: irb_rocket
85
+ rubygems_version: 1.3.6
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: "irb plugin that makes irb #=> rocket"
89
+ test_files: []
90
+