genki-irb_rocket 0.1.1

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 +11 -0
  2. data/Rakefile +56 -0
  3. data/lib/irb_rocket.rb +81 -0
  4. metadata +72 -0
data/README ADDED
@@ -0,0 +1,11 @@
1
+ irb_rocket
2
+ ==========
3
+
4
+ USAGE
5
+
6
+ In your ~/.irbrc
7
+
8
+ require 'irb_rocket'
9
+
10
+ That's all!
11
+ 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.1"
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,81 @@
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 capture(&block)
16
+ STDOUT.reopen(@sout)
17
+ STDERR.reopen(@eout)
18
+ block.call
19
+ ensure
20
+ play
21
+ STDOUT.reopen(@out)
22
+ STDERR.reopen(@err)
23
+ end
24
+
25
+ def print(*args)
26
+ @out.print(*args)
27
+ end
28
+
29
+ def play
30
+ play_io(@ein) do |buf|
31
+ @err.print Wirble::Colorize::Color.escape(:red) + buf + "\e[m"
32
+ end
33
+ play_io(@sin) do |buf|
34
+ @out.print buf
35
+ end
36
+ end
37
+
38
+ private
39
+ def play_io(io, &block)
40
+ buf = ""
41
+ buf << io.read_nonblock(3) while true
42
+ rescue Errno::EAGAIN
43
+ block[buf]
44
+ rescue Exception => e
45
+ @out.print Wirble::Colorize::Color.escape(:yellow) + e.inspect
46
+ end
47
+ end
48
+
49
+ class Irb
50
+ alias :original_signal_status :signal_status
51
+ def signal_status(name, *args, &block)
52
+ if name == :IN_EVAL
53
+ @last_line = eval('line', block.binding)
54
+ @io = CaptureIO.new
55
+ @io.capture do
56
+ original_signal_status(name, *args, &block)
57
+ end
58
+ else
59
+ if name == :IN_INPUT
60
+ end
61
+ original_signal_status(name, *args, &block)
62
+ end
63
+ end
64
+
65
+ def output_value
66
+ last = @context.io.prompt + @last_line.split("\n").last
67
+ @io.print(cuu1 + (cuf1*last.length) + " " +
68
+ Wirble::Colorize::Color.escape(:blue) + "#=>" + sgr0 +
69
+ " " + Wirble::Colorize.colorize(@context.last_value.inspect) + cud1)
70
+ end
71
+
72
+ private
73
+ def terminfo; @terminfo ||= TermInfo.new end
74
+ def cuu1; terminfo.tigetstr('cuu1') end
75
+ def cud1; terminfo.tigetstr('cud1') end
76
+ def cuf1; terminfo.tigetstr('cuf1') end
77
+ def sgr0; terminfo.tigetstr('sgr0') end
78
+ def sc; terminfo.tigetstr('sc') end
79
+ def rc; terminfo.tigetstr('rc') end
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genki-irb_rocket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Genki Takiuchi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-08 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: wirble
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.2
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: ruby-terminfo
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0.1"
32
+ version:
33
+ description: "irb plugin that makes irb #=> rocket"
34
+ email: genki@s21g.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README
41
+ files:
42
+ - README
43
+ - Rakefile
44
+ - lib/irb_rocket.rb
45
+ has_rdoc: true
46
+ homepage: http://blog.s21g.com/genki
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: irb_rocket
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: "irb plugin that makes irb #=> rocket"
71
+ test_files: []
72
+