Sha256: 623fb4eb4ca3645b8ce23ce2a1f0d231877553a9e679a3621096e3d12a696993

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

module ConsoleColor
  class Railtie < Rails::Railtie
    module IRBSetup
      def setup(*)
        super

        app_name = if Rails.application.class.respond_to?(:module_parent_name)
          Rails.application.class.module_parent_name
        else
          Rails.application.class.parent_name
        end
        environment = ENV.fetch('CONSOLE_COLOR_ENV', Rails.env)
        color = ConsoleColor::COLORS[environment]

        prompt = "\001#{color}\002#{app_name.downcase}:#{environment}"

        IRB.conf[:PROMPT][:RAILS_APP] = {
          PROMPT_I: "#{prompt}>\e[0m ",
          PROMPT_N: "#{prompt}>\e[0m ",
          PROMPT_S: "#{prompt}%l\e[0m ",
          PROMPT_C: "#{prompt}*\e[0m ",
          RETURN: "=> %s\n",
          AUTO_INDENT: true
        }

        IRB.conf[:PROMPT_MODE] = :RAILS_APP
      end
    end

    config.after_initialize do
      require "irb"
      class << IRB
        prepend IRBSetup
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
console_color-0.0.7 lib/console_color/railtie.rb