temporary-wirble 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (11) hide show
  1. data/.gitignore +2 -0
  2. data/COPYING +21 -0
  3. data/ChangeLog +29 -0
  4. data/MANIFEST +5 -0
  5. data/README +454 -0
  6. data/Rakefile +58 -0
  7. data/VERSION +1 -0
  8. data/_irbrc +27 -0
  9. data/lib/wirble.rb +541 -0
  10. data/wirble.gemspec +74 -0
  11. metadata +75 -0
@@ -0,0 +1,2 @@
1
+ doc
2
+ pkg
data/COPYING ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (C) 2006-2009 Paul Duncan <pabs@pablotron.org>
2
+ Copyright (C) 2009 Jens Wille <jens.wille@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a
5
+ copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+
2
+ * Wed Sep 06 00:01:21 2006, pabs <pabs@pablotron.org>
3
+ * initial import
4
+
5
+ * Wed Sep 06 00:10:13 2006, pabs <pabs@pablotron.org>
6
+ * wirble.rb: remove symbol hackery to prevent
7
+ ri/rdoc from barfing
8
+
9
+ * Wed Sep 6 02:49:02 EDT 2006, Paul Duncan <pabs@pablotron.org>
10
+ * wirble.rb: fix typo
11
+ * re-release 0.1.0
12
+
13
+ * Fri Sep 8 04:01:40 EDT 2006, Paul Duncan <pabs@pablotron.org>
14
+ * README: updated version to 0.1.1
15
+ * wirble.gemspec: ditto
16
+ * wirble.rb: ditto
17
+ * wirble.rb: wrap colorize in an exception (just in case)
18
+
19
+ * Fri Sep 08 13:11:05 2006, pabs <pabs@pablotron.org>
20
+ * increment version to 0.1.2
21
+ * wirble.gemspec: remove rubilicious dependency
22
+
23
+ * Fri Sep 8 13:17:29 EDT 2006, Paul Duncan <pabs@pablotron.org>
24
+ * README: increment version to 0.1.2
25
+ * wirble.gemspec: ditto
26
+ * wirble.rb: ditto
27
+
28
+ * Fri Sep 08 13:18:15 2006, pabs <pabs@pablotron.org>
29
+ * releasing 0.1.2
@@ -0,0 +1,5 @@
1
+ ./ChangeLog
2
+ ./COPYING
3
+ ./wirble.rb
4
+ ./README
5
+ ./wirble.gemspec
data/README ADDED
@@ -0,0 +1,454 @@
1
+ Wirble 0.1.3 README
2
+ ===================
3
+
4
+ This document was last updated on 2009-05-30. See the file COPYING for
5
+ licensing and warranty information. The latest version of this software
6
+ is available at the following URL:
7
+
8
+ http://pablotron.org/software/wirble/
9
+
10
+ Table of Contents
11
+ =================
12
+ * Introduction to Wirble
13
+ * Installing Wirble
14
+ o Via RubyGems
15
+ o Via a Tarball
16
+ o As a User
17
+ * Using Wirble
18
+ o Editing Your ~/.irbrc
19
+ o Enabling Color
20
+ * Configuring Wirble
21
+ * Color Settings
22
+ o Color Keys
23
+ o Color Values
24
+ o Default Color Map
25
+ * Frequently Asked Questions (FAQ)
26
+ * Reporting Bugs
27
+ * About the Author
28
+
29
+
30
+ Introduction to Wirble
31
+ ======================
32
+ Wirble is a set of enhancements to Irb all included together in one
33
+ easy-to-use package. Specifically, Wirble adds a saved history, a
34
+ couple of useful shortcuts, and color to Irb. Wirble also enables a
35
+ Irb's built-in tab-completion and a simpler prompt.
36
+
37
+ Before we begin, I should mention that several of Wirble's features were
38
+ shamelessly inspired (read: borrowed with extreme prejudice) from the
39
+ "Irb Tips and Tricks" page of the Ruby Garden Wiki, which you can find
40
+ at the following URL:
41
+
42
+ http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks
43
+
44
+ In particular, the Irb history and ri features bear a striking
45
+ resemblence to their Ruby Garden counterparts.
46
+
47
+
48
+ Installing Wirble
49
+ =================
50
+ The easiest way to install Wirble is via RubyGems
51
+ (http://rubygems.org/). If you've already got RubyGems installed,
52
+ simply do the following, then skip to the "Using Wirble" section below:
53
+
54
+ # install wirble via RubyGems
55
+ sudo gem install wirble
56
+
57
+ If you don't have RubyGems, you can also install the Wirble using
58
+ setup.rb:
59
+
60
+ # install wirble using setup.rb
61
+ ruby ./setup.rb config && ruby ./setup.rb setup
62
+ sudo ruby ./setup.rb install
63
+
64
+ Or, install Wirble by hand using sudo:
65
+
66
+ # install wirble to library directory
67
+ sudo cp -v wirble.rb $(ruby -e 'puts $LOAD_PATH[0]')
68
+
69
+ Or, if you don't use sudo, you can do the same thing with su, like so:
70
+
71
+ # install wirble to library directory
72
+ su -c "cp -v wirble.rb $(ruby -e 'puts $LOAD_PATH[0]')"
73
+
74
+ Finally, if you don't have an administrator account, you can still
75
+ install Wirble in your local home directory like so:
76
+
77
+ # create local ruby library directory
78
+ mkdir ~/.ruby && chmod 700 ~/.ruby
79
+ cp -v wirble.rb ~/.ruby
80
+
81
+ Then add the following line at the _top_ of your ~/.irbrc file:
82
+
83
+ # add ~/.ruby to the library search path
84
+ $LOAD_PATH << File.expand_path('~/.ruby')
85
+
86
+
87
+ Using Wirble
88
+ ============
89
+ A sample ~/.irbrc is available in the file "_irbrc". If you just want
90
+ to get Wirble up quickly, copy that to your home directory and be done
91
+ with it. Otherwise. read on:
92
+
93
+ Using Wirble is easy: just add the following lines to your ~/.irbrc
94
+ file:
95
+
96
+ begin
97
+ require 'wirble'
98
+
99
+ # init wirble
100
+ Wirble.init
101
+ rescue LoadError => err
102
+ $stderr.puts "Couldn't load Wirble: #{err}"
103
+ end
104
+
105
+ A lot of people really don't like colors, so I've kept the color
106
+ disabled by default. To enable it, add the following bit to your
107
+ ~/.irbrc file immediately after the call to "Wirble.init":
108
+
109
+ # enable color
110
+ Wirble.colorize
111
+
112
+ If you want to terrify your grandmother and impress your buddies, your
113
+ entire ~/.irbrc can also be written like so:
114
+
115
+ %w{rubygems wirble}.each do |lib|
116
+ begin
117
+ require lib
118
+ rescue LoadError => err
119
+ $stderr.puts "Couldn't load #{lib}: #{err}"
120
+ end
121
+ end
122
+
123
+ %w{init colorize}.each { |str| Wirble.send(str) }
124
+
125
+ Configuring Wirble
126
+ ==================
127
+ You can pass a hash of options to Wirble.init in order to adjust the
128
+ behavior of Wirble. Here's a full list of options and a brief
129
+ description of each one:
130
+
131
+ * :skip_internals
132
+
133
+ Don't load the internal Irb features. Equivalent to setting both
134
+ :skip_libraries and :skip_prompt (see below).
135
+
136
+ * :skip_libraries
137
+
138
+ Don't load any libraries. At the moment, Wirble attempts to load
139
+ the following libraries: "pp", "irb/completion", and "rubygems".
140
+
141
+ * :skip_prompt
142
+
143
+ Down't load the simple prompt. Shouldn't ever be necessary, but
144
+ I've included it for the sake of completeness. Wirble's default
145
+ behavior is to the prompt setting before making any changes. If the
146
+ prompt is anything other than :DEFAULT, Wirble won't override it.
147
+
148
+ * :skip_history
149
+
150
+ Don't load the Irb history. There are a few additional history
151
+ options as well; see :history_path, :history_size, and
152
+ :history_perms below.
153
+
154
+ * :history_path
155
+
156
+ Set the path to the Irb history file. Defaults to "~/.irb_history".
157
+ If an environment variable named IRB_HISTORY_FILE is set, Wirble
158
+ will use that instead of the default value.
159
+
160
+ * :history_size
161
+
162
+ Set the size (in lines) of the Irb history file. Defaults to 1000
163
+ lines. If an environment variable named IRB_HISTORY_SIZE is set,
164
+ Wirble will use that instead of the default value.
165
+
166
+ * :history_perms
167
+
168
+ Set the permissions of the Irb history file. Defaults to
169
+ File::WRONLY.
170
+
171
+ * :skip_shortcuts
172
+
173
+ Don't load any shortcut methods. at the moment there are three
174
+ shortcut methods: "ri", "po", and "poc". The first calls the "ri"
175
+ command on the specified value -- you"ll need to use proper quoting
176
+ to pass the name properly. As for "po" and "poc": the former lists
177
+ an object's instance methods (excluding methods that belong to
178
+ Object), sorted by name, and the latter lists an object's constants,
179
+ sorted by name.
180
+
181
+ * :init_colors
182
+
183
+ Enable colors. Equivalent to calling Wirble.colorize directly.
184
+
185
+ * :colors
186
+
187
+ A hash of colors. Only makes sense in conjunction with the
188
+ :init_colors option. See below for additional information on
189
+ customizing color settings.
190
+
191
+ Here's an example of passing a list of options to Wirble.init():
192
+
193
+ wirble_opts = {
194
+ # skip shortcuts
195
+ :skip_shortcuts => true,
196
+
197
+ # don't set the prompt
198
+ :skip_prompt => true,
199
+
200
+ # override some of the default colors
201
+ :colors => {
202
+ :open_hash => :green.
203
+ :close_hash => :green.
204
+ :string => :blue,
205
+ },
206
+
207
+ # enable color
208
+ :init_color => true,
209
+ }
210
+
211
+ # initialize wirble with options above
212
+ Wirble.init(wirble_opts)
213
+
214
+ For a full description of the color options, see the next section.
215
+
216
+
217
+ Color Settings
218
+ ==============
219
+ You can set colors in Wirble by passing a hash of color options via
220
+ Wirble.init (see the :color option for Wirble.init above), or by setting
221
+ Wirble::Colorize.color directly. For example:
222
+
223
+ # get the default colors and add in your own
224
+ colors = Wirble::Colorize.colors.merge({
225
+ # set the comma color to blue
226
+ :comma => :blue,
227
+ })
228
+
229
+ # set the colors used by Wirble
230
+ Wirble::Colorize.colors = colors
231
+
232
+ Below is a list of all the recognized color keys.
233
+
234
+ * :comma (',')
235
+
236
+ A comma character. The element delimiter in arrays and hashes.
237
+
238
+ * :refers ('=>')
239
+
240
+ The hash reference operator. The key/value delimiter in hashes.
241
+
242
+ * :open_hash ('{')
243
+
244
+ The opening curly brace for a hash.
245
+
246
+ * :close_hash ('}')
247
+
248
+ The opening curly brace for a hash.
249
+
250
+ * :open_array ('[')
251
+
252
+ The opening brace for a array.
253
+
254
+ * :close_array (']')
255
+
256
+ The opening brace for a array.
257
+
258
+ * :open_object ('#<')
259
+
260
+ The opening delimiter for an object.
261
+
262
+ * :close_object ('>')
263
+
264
+ The closing delimiter for an object inspection.
265
+
266
+ * :object_class
267
+
268
+ The class attribute of an object inspection. For example, in the
269
+ string "#<Proc:0xb7be4968@(irb):8>", the string "Proc" is the class
270
+ attribute.
271
+
272
+ * :object_addr_prefix (':')
273
+
274
+ The colon prefixing the address attribute of an object inspection.
275
+ For example, in the string "#<Proc:0xb7be4968@(irb):8>", the string
276
+ "0xb7be4968" is the memory address attribute, so the ':' is the
277
+ address prefix.
278
+
279
+ * :object_addr
280
+
281
+ The memory address attribute of an object inspection. For example,
282
+ in the string "#<Proc:0xb7be4968@(irb):8>", the string "0xb7be4968"
283
+ is the memory address attribute.
284
+
285
+ * :object_addr_prefix ('@')
286
+
287
+ The at symbol prefixing the line attribute of an object inspection.
288
+ For example, in the string "#<Proc:0xb7be4968@(irb):8>", the string
289
+ "(irb):8" is the line attribute, so the '@' is the line attribute
290
+ prefix.
291
+
292
+ * :object_line
293
+
294
+ The line number attribute of an object inspection. For example,
295
+ in the string "#<Proc:0xb7be4968@(irb):8>", the string "(irb):8"
296
+ is the line number attribute.
297
+
298
+ * :symbol_prefix (':')
299
+
300
+ The colon prefix for a symbol object.
301
+
302
+ * :symbol
303
+
304
+ The string of a symbol object.
305
+
306
+ * :open_string ('"')
307
+
308
+ The opening quote of a string object.
309
+
310
+ * :close_string ('"')
311
+
312
+ The closing quote of a string object.
313
+
314
+ * :number
315
+
316
+ A number (integer or float).
317
+
318
+ * :range ('..')
319
+
320
+ The delimeter of a range object.
321
+
322
+ * :keyword
323
+
324
+ A built-in Ruby keyword. This includes values like "true", "false",
325
+ and "nil".
326
+
327
+ * :class
328
+
329
+ A class. This includes strings like "Class" and "Object".
330
+
331
+ * :whitespace
332
+
333
+ Whitespace character (i.e. space, newline, tab, etc).
334
+
335
+ The highlighting is implemented with a simple hand-rolled state-based
336
+ tokenizer (wow, that was a mouthful). This should be adequate most of
337
+ the time, but since it's not a actual LALR parser, Wirble can get
338
+ confused in a few specific instances. If you find a serious
339
+ highlighting problem, please let me know. Oh yeah, before I forget,
340
+ here's a list of the valid color codes:
341
+
342
+ :nothing :green :light_purple
343
+ :black :light_blue :purple
344
+ :blue :light_cyan :red
345
+ :brown :light_gray :white
346
+ :cyan :light_green :yellow
347
+ :dark_gray :light_red
348
+
349
+ Note that I'm not a designer, and I also use a terminal with a dark
350
+ background. I've also been accused of having a Vim color scheme that
351
+ looks like "a beat up clown". With those caveats in mind, here's the
352
+ default color scheme for Wirble:
353
+
354
+ #
355
+ # Default Wirble color scheme.
356
+ #
357
+ DEFAULT_COLORS = {
358
+ # delimiter colors
359
+ :comma => :blue,
360
+ :refers => :blue,
361
+
362
+ # container colors (hash and array)
363
+ :open_hash => :green,
364
+ :close_hash => :green,
365
+ :open_array => :green,
366
+ :close_array => :green,
367
+
368
+ # object colors
369
+ :open_object => :light_red,
370
+ :object_class => :white,
371
+ :object_addr_prefix => :blue,
372
+ :object_line_prefix => :blue,
373
+ :close_object => :light_red,
374
+
375
+ # symbol colors
376
+ :symbol => :yellow,
377
+ :symbol_prefix => :yellow,
378
+
379
+ # string colors
380
+ :open_string => :red,
381
+ :string => :cyan,
382
+ :close_string => :red,
383
+
384
+ # misc colors
385
+ :number => :cyan,
386
+ :keyword => :green,
387
+ :class => :light_green,
388
+ :range => :red,
389
+ }
390
+
391
+ This map is also available via programmatically via
392
+ Wirble::Colorize::DEFAULT_COLORS.
393
+
394
+
395
+ Frequently Asked Questions (FAQ)
396
+ ================================
397
+ Q. Where did the name come from?
398
+ A. Beats me. It's the only thing I could find in the dictionary, and
399
+ the only name I came up with that I could pronounce.
400
+
401
+ Q. How do I use color in my Irb prompts?
402
+ A. You can use standard color escape codes in the format string used by
403
+ Irb. For example, to set the user prompt to cyan, you could do
404
+ something like this:
405
+
406
+ ctx = IRB.CurrentContext
407
+ ctx.prompt_i = Wirble::Colorize.colorize_string(ctx.prompt_i, :cyan)
408
+
409
+ Q. How can I do syntax highlighting as I type?
410
+ A. I don't know. If there is an answer, I suspect it's not very
411
+ portable and probably requires some modification to Irb. There's a
412
+ sneaky hack called eval.rb that seems to do a little bit of
413
+ highlight, but it doesn't use Irb, and it doesn't really do what
414
+ you're asking. That said, you can find it here:
415
+
416
+ http://www.rubyist.net/~slagell/ruby/eval.txt
417
+
418
+ Incidentally, part of the problem is that there's no real easy way
419
+ to do the following:
420
+
421
+ 1. Access to the token stream or parser state incrementally.
422
+ 2. Process partial strings in readline.
423
+
424
+ A bit more about #1: both Irb and the internal Ruby lexer kind of
425
+ muddle the traditionally separate concepts of lexer and parser, so
426
+ it's difficult to, say, parse a string into components and do syntax
427
+ highlighting on them. Vim and Emacs both handle this with sneaky
428
+ regular expressions, and a simple Ruby parser, respectively. Wirble
429
+ and Irb both roll their own (albeit limited) Ruby lexers.
430
+
431
+
432
+ Reporting Bugs
433
+ ==============
434
+ Have a bug to report or a feature you'd like me to add to Wirble?
435
+ Feel free to email me at the address below. Alternatively, you can
436
+ submit your feature request or bug directly to my bug-tracking web
437
+ interface at the following URL:
438
+
439
+ http://redmine.pablotron.org/projects/show/wirble
440
+
441
+ Note: you'll need to create an account in order to submit a feature
442
+ request or a bug report via the web interface. Also, I'm a busy guy! I
443
+ make every effort to respond quickly to bug reports, but detailed
444
+ descriptions and or patches really do make my life a whole lot easier.
445
+
446
+
447
+ About the Authors
448
+ =================
449
+ Paul Duncan <pabs@pablotron.org>
450
+ http://pablotron.org/
451
+
452
+ Jens Wille <jens.wille@gmail.com>
453
+
454
+ And of course, all the fine folks from the Ruby Garden Wiki. :)
@@ -0,0 +1,58 @@
1
+
2
+ # load libraries
3
+
4
+ require 'rubygems'
5
+ require 'rake'
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gemspec|
10
+ gemspec.name = 'temporary-wirble'
11
+ gemspec.summary = "A gem version of blackwinter's fork of pablotron's wirble, with fixes to how wirble remembers history."
12
+ gemspec.description = <<-EOF
13
+ A handful of useful Irb features, including colorized results,
14
+ tab-completion, history, a simple prompt, and several helper
15
+ methods, all rolled into one easy to use package.
16
+ EOF
17
+ gemspec.email = ['pabs@pablotron.org', 'jens.wille@gmail.com']
18
+ gemspec.homepage = 'http://github.com/seamusabshere/wirble'
19
+ gemspec.authors = ['Paul Duncan', 'Jens Wille']
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/test_*.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+ rescue LoadError
41
+ task :rcov do
42
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
+ end
44
+ end
45
+
46
+ task :test => :check_dependencies
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "temporary-wirble #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.4
data/_irbrc ADDED
@@ -0,0 +1,27 @@
1
+ ######################################################################
2
+ # _irbrc - Sample .irbrc file to enable Wirble. #
3
+ ######################################################################
4
+
5
+ #
6
+ # Uncomment the block below if you want to load RubyGems in Irb.
7
+ #
8
+
9
+ # begin
10
+ # require 'rubygems'
11
+ # rescue LoadError => err
12
+ # warn "Couldn't load RubyGems: #{err}"
13
+ # end
14
+
15
+ begin
16
+ # load and initialize wirble
17
+ require 'wirble'
18
+ Wirble.init
19
+
20
+ #
21
+ # Uncomment the line below to enable Wirble colors.
22
+ #
23
+
24
+ # Wirble.colorize
25
+ rescue LoadError => err
26
+ warn "Couldn't load Wirble: #{err}"
27
+ end
@@ -0,0 +1,541 @@
1
+ require 'ostruct'
2
+
3
+ #
4
+ # Wirble: A collection of useful Irb features.
5
+ #
6
+ # To use, add the following to your ~/.irbrc:
7
+ #
8
+ # require 'rubygems'
9
+ # require 'wirble'
10
+ # Wirble.init
11
+ #
12
+ # If you want color in Irb, add this to your ~/.irbrc as well:
13
+ #
14
+ # Wirble.colorize
15
+ #
16
+ # Note: I spent a fair amount of time documenting this code in the
17
+ # README. If you've installed via RubyGems, root around your cache a
18
+ # little bit (or fire up gem_server) and read it before you tear your
19
+ # hair out sifting through the code below.
20
+ #
21
+ module Wirble
22
+ ## sabshere 5/26/10 using jeweler
23
+ # VERSION = '0.1.3.2'
24
+
25
+ #
26
+ # Load internal Ruby features, including pp, tab-completion,
27
+ # and a simple prompt.
28
+ #
29
+ module Internals
30
+ # list of internal libraries to automatically load
31
+ LIBRARIES = %w{pp irb/completion}
32
+
33
+ #
34
+ # load libraries
35
+ #
36
+ def self.init_libraries
37
+ LIBRARIES.each do |lib|
38
+ begin
39
+ require lib
40
+ rescue LoadError
41
+ nil
42
+ end
43
+ end
44
+ end
45
+
46
+ #
47
+ # Set a simple prompt, unless a custom one has been specified.
48
+ #
49
+ def self.init_prompt
50
+ # set the prompt
51
+ if IRB.conf[:PROMPT_MODE] == :DEFAULT
52
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
53
+ end
54
+ end
55
+
56
+ #
57
+ # Load all Ruby internal features.
58
+ #
59
+ def self.init(opt = nil)
60
+ init_libraries unless opt && opt[:skip_libraries]
61
+ init_prompt unless opt && opt[:skip_prompt]
62
+ end
63
+ end
64
+
65
+ #
66
+ # Basic IRB history support. This is based on the tips from
67
+ # http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks
68
+ #
69
+ class History
70
+ DEFAULTS = {
71
+ :history_path => ENV['IRB_HISTORY_FILE'] || "~/.irb_history",
72
+ :history_size => (ENV['IRB_HISTORY_SIZE'] || 1000).to_i,
73
+ :history_perms => File::WRONLY | File::CREAT | File::TRUNC,
74
+ :history_uniq => true,
75
+ }
76
+
77
+ private
78
+
79
+ def say(*args)
80
+ puts(*args) if @verbose
81
+ end
82
+
83
+ def cfg(key)
84
+ @opt["history_#{key}".intern]
85
+ end
86
+
87
+ def save_history
88
+ path, max_size, perms, uniq = %w{path size perms uniq}.map { |v| cfg(v) }
89
+
90
+ # read lines from history, and truncate the list (if necessary)
91
+ lines = Readline::HISTORY.to_a
92
+
93
+ lines.reverse! if reverse = uniq.to_s == 'reverse'
94
+ lines.uniq! if uniq
95
+ lines.reverse! if reverse
96
+
97
+ lines.slice!(0, lines.size - max_size) if lines.size > max_size
98
+
99
+ # write the history file
100
+ real_path = File.expand_path(path)
101
+ File.open(real_path, perms) { |fh| fh.puts lines }
102
+ say 'Saved %d lines to history file %s.' % [lines.size, path]
103
+ end
104
+
105
+ def load_history
106
+ # expand history file and make sure it exists
107
+ real_path = File.expand_path(cfg('path'))
108
+ unless File.exist?(real_path)
109
+ say "History file #{real_path} doesn't exist."
110
+ return
111
+ end
112
+
113
+ # read lines from file and add them to history
114
+ lines = File.readlines(real_path).map { |line| line.chomp }
115
+ Readline::HISTORY.push(*lines)
116
+
117
+ say 'Read %d lines from history file %s' % [lines.size, cfg('path')]
118
+ end
119
+
120
+ public
121
+
122
+ def initialize(opt = nil)
123
+ @opt = DEFAULTS.merge(opt || {})
124
+ return unless defined? Readline::HISTORY
125
+ load_history
126
+ Kernel.at_exit { save_history }
127
+ end
128
+ end
129
+
130
+ #
131
+ # Add color support to IRB.
132
+ #
133
+ module Colorize
134
+ #
135
+ # Tokenize an inspection string.
136
+ #
137
+ module Tokenizer
138
+ def self.tokenize(str)
139
+ raise 'missing block' unless block_given?
140
+ chars = str.split(//)
141
+
142
+ # $stderr.puts "DEBUG: chars = #{chars.join(',')}"
143
+
144
+ state, val, i, lc = [], '', 0, nil
145
+ while i <= chars.size
146
+ repeat = false
147
+ c = chars[i]
148
+
149
+ # $stderr.puts "DEBUG: state = #{state}"
150
+
151
+ case state[-1]
152
+ when nil
153
+ case c
154
+ when ':'
155
+ state << :symbol
156
+ when '"'
157
+ state << :string
158
+ when '#'
159
+ state << :object
160
+ when /[a-z]/i
161
+ state << :keyword
162
+ repeat = true
163
+ when /[0-9-]/
164
+ state << :number
165
+ repeat = true
166
+ when '{'
167
+ yield :open_hash, '{'
168
+ when '['
169
+ yield :open_array, '['
170
+ when ']'
171
+ yield :close_array, ']'
172
+ when '}'
173
+ yield :close_hash, '}'
174
+ when /\s/
175
+ yield :whitespace, c
176
+ when ','
177
+ yield :comma, ','
178
+ when '>'
179
+ yield :refers, '=>' if lc == '='
180
+ when '.'
181
+ yield :range, '..' if lc == '.'
182
+ when '='
183
+ # ignore these, they're used elsewhere
184
+ nil
185
+ else
186
+ # $stderr.puts "DEBUG: ignoring char #{c}"
187
+ end
188
+ when :symbol
189
+ case c
190
+ # XXX: should have =, but that messes up foo=>bar
191
+ when /[a-z0-9_!?]/
192
+ val << c
193
+ else
194
+ yield :symbol_prefix, ':'
195
+ yield state[-1], val
196
+ state.pop; val = ''
197
+ repeat = true
198
+ end
199
+ when :string
200
+ case c
201
+ when '"'
202
+ if lc == "\\"
203
+ val[-1] = ?"
204
+ else
205
+ yield :open_string, '"'
206
+ yield state[-1], val
207
+ state.pop; val = ''
208
+ yield :close_string, '"'
209
+ end
210
+ else
211
+ val << c
212
+ end
213
+ when :keyword
214
+ case c
215
+ when /[a-z0-9_]/i
216
+ val << c
217
+ else
218
+ # is this a class?
219
+ st = val =~ /^[A-Z]/ ? :class : state[-1]
220
+
221
+ yield st, val
222
+ state.pop; val = ''
223
+ repeat = true
224
+ end
225
+ when :number
226
+ case c
227
+ when /[0-9e-]/
228
+ val << c
229
+ when '.'
230
+ if lc == '.'
231
+ val[/\.$/] = ''
232
+ yield state[-1], val
233
+ state.pop; val = ''
234
+ yield :range, '..'
235
+ else
236
+ val << c
237
+ end
238
+ else
239
+ yield state[-1], val
240
+ state.pop; val = ''
241
+ repeat = true
242
+ end
243
+ when :object
244
+ case c
245
+ when '<'
246
+ yield :open_object, '#<'
247
+ state << :object_class
248
+ when ':'
249
+ state << :object_addr
250
+ when '@'
251
+ state << :object_line
252
+ when '>'
253
+ yield :close_object, '>'
254
+ state.pop; val = ''
255
+ end
256
+ when :object_class
257
+ case c
258
+ when ':'
259
+ yield state[-1], val
260
+ state.pop; val = ''
261
+ repeat = true
262
+ else
263
+ val << c
264
+ end
265
+ when :object_addr
266
+ case c
267
+ when '>'
268
+ when '@'
269
+ yield :object_addr_prefix, ':'
270
+ yield state[-1], val
271
+ state.pop; val = ''
272
+ repeat = true
273
+ else
274
+ val << c
275
+ end
276
+ when :object_line
277
+ case c
278
+ when '>'
279
+ yield :object_line_prefix, '@'
280
+ yield state[-1], val
281
+ state.pop; val = ''
282
+ repeat = true
283
+ else
284
+ val << c
285
+ end
286
+ else
287
+ raise "unknown state #{state}"
288
+ end
289
+
290
+ unless repeat
291
+ i += 1
292
+ lc = c
293
+ end
294
+ end
295
+ end
296
+ end
297
+
298
+ #
299
+ # Terminal escape codes for colors.
300
+ #
301
+ module Color
302
+ COLORS = {
303
+ :nothing => '0;0',
304
+ :black => '0;30',
305
+ :red => '0;31',
306
+ :green => '0;32',
307
+ :brown => '0;33',
308
+ :blue => '0;34',
309
+ :cyan => '0;36',
310
+ :purple => '0;35',
311
+ :light_gray => '0;37',
312
+ :dark_gray => '1;30',
313
+ :light_red => '1;31',
314
+ :light_green => '1;32',
315
+ :yellow => '1;33',
316
+ :light_blue => '1;34',
317
+ :light_cyan => '1;36',
318
+ :light_purple => '1;35',
319
+ :white => '1;37',
320
+ }
321
+
322
+ #
323
+ # Return the escape code for a given color.
324
+ #
325
+ def self.escape(key)
326
+ COLORS.key?(key) && "\033[#{COLORS[key]}m"
327
+ end
328
+ end
329
+
330
+ #
331
+ # Default Wirble color scheme.
332
+ #
333
+ DEFAULT_COLORS = {
334
+ # delimiter colors
335
+ :comma => :blue,
336
+ :refers => :blue,
337
+
338
+ # container colors (hash and array)
339
+ :open_hash => :green,
340
+ :close_hash => :green,
341
+ :open_array => :green,
342
+ :close_array => :green,
343
+
344
+ # object colors
345
+ :open_object => :light_red,
346
+ :object_class => :white,
347
+ :object_addr_prefix => :blue,
348
+ :object_line_prefix => :blue,
349
+ :close_object => :light_red,
350
+
351
+ # symbol colors
352
+ :symbol => :yellow,
353
+ :symbol_prefix => :yellow,
354
+
355
+ # string colors
356
+ :open_string => :red,
357
+ :string => :cyan,
358
+ :close_string => :red,
359
+
360
+ # misc colors
361
+ :number => :cyan,
362
+ :keyword => :green,
363
+ :class => :light_green,
364
+ :range => :red,
365
+ }
366
+
367
+ #
368
+ # Fruity testing colors.
369
+ #
370
+ TESTING_COLORS = {
371
+ :comma => :red,
372
+ :refers => :red,
373
+ :open_hash => :blue,
374
+ :close_hash => :blue,
375
+ :open_array => :green,
376
+ :close_array => :green,
377
+ :open_object => :light_red,
378
+ :object_class => :light_green,
379
+ :object_addr => :purple,
380
+ :object_line => :light_purple,
381
+ :close_object => :light_red,
382
+ :symbol => :yellow,
383
+ :symbol_prefix => :yellow,
384
+ :number => :cyan,
385
+ :string => :cyan,
386
+ :keyword => :white,
387
+ :range => :light_blue,
388
+ }
389
+
390
+ #
391
+ # Set color map to hash
392
+ #
393
+ def self.colors=(hash)
394
+ @colors = hash
395
+ end
396
+
397
+ #
398
+ # Get current color map
399
+ #
400
+ def self.colors
401
+ @colors ||= {}.update(DEFAULT_COLORS)
402
+ end
403
+
404
+ #
405
+ # Return a string with the given color.
406
+ #
407
+ def self.colorize_string(str, color)
408
+ col, nocol = [color, :nothing].map { |key| Color.escape(key) }
409
+ col ? "#{col}#{str}#{nocol}" : str
410
+ end
411
+
412
+ #
413
+ # Colorize the results of inspect
414
+ #
415
+ def self.colorize(str)
416
+ begin
417
+ ret, nocol = '', Color.escape(:nothing)
418
+ Tokenizer.tokenize(str) do |tok, val|
419
+ # c = Color.escape(colors[tok])
420
+ ret << colorize_string(val, colors[tok])
421
+ end
422
+ ret
423
+ rescue
424
+ # catch any errors from the tokenizer (just in case)
425
+ str
426
+ end
427
+ end
428
+
429
+ #
430
+ # Enable colorized IRB results.
431
+ #
432
+ def self.enable(custom_colors = nil)
433
+ # if there's a better way to do this, I'm all ears.
434
+ ::IRB::Irb.class_eval do
435
+ alias :non_color_output_value :output_value
436
+
437
+ def output_value
438
+ if @context.inspect?
439
+ val = Colorize.colorize(@context.last_value.inspect)
440
+ printf @context.return_format, val
441
+ else
442
+ printf @context.return_format, @context.last_value
443
+ end
444
+ end
445
+ end
446
+
447
+ self.colors = custom_colors if custom_colors
448
+ end
449
+
450
+ #
451
+ # Disable colorized IRB results.
452
+ #
453
+ def self.disable
454
+ ::IRB::Irb.class_eval do
455
+ alias :output_value :non_color_output_value
456
+ end
457
+ end
458
+ end
459
+
460
+ #
461
+ # Convenient shortcut methods.
462
+ #
463
+ module Shortcuts
464
+ #
465
+ # Print object methods, sorted by name. (excluding methods that
466
+ # exist in the class Object) .
467
+ #
468
+ def po(o)
469
+ o.methods.sort - Object.methods
470
+ end
471
+
472
+ #
473
+ # Print object constants, sorted by name.
474
+ #
475
+ def poc(o)
476
+ o.constants.sort
477
+ end
478
+ end
479
+
480
+ #
481
+ # Convenient shortcut for ri
482
+ #
483
+ module RiShortcut
484
+ def self.init
485
+ Kernel.class_eval {
486
+ def ri(arg)
487
+ puts `ri '#{arg}'`
488
+ end
489
+ }
490
+
491
+ Module.instance_eval {
492
+ def ri(meth=nil)
493
+ if meth
494
+ if instance_methods(false).include? meth.to_s
495
+ puts `ri #{self}##{meth}`
496
+ else
497
+ super
498
+ end
499
+ else
500
+ puts `ri #{self}`
501
+ end
502
+ end
503
+ }
504
+ end
505
+ end
506
+
507
+
508
+
509
+ #
510
+ # Enable color results.
511
+ #
512
+ def self.colorize(custom_colors = nil)
513
+ Colorize.enable(custom_colors)
514
+ end
515
+
516
+ #
517
+ # Load everything except color.
518
+ #
519
+ def self.init(opt = nil)
520
+ # make sure opt isn't nil
521
+ opt ||= {}
522
+
523
+ # load internal irb/ruby features
524
+ Internals.init(opt) unless opt && opt[:skip_internals]
525
+
526
+ # load the history
527
+ History.new(opt) unless opt && opt[:skip_history]
528
+
529
+ # load shortcuts
530
+ unless opt && opt[:skip_shortcuts]
531
+ # load ri shortcuts
532
+ RiShortcut.init
533
+
534
+ # include common shortcuts
535
+ Object.class_eval { include Shortcuts }
536
+ end
537
+
538
+ colorize(opt[:colors]) if opt && opt[:init_colors]
539
+ end
540
+ end
541
+
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wirble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Paul Duncan
8
+ - Jens Wille
9
+ autorequire: wirble
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-30 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Handful of common Irb features, made easy.
18
+ email:
19
+ - pabs@pablotron.org
20
+ - jens.wille@gmail.com
21
+ executables: []
22
+
23
+ extensions: []
24
+
25
+ extra_rdoc_files: []
26
+
27
+ files:
28
+ - MANIFEST
29
+ - Rakefile
30
+ - _irbrc
31
+ - setup.rb
32
+ - COPYING
33
+ - ChangeLog
34
+ - github-test.rb
35
+ - lib/wirble.rb
36
+ - wirble.gemspec
37
+ - README
38
+ - wirble-0.1.2.gem
39
+ has_rdoc: true
40
+ homepage: http://pablotron.org/software/wirble/
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --title
46
+ - Wirble 0.1.3.2 API Documentation
47
+ - --webcvs
48
+ - http://hg.pablotron.org/wirble
49
+ - lib/wirble.rb
50
+ - README
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements:
66
+ - none
67
+ rubyforge_project: pablotron
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Handful of common Irb features, made easy.
72
+ test_files: []
73
+
74
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: temporary-wirble
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
+ - Paul Duncan
13
+ - Jens Wille
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-26 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: " A handful of useful Irb features, including colorized results,\n tab-completion, history, a simple prompt, and several helper\n methods, all rolled into one easy to use package.\n"
23
+ email:
24
+ - pabs@pablotron.org
25
+ - jens.wille@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - ChangeLog
32
+ - README
33
+ files:
34
+ - .gitignore
35
+ - COPYING
36
+ - ChangeLog
37
+ - MANIFEST
38
+ - README
39
+ - Rakefile
40
+ - VERSION
41
+ - _irbrc
42
+ - lib/wirble.rb
43
+ - wirble.gemspec
44
+ has_rdoc: true
45
+ homepage: http://github.com/seamusabshere/wirble
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.6
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: A gem version of blackwinter's fork of pablotron's wirble, with fixes to how wirble remembers history.
74
+ test_files: []
75
+