[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

A nicer-looking ri

Vincent Fourmond

9/29/2006 6:50:00 AM


Hello !

I'm recently in a shell scripting mood, and I came up with some small
code that makes ri output look a fair deal nicer (at least on my box).
If you put the following function definition in your shell's init script
(such as .bashrc or .zshrc) and use ril instead of ri, you'll be pleased ;-)

ril () {
ri -T -f ansi "$@" | less -r
}

I wish a good day (or night) to all of you...

Vince

5 Answers

Eric Hodel

9/29/2006 8:11:00 AM

0

On Sep 28, 2006, at 11:49 PM, Vincent Fourmond wrote:

> I'm recently in a shell scripting mood, and I came up with some
> small
> code that makes ri output look a fair deal nicer (at least on my box).
> If you put the following function definition in your shell's init
> script
> (such as .bashrc or .zshrc) and use ril instead of ri, you'll be
> pleased ;-)
>
> ril () {
> ri -T -f ansi "$@" | less -r
> }
>
> I wish a good day (or night) to all of you...

Why not just set the RI and PAGER environment variables?

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Vincent Fourmond

9/29/2006 8:20:00 AM

0


Hello !

>> ril () {
>> ri -T -f ansi "$@" | less -r
>> }
>>
>
> Why not just set the RI and PAGER environment variables?

That's a good point, but you don't always want less to have the -r
option, don't you ?

Vince

Eric Hodel

9/30/2006 12:46:00 AM

0

On Sep 29, 2006, at 1:19 AM, Vincent Fourmond wrote:

>>> ril () {
>>> ri -T -f ansi "$@" | less -r
>>> }
>>>
>>
>> Why not just set the RI and PAGER environment variables?
>
> That's a good point, but you don't always want less to have the -r
> option, don't you ?

To be honest, I never use the pager with ri.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Nobuyoshi Nakada

10/1/2006 8:02:00 AM

0

Hi,

At Fri, 29 Sep 2006 17:19:42 +0900,
Vincent Fourmond wrote in [ruby-talk:217143]:
> >> ril () {
> >> ri -T -f ansi "$@" | less -r
> >> }
> >>
> >
> > Why not just set the RI and PAGER environment variables?
>
> That's a good point, but you don't always want less to have the -r
> option, don't you ?

Why doesn't ri have --pager option?


Index: lib/rdoc/ri/ri_display.rb
===================================================================
RCS file: /pub/cvs/ruby/lib/rdoc/ri/ri_display.rb,v
retrieving revision 1.6
diff -U 2 -p -r1.6 ri_display.rb
--- lib/rdoc/ri/ri_display.rb 24 Mar 2004 19:17:13 -0000 1.6
+++ lib/rdoc/ri/ri_display.rb 29 Sep 2006 10:41:04 -0000
@@ -210,9 +210,14 @@ class DefaultDisplay

def setup_pager
- unless @options.use_stdout
- for pager in [ ENV['PAGER'], "less", "more", 'pager' ].compact.uniq
+ if pager = @options.pager
+ pagers = []
+ pagers << pager unless pager == true
+ pagers << pager if pager = ENV['PAGER']
+ pagers.concat(%w"less more pager")
+ pagers.uniq!
+ pagers.each do |pager|
return IO.popen(pager, "w") rescue nil
end
- @options.use_stdout = true
+ @options.pager = false
nil
end
Index: lib/rdoc/ri/ri_options.rb
===================================================================
RCS file: /pub/cvs/ruby/lib/rdoc/ri/ri_options.rb,v
retrieving revision 1.17
diff -U 2 -p -r1.17 ri_options.rb
--- lib/rdoc/ri/ri_options.rb 22 Sep 2006 23:39:10 -0000 1.17
+++ lib/rdoc/ri/ri_options.rb 29 Sep 2006 10:34:20 -0000
@@ -6,4 +6,5 @@ module RI
require 'rdoc/ri/ri_paths'
require 'rdoc/ri/ri_display'
+ require 'rdoc/ri/ri_paths'

VERSION_STRING = "ri v1.0.1 - 20041108"
@@ -16,7 +17,7 @@ module RI
include Singleton

- # No not use a pager. Writable, because ri sets it if it
+ # Pager to use. Writable, because ri sets it if it
# can't find a pager
- attr_accessor :use_stdout
+ attr_accessor :pager

# should we just display a class list and exit
@@ -64,5 +65,5 @@ module RI
[ "--gems", nil, nil,
"Include documentation from Rubygems:\n " +
- (RI::Paths::GEMDIRS ? "#{Gem.path}/doc/*/ri" :
+ (RI::Paths::GEMDIRS ? "#{::Gem.path}/doc/*/ri" :
"No Rubygems ri found.") ],

@@ -79,4 +80,8 @@ module RI
],

+ [ "--pager", "-P", "pager",
+ "Send output to the command to pagenate"
+ ],
+
[ "--no-pager", "-T", nil,
"Send output directly to stdout."
@@ -218,5 +223,5 @@ module RI

def initialize
- @use_stdout = !STDOUT.tty?
+ @pager = STDOUT.tty?
@width = 72
@formatter = RI::TextFormatter.for("plain")
@@ -251,5 +256,6 @@ module RI
when "--version" then show_version
when "--list-names" then @list_names = true
- when "--no-pager" then @use_stdout = true
+ when "--pager" then @pager = arg
+ when "--no-pager" then @pager = false
when "--classes" then @list_classes = true

Index: lib/rdoc/ri/ri_paths.rb
===================================================================
RCS file: /pub/cvs/ruby/lib/rdoc/ri/ri_paths.rb,v
retrieving revision 1.7
diff -U 2 -p -r1.7 ri_paths.rb
--- lib/rdoc/ri/ri_paths.rb 26 Jun 2006 18:10:30 -0000 1.7
+++ lib/rdoc/ri/ri_paths.rb 19 Sep 2006 06:02:58 -0000
@@ -45,6 +45,7 @@ module RI
begin
require 'rubygems'
- GEMDIRS = Dir["#{Gem.path}/doc/*/ri"]
- GEMDIRS.each { |path| RI::Paths::PATH << path }
+ if GEMDIRS = (Dir["#{::Gem.path}/doc/*/ri"] if defined?(::Gem.path))
+ PATH.concat(GEMDIRS)
+ end
rescue LoadError
GEMDIRS = nil


--
Nobu Nakada

Eric Hodel

10/2/2006 5:47:00 PM

0

On Oct 1, 2006, at 1:02 AM, Nobuyoshi Nakada wrote:

> At Fri, 29 Sep 2006 17:19:42 +0900,
> Vincent Fourmond wrote in [ruby-talk:217143]:
>>>> ril () {
>>>> ri -T -f ansi "$@" | less -r
>>>> }
>>>>
>>>
>>> Why not just set the RI and PAGER environment variables?
>>
>> That's a good point, but you don't always want less to have the -r
>> option, don't you ?
>
> Why doesn't ri have --pager option?
>
> [...]

Thank you.

I will commit this after returning from AJAXWorld.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...