ripl 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = "gabriel.horner@gmail.com"
10
10
  s.homepage = "http://github.com/cldwlaker/ripl"
11
11
  s.summary = "Ruby Interactive Print Loop - A light, modular alternative to irb"
12
- s.description = "ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports commands. This customizability makes it easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the web)."
12
+ s.description = "ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports commands i.e. ripl-play. This customizability makes it easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the web)."
13
13
  s.required_rubygems_version = ">= 1.3.6"
14
14
  s.rubyforge_project = 'tagaholic'
15
15
  s.executables = %w(ripl)
@@ -1,3 +1,8 @@
1
+ == 0.2.6
2
+ * Add ctrl-c handling
3
+ * Clean up api to extend options
4
+ * Allow exit with 'quit'
5
+
1
6
  == 0.2.5
2
7
  * Add -F option
3
8
  * Extendable commandline options
@@ -2,8 +2,9 @@
2
2
 
3
3
  ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and
4
4
  keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports
5
- commands. This customizability makes it easy to build custom shells (i.e. for a gem or application)
6
- and complex shells (i.e. for the {web}[http://github.com/cldwalker/nirvana]).
5
+ commands i.e. {ripl-play}[http://github.com/cldwalker/ripl-play]. This customizability makes it
6
+ easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the
7
+ {web}[http://github.com/cldwalker/nirvana]).
7
8
 
8
9
  == Install
9
10
 
@@ -57,22 +58,27 @@ modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:
57
58
  * Appends to ~/.irb_history on exit
58
59
  * Autocompletion (from bond)
59
60
  * _ for last result
60
- * Type 'exit' or Ctrl-D to exit
61
+ * Type 'exit', 'quit' or press Ctrl-D to exit
61
62
  * 6 common commandline options: -f, -r, -I, -d, -h, -v
62
63
  * IRB.conf -> Ripl.config
64
+ * Handles Ctrl-C quietly
63
65
  * Enhancements over irb
64
- * ~250 lines (doc included) vs irb's 5000+ lines
66
+ * ~260 lines (doc included) vs irb's 5000+ lines
65
67
  * Easily extendable with plugins
66
68
  * Tests and documentation!
67
69
  * Customizable completion and completion of method arguments (from bond)
68
70
  * Easy to create custom shells for gems and apps i.e. Ripl.start
69
71
  * Easy to create and invoke ripl commands
70
72
  * Create console commands in a simple, modular way
73
+ * Custom commandline options can be added via a plugin
71
74
  * ~/.irbrc errors caught
72
75
  * Different from irb
73
- * No multi-line evaluation by default (there is a plugin. See Available Plugins below).
74
- * No irb subsessions or workspaces
75
- * No IRB.conf features i.e. preconfigured prompts and auto indent
76
+ * No multi-line evaluation by default (but there is a plugin,
77
+ {ripl-multi_line}[http://github.com/janlelis/ripl-multi_line]).
78
+ * No irb subsessions or workspaces (though ripl has jumps via
79
+ {ripl-commands}[http://github.com/cldwalker/ripl-commands])
80
+ * Some IRB.conf features aren't supported (see {ripl-irb}[http://github.com/cldwalker/ripl-irb]
81
+ for details)
76
82
 
77
83
  Note: Irb features not in ripl can be implemented as plugins.
78
84
 
@@ -103,7 +109,7 @@ extension, see Ripl::Shell::API and Ripl::Runner::API.
103
109
  If we want to add a config for this plugin, we can simply add a key to Ripl.config that matches the
104
110
  underscored version of the plugin name i.e. Ripl.config[:red_error].
105
111
 
106
- For available plugins, see Available Plugins below.
112
+ For available plugins, see Ripl Plugins below.
107
113
 
108
114
  == Configuration
109
115
 
@@ -132,22 +138,31 @@ $PATH. For example, the file 'ripl-my_gem' would be invoked with `ripl my_gem`.
132
138
  command you can take arguments and parse your options as you please. For an example command,
133
139
  see {ripl-rails}[http://github.com/cldwalker/ripl-rails].
134
140
 
135
- == Available Plugins
141
+ == Credits
142
+ * janlelis for bug fix and tweaks
143
+
144
+ == Ripl Plugins
136
145
 
137
146
  * {ripl-rails}[http://github.com/cldwalker/ripl-rails] : script/console for ripl
138
147
  * {ripl-color_error}[http://github.com/cldwalker/ripl-color_error] : colorize errors
139
148
  * {ripl-multi_line}[http://github.com/janlelis/ripl-multi_line] : evaluate multiple lines
149
+ * {ripl-play}[http://github.com/cldwalker/ripl-play] : play back and record input into ripl
140
150
  * {ripl-after_rc}[http://github.com/cldwalker/ripl-after_rc] : provide blocks to run after ~/.irbrc is loaded
141
151
  * {ripl-irb}[http://github.com/cldwalker/ripl-irb] : smooths transition from irb
142
152
  * {ripl-commands}[http://github.com/cldwalker/ripl-commands] : adds ripl commands similar to irb's commands
143
153
  * {ripl-color_streams}[http://github.com/janlelis/ripl-color_streams] : colorizes stderr + stdout
144
154
  * {ripl-color_result}[http://github.com/janlelis/ripl-color_result] : colorizes results
145
- * {nirvana}[http://github.com/cldwalker/nirvana]: Not a plugin but rather a web shell built on top of ripl
155
+ * {ripl-auto_indent}[http://github.com/janlelis/ripl-auto_indent] : auto indents multi-line input
156
+ * {ripl-hirb}[http://github.com/cldwalker/hirb] : comes with hirb to make it a proper riplzen
157
+ * {ripl-misc}[http://github.com/cldwalker/ripl-misc] : a playground for ripl plugins
146
158
 
147
- == Credits
148
- * janlelis for bug fix and tweaks
159
+ == Ripl Shells
160
+ Shells built on top of ripl:
161
+
162
+ * {nirvana}[http://github.com/cldwalker/nirvana]: A ruby web shell complete with autocomplete
163
+ * {fresh}[http://github.com/janlelis/fresh]: An interesting ruby/system hybrid shell
149
164
 
150
- == irb alternatives
165
+ == Irb Alternatives
151
166
  Some other irb alternatives to check out:
152
167
 
153
168
  * {ir}[http://github.com/raggi/ir]: nice and light
@@ -9,9 +9,12 @@ module Ripl::Runner
9
9
  ['-h, --help', 'Print help']
10
10
  ]
11
11
 
12
- module API
13
- def options; OPTIONS; end
12
+ # Adds commandline options for --help
13
+ def self.add_options(*options)
14
+ OPTIONS.concat(options)
15
+ end
14
16
 
17
+ module API
15
18
  def run(argv=ARGV)
16
19
  ENV['RIPLRC'] = 'false' if argv.delete('-F')
17
20
  load_rc(Ripl.config[:riplrc]) unless ENV['RIPLRC'] == 'false'
@@ -34,18 +37,18 @@ module Ripl::Runner
34
37
  when '-f'
35
38
  ENV['RIPL_IRBRC'] = 'false'
36
39
  when '-h', '--help'
37
- name_max = options.map {|e| e[0].length }.max
38
- desc_max = options.map {|e| e[1].length }.max
40
+ name_max = OPTIONS.map {|e| e[0].length }.max
41
+ desc_max = OPTIONS.map {|e| e[1].length }.max
39
42
  puts "Usage: ripl [OPTIONS] [COMMAND] [ARGS]", "\nOptions:",
40
- options.map {|k,v| " %-*s %-*s" % [name_max, k, desc_max, v] }
43
+ OPTIONS.map {|k,v| " %-*s %-*s" % [name_max, k, desc_max, v] }
41
44
  exit
42
45
  when /^(--?[^-]+)/
43
- invalid_option($1, argv)
46
+ parse_option($1, argv)
44
47
  end
45
48
  end
46
49
  end
47
50
 
48
- def invalid_option(option, argv)
51
+ def parse_option(option, argv)
49
52
  warn "ripl: invalid option `#{option.sub(/^-+/, '')}'"
50
53
  end
51
54
 
@@ -1,6 +1,7 @@
1
1
  class Ripl::Shell
2
2
  OPTIONS = {:name=>'ripl', :result_prompt=>'=> ', :prompt=>'>> ',
3
3
  :binding=>TOPLEVEL_BINDING, :irbrc=>'~/.irbrc'}
4
+ EXIT_WORDS = [nil, 'exit', 'quit']
4
5
 
5
6
  def self.create(options={})
6
7
  require 'ripl/readline' if options[:readline]
@@ -45,11 +46,16 @@ class Ripl::Shell
45
46
  def loop_once
46
47
  @error_raised = nil
47
48
  @input = get_input
48
- throw(:ripl_exit) if !@input || @input == 'exit'
49
+ throw(:ripl_exit) if EXIT_WORDS.include?(@input)
49
50
  eval_input(@input)
50
51
  print_result(@result)
52
+ rescue Interrupt
53
+ handle_interrupt
51
54
  end
52
55
 
56
+ # Handles interrupt (Control-C) by printing a newline
57
+ def handle_interrupt; puts; end
58
+
53
59
  # Sets @result to result of evaling input and print unexpected errors
54
60
  def eval_input(input)
55
61
  @result = loop_eval(input)
@@ -1,3 +1,3 @@
1
1
  module Ripl
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
data/man/ripl.1 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "RIPL" "1" "November 2010" "CLDWALKER" "Ripl Manual"
4
+ .TH "RIPL" "1" "December 2010" "CLDWALKER" "Ripl Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBripl\fR \- Ruby Interactive Print Loop \- A light, modular alternative to irb
@@ -87,7 +87,7 @@ An example ~/\.riplrc:
87
87
  .IP "" 0
88
88
  .
89
89
  .SH "PLUGINS"
90
- A ripl plugin is a module that is included into Ripl::Shell or Ripl::Runner\. Being simply modules, they can be packaged as gems and reused across shells as needed\. ripl highly encourages plugins by loading them as early as possible and allowing them to extend most of ripl\'s functionality\. As mentioned in the \fBCONFIGURATION\fR section, a plugin can be configured via Ripl\.config\.
90
+ A ripl plugin is a module that is included into Ripl::Shell or extended into Ripl::Runner\. Being simply modules, they can be packaged as gems and reused across shells as needed\. ripl highly encourages plugins by loading them as early as possible and allowing them to extend most of ripl\'s functionality\. As mentioned in the \fBCONFIGURATION\fR section, a plugin can be configured via Ripl\.config\.
91
91
  .
92
92
  .P
93
93
  To always use a plugin, require it in ~/\.riplrc\. To sometimes use it, require it from the commandline:
@@ -134,10 +134,11 @@ a plugin start with an underscored version of its name i.e. Ripl::ColorError ->
134
134
 
135
135
  <h2 id="PLUGINS">PLUGINS</h2>
136
136
 
137
- <p>A ripl plugin is a module that is included into Ripl::Shell or Ripl::Runner. Being simply modules,
138
- they can be packaged as gems and reused across shells as needed. ripl highly encourages plugins by
139
- loading them as early as possible and allowing them to extend most of ripl's functionality. As
140
- mentioned in the <code>CONFIGURATION</code> section, a plugin can be configured via Ripl.config.</p>
137
+ <p>A ripl plugin is a module that is included into Ripl::Shell or extended into Ripl::Runner. Being
138
+ simply modules, they can be packaged as gems and reused across shells as needed. ripl highly
139
+ encourages plugins by loading them as early as possible and allowing them to extend most of ripl's
140
+ functionality. As mentioned in the <code>CONFIGURATION</code> section, a plugin can be configured via
141
+ Ripl.config.</p>
141
142
 
142
143
  <p>To always use a plugin, require it in ~/.riplrc. To sometimes use it, require it from
143
144
  the commandline:</p>
@@ -269,7 +270,7 @@ arguments. For an example command, see <a href="http://github.com/cldwalker/ripl
269
270
 
270
271
  <ol class='man-decor man-foot man foot'>
271
272
  <li class='tl'>CLDWALKER</li>
272
- <li class='tc'>November 2010</li>
273
+ <li class='tc'>December 2010</li>
273
274
  <li class='tr'>ripl(1)</li>
274
275
  </ol>
275
276
 
@@ -66,10 +66,11 @@ An example ~/.riplrc:
66
66
 
67
67
  ## PLUGINS
68
68
 
69
- A ripl plugin is a module that is included into Ripl::Shell or Ripl::Runner. Being simply modules,
70
- they can be packaged as gems and reused across shells as needed. ripl highly encourages plugins by
71
- loading them as early as possible and allowing them to extend most of ripl's functionality. As
72
- mentioned in the `CONFIGURATION` section, a plugin can be configured via Ripl.config.
69
+ A ripl plugin is a module that is included into Ripl::Shell or extended into Ripl::Runner. Being
70
+ simply modules, they can be packaged as gems and reused across shells as needed. ripl highly
71
+ encourages plugins by loading them as early as possible and allowing them to extend most of ripl's
72
+ functionality. As mentioned in the `CONFIGURATION` section, a plugin can be configured via
73
+ Ripl.config.
73
74
 
74
75
  To always use a plugin, require it in ~/.riplrc. To sometimes use it, require it from
75
76
  the commandline:
@@ -157,15 +157,15 @@ describe "Runner" do
157
157
  end
158
158
 
159
159
  it "with -v option prints version" do
160
- should.raise(SystemExit) { ripl("-v").should == Ripl::VERSION }
160
+ mock(Runner).exit
161
+ ripl("-v", :start=>true).chomp.should == Ripl::VERSION
161
162
  end
162
163
 
163
164
  it "with -h option prints help" do
164
- should.raise(SystemExit) {
165
- actual = ripl("-v")
166
- actual.should =~ /^Usage: ripl/
167
- actual.should =~ /Options:\n -f/
168
- }
165
+ mock(Runner).exit
166
+ actual = ripl("-h", :start=>true)
167
+ actual.should =~ /^Usage: ripl/
168
+ actual.should =~ /Options:\n -f/
169
169
  end
170
170
 
171
171
  it "with invalid options prints errors" do
@@ -173,5 +173,32 @@ describe "Runner" do
173
173
  ripl('--blah', '-z', :start=>true)
174
174
  }.chomp.should == "ripl: invalid option `blah'\nripl: invalid option `z'"
175
175
  end
176
+
177
+ describe "with plugin" do
178
+ before_all do
179
+ Moo = Module.new do
180
+ def parse_option(option, argv)
181
+ option == '--moo' ? puts("MOOOO") : super
182
+ end
183
+ end
184
+ Runner.extend Moo
185
+ Runner.add_options ['--moo', 'just moos']
186
+ end
187
+
188
+ it "parses plugin option" do
189
+ ripl("--moo", :start=>true).chomp.should == 'MOOOO'
190
+ end
191
+
192
+ it "displays plugin option in --help" do
193
+ mock(Runner).exit
194
+ ripl("--help", :start=>true).should =~ /--moo\s*just moos/
195
+ end
196
+
197
+ it "handles invalid option" do
198
+ capture_stderr {
199
+ ripl('--blah', :start=>true)
200
+ }.chomp.should == "ripl: invalid option `blah'"
201
+ end
202
+ end
176
203
  end
177
204
  end
@@ -15,6 +15,12 @@ describe "Shell" do
15
15
  shell.loop
16
16
  end
17
17
 
18
+ it "exits with quit" do
19
+ mock(shell).get_input { 'quit' }
20
+ dont_allow(shell).eval_input
21
+ shell.loop
22
+ end
23
+
18
24
  it "exits with Control-D" do
19
25
  mock(shell).get_input { nil }
20
26
  dont_allow(shell).eval_input
@@ -22,6 +28,12 @@ describe "Shell" do
22
28
  end
23
29
  end
24
30
 
31
+ it "#loop_once handles Control-C" do
32
+ mock(shell).get_input { raise Interrupt }
33
+ dont_allow(shell).eval_input
34
+ capture_stdout { shell.loop_once }.should == "\n"
35
+ end
36
+
25
37
  describe "#prompt" do
26
38
  it "from a string" do
27
39
  shell(:prompt=>'> ').prompt.should == '> '
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 5
10
- version: 0.2.5
9
+ - 6
10
+ version: 0.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabriel Horner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-24 00:00:00 -05:00
18
+ date: 2010-12-03 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ dependencies:
80
80
  version: "0"
81
81
  type: :development
82
82
  version_requirements: *id004
83
- description: ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports commands. This customizability makes it easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the web).
83
+ description: ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports commands i.e. ripl-play. This customizability makes it easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the web).
84
84
  email: gabriel.horner@gmail.com
85
85
  executables:
86
86
  - ripl