Sha256: 1a3622e267ed8fba0bc40c15b81be04024e97d7b388025a4890f99688099ddd4

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module PryTheme
  class WhenStartedHook
    def call(target, options, _pry_)
      recreate_user_themes_from_default_ones
      load_themes

      if Pry.config.theme
        ThemeList.activate_theme(Pry.config.theme)
      else
        ThemeList.activate_theme_intelligently
      end
    end

    private

    # Copy a default theme to theme directory, but only if it isn't there yet.
    def recreate_user_themes_from_default_ones
      FileUtils.mkdir_p(USER_THEMES_DIR) unless File.exists?(USER_THEMES_DIR)
      default_themes = Dir.entries(DEF_THEMES_DIR) - %w{. ..}

      default_themes.each do |theme|
        user_theme_path = File.join(USER_THEMES_DIR, theme)
        unless File.exists?(user_theme_path)
          def_theme_path = File.join(DEF_THEMES_DIR, theme)
          FileUtils.cp(def_theme_path, USER_THEMES_DIR)
        end
      end
    end

    def load_themes
      user_themes = Dir[File.join(USER_THEMES_DIR, '*' + PT_EXT)]
      user_themes.each do |theme|
        require theme
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pry-theme-1.0.2 lib/pry-theme/when_started_hook.rb
pry-theme-1.0.1 lib/pry-theme/when_started_hook.rb
pry-theme-1.0.0 lib/pry-theme/when_started_hook.rb
pry-theme-0.2.0 lib/pry-theme/when_started_hook.rb