irb icon indicating copy to clipboard operation
irb copied to clipboard

Allow disabling dialog colors

Open teoljungberg opened this issue 3 years ago • 2 comments

Description

I'm unsure if this falls under Reline, or IRB, if I have filed this in the wrong repository do let me know and I'll move it.

IRB allows us to disable colors using IRB.conf[:USE_COLORIZE] = false, however - after the dialog introduction in Ruby 3.1 (or Reline 0.3.0) - the dialog is still colored even though --nocolorize or the config above is present.

image

I would expect that the colors are disabled if the irb configuration is present, or by any other means if possible.

Result of irb_info

irb(main):002:0> irb_info
=>
Ruby version: 3.1.0
IRB version: irb 1.4.1 (2021-12-25)
InputMethod: ReidlineInputMethod with Reline 0.3.0
.irbrc path: /Users/teo/.irbrc
RUBY_PLATFORM: x86_64-darwin21
LANG env: en_US.UTF-8
LC_ALL env: en_US.UTF-8
East Asian Ambiguous Width: 1

Terminal Emulator

kitty

Setting Files

~/.irbrc:

require "irb"
require "irb/completion"

ENV["TERM"] = "xterm"

IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] =
  if defined?(Rails) && Rails.root
    Rails.root.join("tmp", "history.rb")
  else
    File.expand_path("~/.history.rb")
  end
IRB.conf[:USE_COLORIZE] = false

if defined?(Rails)
  ActiveSupport::LogSubscriber.colorize_logging = false
end

class Object
  def interesting_methods
    case self.class
    when Class
      self.public_methods.sort - Object.public_methods
    when Module
      self.public_methods.sort - Module.public_methods
    else
      self.public_methods.sort - Object.new.public_methods
    end
  end
end

def capture_exception(&block)
  block.call
rescue => exception
  exception
end

def time(&block)
  t0 = Time.now
  block.call
  puts Time.now - t0
end

def ri(*args)
  help(*args)
end

teoljungberg avatar Jan 07 '22 13:01 teoljungberg

I tried to debug this issue a little bit. When URI is not used, the addr_port method is normally called. The addr_port method handles wrapping an IPv6 address in brackets. When a URI is used, we end up here, where req['host'] is set and that prevents addr_port from being called. I don't know what the best fix would be, but having a single source of truth for handling the conversion of the 'host' header would probably help.

Edit: How we end up with ::1 rather than [::1] is due to using #hostname (vs #host).

0x1eef avatar Sep 18 '23 04:09 0x1eef