A nicer-looking ri

Discussion in 'Ruby' started by Vincent Fourmond, Sep 29, 2006.

  1. 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
     
    Vincent Fourmond, Sep 29, 2006
    #1
    1. Advertising

  2. Vincent Fourmond

    Eric Hodel Guest

    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 - - http://blog.segment7.net
    This implementation is HODEL-HASH-9600 compliant

    http://trackmap.robotcoop.com
     
    Eric Hodel, Sep 29, 2006
    #2
    1. Advertising

  3. 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
     
    Vincent Fourmond, Sep 29, 2006
    #3
  4. Vincent Fourmond

    Eric Hodel Guest

    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 - - http://blog.segment7.net
    This implementation is HODEL-HASH-9600 compliant

    http://trackmap.robotcoop.com
     
    Eric Hodel, Sep 30, 2006
    #4
  5. 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
     
    Nobuyoshi Nakada, Oct 1, 2006
    #5
  6. Vincent Fourmond

    Eric Hodel Guest

    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 - - http://blog.segment7.net
    This implementation is HODEL-HASH-9600 compliant

    http://trackmap.robotcoop.com
     
    Eric Hodel, Oct 2, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dede
    Replies:
    0
    Views:
    416
  2. Michele Simionato

    in search of a nicer super ...

    Michele Simionato, May 18, 2004, in forum: Python
    Replies:
    0
    Views:
    296
    Michele Simionato
    May 18, 2004
  3. Markus Rosenstihl

    Nicer way of strip and replace?

    Markus Rosenstihl, Oct 11, 2005, in forum: Python
    Replies:
    6
    Views:
    400
    Markus Rosenstihl
    Oct 12, 2005
  4. Paul Furman

    nicer url thoughts?

    Paul Furman, Jul 26, 2007, in forum: HTML
    Replies:
    36
    Views:
    1,086
    John Dunlop
    Sep 23, 2007
  5. Replies:
    3
    Views:
    313
Loading...

Share This Page