diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2019-03-28 02:13:24 +0200 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2019-03-28 02:13:24 +0200 |
commit | 79712f279a2b540f36cc2c9a181403b6cd990880 (patch) | |
tree | f9eaaf5cdc10479efce2f36c6846b067c6aad359 /lib/pry/code | |
parent | 92aeb347d4a64bb80313f3d328dd1afb2edee510 (diff) | |
download | pry-79712f279a2b540f36cc2c9a181403b6cd990880.tar.gz |
Factor out all CodeRay code to Pry::SyntaxHighlighter
This moves all the code related syntax highlighting and tokenization to a
wrapper class of CodeRay. Benefits:
* we reduce duplication (no need to call `scan(code, :ruby).term` everywhere)
* swapping CodeRay becomes easier because it's isolated in one class
Diffstat (limited to 'lib/pry/code')
-rw-r--r-- | lib/pry/code/code_file.rb | 4 | ||||
-rw-r--r-- | lib/pry/code/loc.rb | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/pry/code/code_file.rb b/lib/pry/code/code_file.rb index 7ac6ef0e..d120af84 100644 --- a/lib/pry/code/code_file.rb +++ b/lib/pry/code/code_file.rb @@ -82,8 +82,8 @@ class Pry # @param [String] filename # @param [Symbol] default (:unknown) the file type to assume if none could be # detected. - # @return [Symbol, nil] The CodeRay type of a file from its extension, or - # `nil` if `:unknown`. + # @return [Symbol, nil] The SyntaxHighlighter type of a file from its + # extension, or `nil` if `:unknown`. def type_from_filename(filename, default = :unknown) _, @code_type = EXTENSIONS.find do |k, _| k.any? { |ext| ext == File.extname(filename) } diff --git a/lib/pry/code/loc.rb b/lib/pry/code/loc.rb index 5ec4ed87..905c7693 100644 --- a/lib/pry/code/loc.rb +++ b/lib/pry/code/loc.rb @@ -54,7 +54,7 @@ class Pry # @param [Symbol] code_type # @return [void] def colorize(code_type) - tuple[0] = CodeRay.scan(line, code_type).term + tuple[0] = SyntaxHighlighter.highlight(line, code_type) end # Prepends the line number `lineno` to the `line`. |