Project

General

Profile

Actions

Bug #3428

closed

ri outputs ansi escape sequences even when stdout is not a tty

Added by coatl (caleb clausen) almost 14 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3dev (2010-06-11 trunk 28269) [i686-linux]
Backport:
[ruby-core:30734]

Description

=begin
ri should only use ansi escape sequences if explicitly asked for or if stdout is known to be a tty. Otherwise, ugliness will occur when piping ri's output to something else. For instance, here are the first few lines displayed when I type "ri exec|less":

ESC[0mESC[1;32m.execESC[m

(from ruby core)
ESC[32mImplementation from KernelESC[m

exec([env,] command... [,options])
=end


Files

rdoc_ansi_esc_test.diff (407 Bytes) rdoc_ansi_esc_test.diff coatl (caleb clausen), 07/11/2010 09:47 AM
Actions #1

Updated by mame (Yusuke Endoh) almost 14 years ago

  • Assignee set to drbrain (Eric Hodel)
  • Target version set to 1.9.2

=begin
Hi,

2010/6/11 caleb clausen :

ri should only use ansi escape sequences if explicitly asked for or if stdout is known to be a tty. Otherwise, ugliness will occur when piping ri's output to something else. For instance, here are the first few lines displayed when I type "ri exec|less":

ESC[0mESC[1;32m.execESC[m

(from ruby core)
ESC[32mImplementation from KernelESC[m

?exec([env,] command... [,options])

Confirmed. "ri --help" says:

 -f, --format=NAME                Uses the selected formatter. The default
                                  formatter is bs for paged output and ansi
                                  otherwise. Valid formatters are:
                                  ansi bs html rdoc

But ansi is used for paged output in this case. So this is a bug.

Eric, could you review this patch?

diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb
index b552335..0c04db6 100644
--- a/lib/rdoc/ri/driver.rb
+++ b/lib/rdoc/ri/driver.rb
@@ -546,7 +546,7 @@ Options may also be set in the 'RI' environment variable.

def display document
  page do |io|
  •  text = document.accept formatter
    
  •  text = document.accept formatter(io)
    
     io.write text
    
    end
    @@ -795,10 +795,10 @@ Options may also be set in the 'RI' environment variable.

    Creates a new RDoc::Markup::Formatter. If a formatter is given with -f,

    use it. If we're outputting to a pager, use bs, otherwise ansi.

  • def formatter
  • def formatter(io)
    if @formatter_klass then
    @formatter_klass.new
  • elsif paging? then
  • elsif paging? or !io.tty? then
    RDoc::Markup::ToBs.new
    else
    RDoc::Markup::ToAnsi.new

--
Yusuke Endoh
=end

Actions #2

Updated by kosaki (Motohiro KOSAKI) almost 14 years ago

=begin
ruby 1.8.x don't have this issue. in other word, this is regression.
=end

Actions #3

Updated by coatl (caleb clausen) almost 14 years ago

=begin
Ruby 1.8's ri never prints any escape sequences... at least, I know that's true in 1.8.6.
=end

Actions #4

Updated by mame (Yusuke Endoh) almost 14 years ago

=begin
Eric,

May I commit my patch?

--
Yusuke Endoh
=end

Actions #5

Updated by mame (Yusuke Endoh) almost 14 years ago

=begin
I don't care anymore.
I'll decide tickets about rubygems at my discretion of assistant
release manager.

Anyone, give him a kick.

--
Yusuke Endoh
=end

Actions #6

Updated by mame (Yusuke Endoh) almost 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r28455.
caleb, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions #7

Updated by coatl (caleb clausen) almost 14 years ago

=begin
Since the maintainer of rdoc is AWOL, I feel we really need to have a test for this bug, so that the next time eric merges his latest rdoc into ruby, we can be sure he didn't accidentally overwrite this fix and cause a regression.

If I submit a patch to test this bug, will it be accepted?
=end

Actions #8

Updated by mame (Yusuke Endoh) almost 14 years ago

=begin
Hi,

Since the maintainer of rdoc is AWOL, I feel we really need to have a test for this bug, so that the next time eric merges his latest rdoc into ruby, we can be sure he didn't accidentally overwrite this fix and cause a regression.

I committed a test at r28460. It is very trivial, though.

If I submit a patch to test this bug, will it be accepted?

Of course!

--
Yusuke Endoh
=end

Actions #9

Updated by coatl (caleb clausen) almost 14 years ago

=begin
Sorry for the delay getting back to you on this. Here's a patch which expands test_formatter slightly to exercise the path when output is not a tty. I had hoped to write a high-level black box test, which would be more robust and thorough. But that has proved to be a little more involved than I anticipated.
=end

Actions #10

Updated by mame (Yusuke Endoh) almost 14 years ago

=begin
Committed to trunk at r28611. Thanks!

2010/7/11 caleb clausen :

Issue #3428 has been updated by caleb clausen.

File rdoc_ansi_esc_test.diff added

Sorry for the delay getting back to you on this. Here's a patch which expands test_formatter slightly to exercise the path when output is not a tty. I had hoped to write a high-level black box test, which would be more robust and thorough. But that has proved to be a little more involved than I anticipated.

--
Yusuke Endoh

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0