Repository: plribeiro3000/jazz_fingers Branch: master Commit: 2d2d4c5a17b4 Files: 28 Total size: 27.8 KB Directory structure: gitextract_v7gj4cha/ ├── .gitignore ├── .rubocop.yml ├── .ruby-gemset ├── .ruby-version ├── CHANGELOG.md ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── Gemfile ├── LICENSE.md ├── README.md ├── Rakefile ├── jazz_fingers.gemspec └── lib/ ├── jazz_fingers/ │ ├── amazing_print.rb │ ├── coderay/ │ │ ├── escaped_colors.rb │ │ └── unescaped_colors.rb │ ├── coderay.rb │ ├── commands/ │ │ ├── caller_method.rb │ │ ├── copy.rb │ │ └── sql.rb │ ├── commands.rb │ ├── configuration.rb │ ├── input.rb │ ├── print.rb │ ├── prompt/ │ │ ├── pry_version_012_and_prior.rb │ │ └── pry_version_013_and_later.rb │ ├── prompt.rb │ └── version.rb └── jazz_fingers.rb ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp ================================================ FILE: .rubocop.yml ================================================ Metrics/LineLength: Max: 120 Style/Documentation: Enabled: false ================================================ FILE: .ruby-gemset ================================================ jazz_fingers ================================================ FILE: .ruby-version ================================================ 3.4.1 ================================================ FILE: CHANGELOG.md ================================================ # CHANGELOG ## 7.1.0 (2026-03-25) ### Fixed * Pager on Ruby 4.0 ## 7.0.0 (2026-03-24) * Replace `readline` with `reline` for Ruby 4.0 compatibility * Remove `pry-byebug` runtime dependency and debugger aliases * Simplify `colored_prompt` and `prompt_separator` defaults ## 6.3.0 (2025-10-01) * Upgrade [amazing-print][amazing-print] to 1.8 * Upgrade [pry][pry] to 0.15 * Upgrade [pry-byebug][pry-byebug] to 3.11 ## 6.2.0 (2021-04-19) * Upgrade [pry-byebug][pry-byebug] to 3.9 ## 6.1.0 (2021-04-19) * Update [amazing_print][amazing_print] to v1.3.0 ## 6.0.0.pre.rc1 (2020-10-22) * Switched [awesome_print][awesome_print] with [amazing_print][amazing_print] ## 5.2.0 (2020-07-22) * Fixed application name ## 5.2.1 (2020-07-16) * Fix Rails deprecation ## 5.2.0 (2020-05-09) * Added Pry custom commands * Customize AwesomePrint configuration * Customize CodeRay colors ## 5.1.0.rc1 (2020-04-25) * Change deprecated method on pry > 0.13.0 * Improve naming context ## 5.0.1 (2019-06-02) * Remove documentation for removed dependency * Use non deprecated method of `pry` if existent ## 5.0.0 (2018-05-02) * Remove [pry-doc][pry-doc] dependency to reduce memory footprint * Remove [hirb][hirb] dependency since its not being actively maintained ## 4.0.1 (2016-05-26) * Remove requires for `pry-remote` ## 4.0.0 (2016-05-26) * Remove [pry-remote][pry-remote] dependency ## 3.0.2 (2016-03-07) * Downgrade [pry-byebug][pry-byebug] to fix issues with [pry-remote][pry-remote] ## 3.0.1 (2016-02-28) * Separate prompt and print output with a new line ## 3.0.0 (2015-09-22) * Remove [pry-git] dependency * Switch to HTTPS in Gemfile ## 2.0.2 (2015-09-06) * Fix YARD issue when ENV['HOME'] is empty ## 2.0.1 (2015-06-29) * Fix application name when outside Rails ## 2.0.1.rc1 (2015-05-27) * Fix load of [pry][pry] plugins * Fix application name when inside Rails * Add feature to set a custom Name ## 2.0.0 (2015-05-31) * Add alias to the most used commands * Update [pry-byebug][pry-byebug] to ~> v3.1 * Improve abstraction by creating models to handle specific responsibilities * Add configuration to enable/disable [pry-coolline][pry-coolline] * Add configuration to enable/disable [awesome_print][awesome_print] * Remove [pry-rails][pry-rails] dependency * Remove [railties][railties] dependency ## 1.0.0 (2015-02-05) * Downgrade [pry-byebug][pry-byebug] to v1.3.3 ## 0.5.5 (2015-02-03) * Update [pry-byebug][pry-byebug] to v2.0.0 * Update [awesome_print][awesome_print] to v1.6.1 ## 0.5.4 (2014-11-06) * Remove [pry-stack_explorer][pry-stack_explorer] ## 0.5.3 (2014-11-04) * Using [pry-byebug][pry-byebug] to use ruby >= 2.0.0. * Switched [coolline][coolline] with [pry-coolline][pry-coolline] * Upgrade [pry][pry] to 0.10, [pry-doc][pry-doc] to 0.6 * Rename to `JazzFingers` to allow releasing. ## 0.5.2 (2013-10-24) * Upgrade [pry-rails][pry-rails] to the latest 0.3.2, [awesome_print][awesome_print] to 1.2 and loosen it's dependency, and removed [coderay][coderay] as an explicit dependency since [pry][pry] already includes it. ## 0.5.1 (2013-06-28) * Upgrade [pry-rails][pry-rails] to the latest 0.3.1, [pry-doc][pry-doc] 0.4.6, [coolline][coolline] 0.4.2. ## 0.5.0 (2013-03-13) * Rails 4, Ruby 2.0.0 compatibility. * Upgrade [pry][pry] to the latest 0.9.12, [pry-stack_explorer][pry-stack_explorer] 0.4.9, [pry-remote][pry-remote] 0.1.7, [pry-debugger][pry-debugger] 0.2.2, [hirb][hirb] 0.7.1, [coderay][coderay] 1.0.9. ## 0.4.0 (2012-12-27) * Add [pry-rails][pry-rails] 0.2.2 for maintained console hooks and new `show-routes`, `show-models`, and `show-middleware` commands. * Add `JazzHands.colored_prompt` and `JazzHands.prompt_separator` options. Detect readline library to turn off incompatible colored prompt or Unicode prompt separator where appropriate. Fixes #1 and #2. * Upgrade [pry][pry] to the latest 0.9.10, [pry-doc][pry-doc] 0.4.4, [pry-stack_explorer][pry-stack_explorer] 0.4.7, [pry-remote][pry-remote] 0.1.6, [pry-debugger][pry-debugger] 0.2.1, [hirb][hirb] 0.7.0, [Coolline][coolline] 0.4.0, [coderay][coderay] 1.0.8, [awesome_print][awesome_print] 1.1.0. Fixes #4. ## 0.3.1 (2012-06-11) * Upgrade [pry-debugger][pry-debugger] to 0.2.0. ## 0.3.0 (2012-06-07) * Replace [pry-nav][pry-nav] with [pry-debugger][pry-debugger] for improved performance and no segfaults. `JazzHands.enable_pry_nav` removed. * Upgrade [pry][pry] to the latest 0.9.9, [pry-doc][pry-doc] 0.4.2, [pry-git][pry-git] 0.2.3, [pry-stack_explorer][pry-stack_explorer] 0.4.2, [pry-remote][pry-remote] 0.1.4, [coderay][coderay] 1.0.6. ## 0.2.0 (2012-03-19) * Add [pry-stack_explorer][pry-stack_explorer] 0.4.1. * Upgrade [pry-remote][pry-remote] to 0.1.1 and [pry-nav][pry-nav] to 0.2.0. * Upgrade recommended gem minor versions: [pry][pry] 0.9.8.4, [pry-doc][pry-doc] 0.4.1, [hirb][hirb] 0.6.2, and [coderay][coderay] 1.0.5. ## 0.1.2 (2012-01-23) * Improved Rails 3.2 compatibility. Console methods like `app`, `new_session`, `reload!`, `helper`, and `controller` work as expected. ## 0.1.1 (2012-01-20) * Rails 3.2 compatibility ## 0.1.0 (2012-01-04) * For performance, enable [pry-nav][pry-nav] only on MRI 1.9.3 by default. To use on MRI 1.9.2, add `JazzHands.enable_pry_nav` to a Rails initializer. * Due to buggy behavior, syntax highlighting as you type via [Coolline][coolline] and [Coderay][coderay] is disabled by default. Enable with `JazzHands.enable_syntax_highlighting_as_you_type` in a Rails initializer. MRI 1.9.3 only. * Fix [Hirb][hirb] support. * Upgrade [awesome_print][awesome_print] to 1.0.2. ## 0.0.6 (2011-12-03) * Add line numbers to the prompt for easy reference when using `_in_` and `_out`. * Upgrade [pry-nav][pry-nav] to 0.0.4. ## 0.0.5 (2011-12-01) * Add [Hirb][hirb] support. Enable with `Hirb.enable` in the console. * Upgrade [pry-nav][pry-nav] to 0.0.3. ## 0.0.4 (2011-11-30) * Add explicit requires for pry plugin gems. ## 0.0.3 (2011-11-30) * Add [pry-nav][pry-nav]. * Upgrade [awesome_print][awesome_print] to 1.0.1. ## 0.0.2 (2011-11-25) * Add [pry-doc][pry-doc]. ## 0.0.1 (2011-11-25) * First release. Combine [pry][pry], [awesome_print][awesome_print], [coolline][coolline] + [coderay][coderay], [pry-remote][pry-remote], [pry-git][pry-git]. Bit of glue to replace IRB with pry in Rails console, pretty colors. [pry]: http://pry.github.com [awesome_print]: https://github.com/michaeldv/awesome_print [amazing_print]: https://github.com/amazing-print/amazing_print [pry-doc]: https://github.com/pry/pry-doc [pry-git]: https://github.com/pry/pry-git [pry-nav]: https://github.com/nixme/pry-nav [pry-remote]: https://github.com/Mon-Ouie/pry-remote [coolline]: https://github.com/Mon-Ouie/coolline [pry-coolline]: https://github.com/pry/pry-coolline [coderay]: https://github.com/rubychan/coderay [hirb]: https://github.com/cldwalker/hirb [pry-stack_explorer]: https://github.com/pry/pry-stack_explorer [pry-debugger]: https://github.com/nixme/pry-debugger [pry-rails]: https://github.com/rweng/pry-rails [pry-byebug]: https://github.com/deivid-rodriguez/pry-byebug [railties]: https://github.com/rails/rails ================================================ FILE: CONTRIBUTING.md ================================================ ## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/plribeiro3000/jazz_fingers/pulls). * Review open [issues](https://github.com/plribeiro3000/jazz_fingers/issues) for things to help on. * [Create an issue](https://github.com/plribeiro3000/jazz_fingers/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * Commit your changes and rebase against `plribeiro3000/jazz_fingers` to ensure everything is up to date. * [Submit a pull request](https://github.com/plribeiro3000/jazz_fingers/compare/) ### Non-Coding * Offer feedback on open [issues](https://github.com/plribeiro3000/jazz_fingers/issues). * Organize or volunteer at events. ================================================ FILE: CONTRIBUTORS.md ================================================ # Original Author * Gopal Patel # Contributors * Andrew Volozhanin * Anthony Sellitti * Casey Lang * Fernando Paredes * Micah Gates * Paulo Henrique Lopes Ribeiro ================================================ FILE: Gemfile ================================================ source 'https://rubygems.org' gemspec ================================================ FILE: LICENSE.md ================================================ The MIT License (MIT) Copyright (c) 2014-2015 [CONTRIBUTORS.md](https://github.com/plribeiro3000/jazz_fingers/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ Jazz Fingers ============ This repo is a fork, with updates and bug fixes based on [`jazz_hands`](https://github.com/nixme/jazz_hands). Spending hours in the pry console? Spruce it up and show off those hard-working fingers! **jazz_fingers** is an opinionated set of console-related gems and a bit of glue: * [**Pry**][pry] for a powerful shell alternative to IRB. * [**Amazing Print**][amazing_print] for stylish pretty print. console. * [**Pry Coolline**][pry-coolline] for syntax highlighting as you type. ## Notes on Update to `5.0.0` * [**Hirb**][hirb] was removed since it is not actively being maintained * [**Pry-Doc**][pry-doc] was removed since it adds a lot of memory footprint which makes `JazzFingers` too heavy to use in production. Add it to your `Gemfile` if you want it back * `jazz_fingers/setup` is not needed since the setup is done automatically after the configuration block ends * Call `JazzFingers.setup!` if you are using the default configurations ## Usage Ruby 2.0.0+. Add to your project Gemfile: ```ruby group :development, :test do gem 'jazz_fingers' end ``` That's it. Run `pry` as usual. Ruby compiled against a proper readline library, ideally GNU readline, is recommended. Alternatively, [`gem install rb-readline`][rb-readline] for an acceptible backup. Using ruby compiled against a `libedit` wrapper (primarily OS X) will work but is not recommended. ## Options Some configurations can be overwritten: ```ruby if defined?(JazzFingers) JazzFingers.configure do |config| config.colored_prompt = false config.amazing_print = false config.coolline = false config.application_name = MyAwesomeProject end end ``` ### `colored_prompt` Color the console prompt? Defaults to `true` when the current ruby is compiled against GNU readline or `rb-readline`, which don't have issues counting characters in colored prompts. `false` for libedit. Note: `Pry.color = false` trumps this setting and disables all console coloring. ### `prompt_separator` Separator string between the application name and line input. Defaults to `»` for GNU readline or libedit. Defaults to `>` for `rb-readline` which fails on mixed encodings. [pry]: http://pry.github.com [amazing_print]: https://github.com/amazing-print/amazing_print [hirb]: https://github.com/cldwalker/hirb [pry-doc]: https://github.com/pry/pry-doc [pry-coolline]: https://github.com/pry/pry-coolline [coderay]: https://github.com/rubychan/coderay [rb-readline]: https://github.com/luislavena/rb-readline [pullrequests]: https://github.com/plribeiro3000/jazz_fingers/pulls [issues]: https://github.com/plribeiro3000/jazz_fingers/issues [changelog]: https://github.com/plribeiro3000/jazz_fingers/blob/master/CHANGELOG.md ================================================ FILE: Rakefile ================================================ #!/usr/bin/env rake require 'bundler/gem_tasks' ================================================ FILE: jazz_fingers.gemspec ================================================ require File.expand_path('lib/jazz_fingers/version', __dir__) Gem::Specification.new do |gem| gem.name = 'jazz_fingers' gem.version = JazzFingers::VERSION gem.author = 'Paulo Henrique Lopes Ribeiro' gem.email = 'plribeiro3000@gmail.com' gem.license = 'MIT' gem.homepage = 'https://github.com/plribeiro3000/jazz_fingers' gem.summary = 'Exercise those fingers. Pry-based enhancements for the default Ruby console.' description = 'Spending hours in the ruby console? Spruce it up and show off those hard-working hands! jazz_fingers'\ 'replaces IRB with Pry, improves output through amazing_print, and has some other goodies up its sleeves.' gem.description = description gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.require_paths = ['lib'] # Dependencies gem.required_ruby_version = '>= 2.0' gem.add_runtime_dependency 'amazing_print', '~> 1.8' gem.add_runtime_dependency 'pry', '~> 0.15' gem.add_runtime_dependency 'pry-coolline', '~> 0.2' gem.add_development_dependency 'rubocop' end ================================================ FILE: lib/jazz_fingers/amazing_print.rb ================================================ module JazzFingers AMAZING_PRINT = { indent: 2, sort_keys: true, color: { args: :greenish, array: :whiteish, bigdecimal: :blue, class: :yellow, date: :greenish, falseclass: :red, fixnum: :blue, float: :blue, hash: :whiteish, keyword: :cyan, method: :purpleish, nilclass: :red, string: :yellowish, struct: :whiteish, symbol: :cyanish, time: :greenish, trueclass: :green, variable: :cyanish } } end ================================================ FILE: lib/jazz_fingers/coderay/escaped_colors.rb ================================================ module JazzFingers module CodeRay ESCAPED_COLORS = { attribute_name: "\e[33m", attribute_value: "\e[31m", binary: "\e[1;35m", char: { self: "\e[36m", delimiter: "\e[34m" }, class: "\e[1;35m", class_variable: "\e[36m", color: "\e[32m", comment: "\e[37m", complex: "\e[34m", constant: "\e[34m\e[4m", decoration: "\e[35m", definition: "\e[1;32m", directive: "\e[32m\e[4m", doc: "\e[46m", doctype: "\e[1;30m", doc_string: "\e[31m\e[4m", entity: "\e[33m", error: "\e[1;33m\e[41m", exception: "\e[1;31m", float: "\e[1;35m", function: "\e[1;34m", global_variable: "\e[42m", hex: "\e[1;36m", include: "\e[33m", integer: "\e[1;34m", key: "\e[35m", label: "\e[1;15m", local_variable: "\e[33m", octal: "\e[1;35m", operator_name: "\e[1;29m", predefined_constant: "\e[1;36m", predefined_type: "\e[1;30m", predefined: "\e[4m\e[1;34m", preprocessor: "\e[36m", pseudo_class: "\e[34m", regexp: { self: "\e[31m", content: "\e[31m", delimiter: "\e[1;29m", modifier: "\e[35m", function: "\e[1;29m" }, reserved: "\e[1;31m", shell: { self: "\e[42m", content: "\e[1;29m", delimiter: "\e[37m", }, string: { self: "\e[36m", modifier: "\e[1;32m", escape: "\e[1;36m", delimiter: "\e[1;32m", }, symbol: "\e[1;31m", tag: "\e[34m", type: "\e[1;34m", value: "\e[36m", variable: "\e[34m", insert: "\e[42m", delete: "\e[41m", change: "\e[44m", head: "\e[45m" }.freeze end end ================================================ FILE: lib/jazz_fingers/coderay/unescaped_colors.rb ================================================ module JazzFingers module CodeRay UNESCAPED_COLORS = { attribute_name: '33', attribute_value: '31', binary: '1;35', char: { self: '36', delimiter: '34' }, class: '1;35', class_variable: '36', color: '32', comment: '37', complex: '34', constant: ['34', '4'], decoration: '35', definition: '1;32', directive: ['32', '4'], doc: '46', doctype: '1;30', doc_string: ['31', '4'], entity: '33', error: ['1;33', '41'], exception: '1;31', float: '1;35', function: '1;34', global_variable: '42', hex: '1;36', include: '33', integer: '1;34', key: '35', label: '1;15', local_variable: '33', octal: '1;35', operator_name: '1;29', predefined_constant: '1;36', predefined_type: '1;30', predefined: ['4', '1;34'], preprocessor: '36', pseudo_class: '34', regexp: { self: '31', content: '31', delimiter: '1;29', modifier: '35', function: '1;29' }, reserved: '1;31', shell: { self: '42', content: '1;29', delimiter: '37', }, string: { self: '36', modifier: '1;32', escape: '1;36', delimiter: '1;32', }, symbol: '1;31', tag: '34', type: '1;34', value: '36', variable: '34', insert: '42', delete: '41', change: '44', head: '45' }.freeze end end ================================================ FILE: lib/jazz_fingers/coderay.rb ================================================ module JazzFingers module CodeRay autoload :ESCAPED_COLORS, 'jazz_fingers/coderay/escaped_colors' autoload :UNESCAPED_COLORS, 'jazz_fingers/coderay/unescaped_colors' def self.setup! ::CodeRay.scan("example", :ruby).term if ::CodeRay::VERSION >= '1.1.0' ESCAPED_COLORS.each do |key, value| ::CodeRay::Encoders::Terminal::TOKEN_COLORS[key] = value end else UNESCAPED_COLORS.each do |key, value| ::CodeRay::Encoders::Terminal::TOKEN_COLORS[key] = value end end end end end ================================================ FILE: lib/jazz_fingers/commands/caller_method.rb ================================================ module JazzFingers module Commands CALLER_METHOD = Pry::CommandSet.new do command "caller_method" do |depth| depth = depth.to_i || 1 if /^(.+?):(\d+)(?::in `(.*)')?/ =~ caller(depth+1).first file = Regexp.last_match[1] line = Regexp.last_match[2].to_i method = Regexp.last_match[3] output.puts [file, line, method] end end end end end ================================================ FILE: lib/jazz_fingers/commands/copy.rb ================================================ module JazzFingers module Commands COPY = Pry::CommandSet.new do command "copy", "Copy argument to the clip-board" do |str| IO.popen('pbcopy', 'w') { |f| f << str.to_s } end end end end ================================================ FILE: lib/jazz_fingers/commands/sql.rb ================================================ module JazzFingers module Commands SQL = Pry::CommandSet.new do command "sql", "Send sql over AR." do |query| if defined?(Rails) pp ActiveRecord::Base.connection.select_all(query) else pp "Rails not defined" end end end end end ================================================ FILE: lib/jazz_fingers/commands.rb ================================================ module JazzFingers module Commands autoload :CALLER_METHOD, 'jazz_fingers/commands/caller_method' autoload :COPY, 'jazz_fingers/commands/copy' autoload :SQL, 'jazz_fingers/commands/sql' end end ================================================ FILE: lib/jazz_fingers/configuration.rb ================================================ module JazzFingers class Configuration attr_writer :colored_prompt, :prompt_separator, :coolline, :amazing_print, :application_name # Color the prompt? # # A different setting than Pry.color since some may like colored output, but a # plain prompt. # # Default: true, delegating to Pry.color. def colored_prompt if @colored_prompt.nil? Pry.color else @colored_prompt end end # Separator between application name and input in the prompt. # # Default: right angle quote (»). def prompt_separator @prompt_separator ||= "\u00BB" end def coolline? return false if @coolline.nil? @coolline end def amazing_print? return true if @amazing_print.nil? @amazing_print end def application_name return underscore(@application_name) unless @application_name.nil? if defined?(Rails) application_class = Rails.application.class if application_class.respond_to?(:module_parent_name) return application_class.module_parent_name.underscore else return application_class.parent_name.underscore end end "jazz_fingers" end private def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end end end ================================================ FILE: lib/jazz_fingers/input.rb ================================================ require 'pry-coolline' require 'coderay' module JazzFingers class Input class << self def config { cool: cool_input } end def cool_input Coolline.new do |c| c.transform_proc = proc do CodeRay.scan(c.line, :ruby).term end c.completion_proc = proc do word = c.completed_word Object.constants.map(&:to_s).select { |w| w.start_with?(word) } end end end end end end ================================================ FILE: lib/jazz_fingers/print.rb ================================================ require 'amazing_print' module JazzFingers class Print class << self def config lambda do |_output, value, pry_object| pretty = value.ai pry_object.pager.page("=> #{pretty}\n") end end end end end ================================================ FILE: lib/jazz_fingers/prompt/pry_version_012_and_prior.rb ================================================ # frozen_string_literal: true module JazzFingers class Prompt # For Pry < 0.13. module PryVersion012AndPrior def config [main_prompt, wait_prompt] end def main_prompt lambda do |context, _nesting, pry| template(Pry.view_clip(context), pry, main_separator) end end def wait_prompt lambda do |context, _nesting, pry| template(Pry.view_clip(context), pry, wait_separator) end end end end end ================================================ FILE: lib/jazz_fingers/prompt/pry_version_013_and_later.rb ================================================ # frozen_string_literal: true module JazzFingers class Prompt # For Pry >= 0.13. module PryVersion013AndLater # Add the JazzFingers prompt to the Pry::Prompt hash to enable changing it # with `change-prompt`. # # Return the Pry::Prompt object. def config return Pry::Prompt[:jazz_fingers] if Pry::Prompt[:jazz_fingers] Pry::Prompt.add( :jazz_fingers, "A spruced-up prompt provided by jazz_fingers.", [main_separator, wait_separator] ) do |context, _nesting, pry, separator| template(Pry.view_clip(context), pry, separator) end Pry::Prompt[:jazz_fingers] end end end end ================================================ FILE: lib/jazz_fingers/prompt.rb ================================================ # frozen_string_literal: true module JazzFingers class Prompt OBJECT_INSTANCE = /#<(.+)>/ autoload :PryVersion013AndLater, 'jazz_fingers/prompt/pry_version_013_and_later' autoload :PryVersion012AndPrior, 'jazz_fingers/prompt/pry_version_012_and_prior' if Pry::VERSION >= "0.13.0" include PryVersion013AndLater else include PryVersion012AndPrior end def initialize(options = {}) @colored = options.fetch(:colored) @separator = options.fetch(:separator) @application_name = options.fetch(:application_name) end def colored? @colored end def red_text(text) return text.to_s unless colored? "\001\e[0;31m\002#{text}\001\e[0m\002" end def blue_text(text) return text.to_s unless colored? "\001\e[0;34m\002#{text}\001\e[0m\002" end def bold_text(text) return text.to_s unless colored? "\001\e[1m\002#{text}\001\e[0m\002" end def main_separator red_text(@separator) end def wait_separator "*" end # Return the current Pry context # # When the Pry context is `"main"` or `"nil"`, use the application name from # the JazzFingers config. Examples: "(my_rails_app_name)", "(jazz_fingers)". # # When in the context of an object instance, use the abbreviated object # path. Example: "(#)", "(#)" # # Fall back to the raw context provided by Pry.view_clip. # Example: "(Pry::Prompt)" def context(module_name = "main") name = case module_name when "main", "nil" @application_name when OBJECT_INSTANCE abbreviated_context(module_name) else module_name end blue_text("(#{name})") end def line_number(pry) if pry.respond_to? :input_ring bold_text(pry.input_ring.size) else bold_text(pry.input_array.size) end end # Abbreviate the object path in the given `object_label` string so the # prompt doesn't overflow. Display only the root and leaf namespaces. # # Examples: # In: # # Out: # # # In: # # Out: # # # In: # # Out: # def abbreviated_context(object_label) object_path = object_label[OBJECT_INSTANCE, 1] object_path_components = object_path.split("::") return object_label if object_path_components.length <= 2 root, *_, leaf = object_path_components "#<#{root}::...::#{leaf}>" end def template(module_name, pry, separator) format( "%s %s[%s] %s ", ruby: RUBY_VERSION, context: context(module_name), line: line_number(pry), separator: separator ) end end end ================================================ FILE: lib/jazz_fingers/version.rb ================================================ module JazzFingers VERSION = '7.1.0'.freeze end ================================================ FILE: lib/jazz_fingers.rb ================================================ ENV['HOME'] ||= '/dev/null' require 'pry' require 'forwardable' # Pry's SimplePager hardcodes the Readline constant. Ruby 4.0 removed # the readline stdlib, so we mirror Pry's own load_readline fallback # and shim the constant when only Reline is available. begin require 'readline' rescue LoadError require 'reline' Readline = Reline unless defined?(Readline) end module JazzFingers autoload :AMAZING_PRINT, 'jazz_fingers/amazing_print' autoload :CodeRay, 'jazz_fingers/coderay' autoload :Commands, 'jazz_fingers/commands' autoload :Configuration, 'jazz_fingers/configuration' autoload :Input, 'jazz_fingers/input' autoload :Print, 'jazz_fingers/print' autoload :Prompt, 'jazz_fingers/prompt' autoload :VERSION, 'jazz_fingers/version' class << self extend Forwardable def_delegators :config, :amazing_print?, :coolline? def print @print ||= Print.config end def prompt @prompt ||= Prompt.new( colored: config.colored_prompt, separator: config.prompt_separator, application_name: config.application_name ) @prompt.config end def input @input ||= Input.config end def configure yield @config ||= Configuration.new setup! end def config @config ||= Configuration.new end def setup! Pry.prompt = prompt Pry.input = input if JazzFingers.coolline? Pry.config.should_load_plugins = false Pry.editor = 'vi' Pry.config.ls.separator = "\n" Pry.config.ls.heading_color = :magenta Pry.config.ls.public_method_color = :green Pry.config.ls.protected_method_color = :yellow Pry.config.ls.private_method_color = :bright_black JazzFingers::Commands.constants(false).each do |constant| command = JazzFingers::Commands.const_get(constant) Pry.config.commands.import(command) end if JazzFingers.amazing_print? require 'amazing_print' AmazingPrint.defaults = JazzFingers::AMAZING_PRINT Pry.print = print end JazzFingers::CodeRay.setup! true end end end