difftastic 0.1.1-x86_64-linux → 0.2.0-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/difftastic/ansi.rb +23 -0
 - data/lib/difftastic/differ.rb +39 -1
 - data/lib/difftastic/version.rb +1 -1
 - data/lib/difftastic.rb +50 -33
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ebac0bf6dd45fe7c5202c0c02c319587f5d2a0c711b9b845c1e909e6ce7c4537
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b638761ceda03c5f892ed618524898fc533debc532e1a43691c7453c12461679
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5b7902cd02bb98b50a3d8da2209c9c4bca76962d215dbd92598a3037d8081c5411d61f02c3e289922a0b2cb3b835b93be2a157321ea99587abe658c7d240fb15
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 37d92b3ed9fff7456f92cc663b837dfa3babe8465593df65289a261b75b877fd3a7eb97a5d85a251eb771e1789a983d3a5036ac9ad8f06101803d74eebadf300
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Difftastic::ANSI
         
     | 
| 
      
 4 
     | 
    
         
            +
            	RED = "\e[91;1m"
         
     | 
| 
      
 5 
     | 
    
         
            +
            	GREEN = "\e[92;1m"
         
     | 
| 
      
 6 
     | 
    
         
            +
            	RESET = "\e[0m"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            	def self.green(string = "")
         
     | 
| 
      
 9 
     | 
    
         
            +
            		"#{GREEN}#{string}"
         
     | 
| 
      
 10 
     | 
    
         
            +
            	end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            	def self.red(string = "")
         
     | 
| 
      
 13 
     | 
    
         
            +
            		"#{RED}#{string}"
         
     | 
| 
      
 14 
     | 
    
         
            +
            	end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            	def self.reset(string = "")
         
     | 
| 
      
 17 
     | 
    
         
            +
            		"#{RESET}#{string}"
         
     | 
| 
      
 18 
     | 
    
         
            +
            	end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            	def self.strip_formatting(string)
         
     | 
| 
      
 21 
     | 
    
         
            +
            		string.to_s.gsub(/\e\[[0-9;]*m/, "")
         
     | 
| 
      
 22 
     | 
    
         
            +
            	end
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/difftastic/differ.rb
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class Difftastic::Differ
         
     | 
| 
       4 
     | 
    
         
            -
            	def initialize(background: nil, color: nil, syntax_highlight: nil, context: nil, tab_width: nil, parse_error_limit: nil, underline_highlights: true)
         
     | 
| 
      
 4 
     | 
    
         
            +
            	def initialize(background: nil, color: nil, syntax_highlight: nil, context: nil, tab_width: nil, parse_error_limit: nil, underline_highlights: true, left_label: nil, right_label: nil)
         
     | 
| 
       5 
5 
     | 
    
         
             
            		@show_paths = false
         
     | 
| 
       6 
6 
     | 
    
         
             
            		@background = background => :dark | :light | nil
         
     | 
| 
       7 
7 
     | 
    
         
             
            		@color = color => :always | :never | :auto | nil
         
     | 
| 
         @@ -10,6 +10,8 @@ class Difftastic::Differ 
     | 
|
| 
       10 
10 
     | 
    
         
             
            		@tab_width = tab_width => Integer | nil
         
     | 
| 
       11 
11 
     | 
    
         
             
            		@parse_error_limit = parse_error_limit => Integer | nil
         
     | 
| 
       12 
12 
     | 
    
         
             
            		@underline_highlights = underline_highlights => true | false
         
     | 
| 
      
 13 
     | 
    
         
            +
            		@left_label = left_label => String | nil
         
     | 
| 
      
 14 
     | 
    
         
            +
            		@right_label = right_label => String | nil
         
     | 
| 
       13 
15 
     | 
    
         
             
            	end
         
     | 
| 
       14 
16 
     | 
    
         | 
| 
       15 
17 
     | 
    
         
             
            	def diff_objects(old, new)
         
     | 
| 
         @@ -297,6 +299,30 @@ class Difftastic::Differ 
     | 
|
| 
       297 
299 
     | 
    
         
             
            			result = result.byteslice(new_line_index, result.bytesize - new_line_index)
         
     | 
| 
       298 
300 
     | 
    
         
             
            		end
         
     | 
| 
       299 
301 
     | 
    
         | 
| 
      
 302 
     | 
    
         
            +
            		if @left_label || @right_label
         
     | 
| 
      
 303 
     | 
    
         
            +
            			# Get the first content line to calculate offset
         
     | 
| 
      
 304 
     | 
    
         
            +
            			offset_line = @show_paths ? 1 : 0
         
     | 
| 
      
 305 
     | 
    
         
            +
            			first_line = result.split("\n")[offset_line]
         
     | 
| 
      
 306 
     | 
    
         
            +
             
     | 
| 
      
 307 
     | 
    
         
            +
            			# Calculate padding needed between labels
         
     | 
| 
      
 308 
     | 
    
         
            +
            			offset = right_label_offset(first_line)
         
     | 
| 
      
 309 
     | 
    
         
            +
             
     | 
| 
      
 310 
     | 
    
         
            +
            			left_part = if @left_label
         
     | 
| 
      
 311 
     | 
    
         
            +
            				Difftastic::ANSI.red(@left_label.to_s.ljust(offset))
         
     | 
| 
      
 312 
     | 
    
         
            +
            			else
         
     | 
| 
      
 313 
     | 
    
         
            +
            				" " * offset
         
     | 
| 
      
 314 
     | 
    
         
            +
            			end
         
     | 
| 
      
 315 
     | 
    
         
            +
             
     | 
| 
      
 316 
     | 
    
         
            +
            			right_part = if @right_label
         
     | 
| 
      
 317 
     | 
    
         
            +
            				Difftastic::ANSI.green(@right_label.to_s)
         
     | 
| 
      
 318 
     | 
    
         
            +
            			else
         
     | 
| 
      
 319 
     | 
    
         
            +
            				""
         
     | 
| 
      
 320 
     | 
    
         
            +
            			end
         
     | 
| 
      
 321 
     | 
    
         
            +
             
     | 
| 
      
 322 
     | 
    
         
            +
            			# Insert formatted labels at the top
         
     | 
| 
      
 323 
     | 
    
         
            +
            			result = "\n#{left_part}#{right_part}#{Difftastic::ANSI.reset}\n#{result}"
         
     | 
| 
      
 324 
     | 
    
         
            +
            		end
         
     | 
| 
      
 325 
     | 
    
         
            +
             
     | 
| 
       300 
326 
     | 
    
         
             
            		# Removed due to inconsistencies in the original output. Need to improve the pattern matching.
         
     | 
| 
       301 
327 
     | 
    
         
             
            		# if @underline_highlights
         
     | 
| 
       302 
328 
     | 
    
         
             
            		# 	result.gsub!(/\e\[([0-9;]*)m/) {
         
     | 
| 
         @@ -311,4 +337,16 @@ class Difftastic::Differ 
     | 
|
| 
       311 
337 
     | 
    
         | 
| 
       312 
338 
     | 
    
         
             
            		result
         
     | 
| 
       313 
339 
     | 
    
         
             
            	end
         
     | 
| 
      
 340 
     | 
    
         
            +
             
     | 
| 
      
 341 
     | 
    
         
            +
            	private
         
     | 
| 
      
 342 
     | 
    
         
            +
             
     | 
| 
      
 343 
     | 
    
         
            +
            	def right_label_offset(line)
         
     | 
| 
      
 344 
     | 
    
         
            +
            		stripped_line = ::Difftastic::ANSI.strip_formatting(line)
         
     | 
| 
      
 345 
     | 
    
         
            +
            		_lhs, rhs = stripped_line.split(/\s{#{@tab_width},}/, 2)
         
     | 
| 
      
 346 
     | 
    
         
            +
             
     | 
| 
      
 347 
     | 
    
         
            +
            		offset = (stripped_line.index("#{' ' * @tab_width}#{rhs}") || 0) + @tab_width
         
     | 
| 
      
 348 
     | 
    
         
            +
            		minimum_offset = 29
         
     | 
| 
      
 349 
     | 
    
         
            +
             
     | 
| 
      
 350 
     | 
    
         
            +
            		[minimum_offset, offset].max
         
     | 
| 
      
 351 
     | 
    
         
            +
            	end
         
     | 
| 
       314 
352 
     | 
    
         
             
            end
         
     | 
    
        data/lib/difftastic/version.rb
    CHANGED
    
    
    
        data/lib/difftastic.rb
    CHANGED
    
    | 
         @@ -4,6 +4,7 @@ require "difftastic/version" 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require "tempfile"
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            module Difftastic
         
     | 
| 
      
 7 
     | 
    
         
            +
            	autoload :ANSI, "difftastic/ansi"
         
     | 
| 
       7 
8 
     | 
    
         
             
            	autoload :Differ, "difftastic/differ"
         
     | 
| 
       8 
9 
     | 
    
         
             
            	autoload :Upstream, "difftastic/upstream"
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
         @@ -39,7 +40,7 @@ module Difftastic 
     | 
|
| 
       39 
40 
     | 
    
         
             
            				MESSAGE
         
     | 
| 
       40 
41 
     | 
    
         
             
            			end
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
            			exe_file = Dir.glob(File.expand_path(File.join(exe_path, " 
     | 
| 
      
 43 
     | 
    
         
            +
            			exe_file = Dir.glob(File.expand_path(File.join(exe_path, "**", "difft"))).find do |f|
         
     | 
| 
       43 
44 
     | 
    
         
             
            				Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
         
     | 
| 
       44 
45 
     | 
    
         
             
            			end
         
     | 
| 
       45 
46 
     | 
    
         
             
            		end
         
     | 
| 
         @@ -70,57 +71,73 @@ module Difftastic 
     | 
|
| 
       70 
71 
     | 
    
         
             
            		exe_file
         
     | 
| 
       71 
72 
     | 
    
         
             
            	end
         
     | 
| 
       72 
73 
     | 
    
         | 
| 
       73 
     | 
    
         
            -
            	def self.pretty(object,  
     | 
| 
      
 74 
     | 
    
         
            +
            	def self.pretty(object, indent: 0, indent_width: 2, max_width: 80, indentation_bytes: "\t")
         
     | 
| 
       74 
75 
     | 
    
         
             
            		case object
         
     | 
| 
       75 
76 
     | 
    
         
             
            		when Hash
         
     | 
| 
       76 
     | 
    
         
            -
            			buffer  
     | 
| 
      
 77 
     | 
    
         
            +
            			buffer = +"{\n"
         
     | 
| 
       77 
78 
     | 
    
         
             
            			indent += 1
         
     | 
| 
       78 
79 
     | 
    
         
             
            			object.each do |key, value|
         
     | 
| 
       79 
80 
     | 
    
         
             
            				buffer << ("	" * indent)
         
     | 
| 
       80 
     | 
    
         
            -
            				pretty(key,  
     | 
| 
      
 81 
     | 
    
         
            +
            				buffer << pretty(key, indent:)
         
     | 
| 
       81 
82 
     | 
    
         
             
            				buffer << " => "
         
     | 
| 
       82 
     | 
    
         
            -
            				pretty(value,  
     | 
| 
      
 83 
     | 
    
         
            +
            				buffer << pretty(value, indent:)
         
     | 
| 
       83 
84 
     | 
    
         
             
            				buffer << ",\n"
         
     | 
| 
       84 
85 
     | 
    
         
             
            			end
         
     | 
| 
       85 
86 
     | 
    
         
             
            			indent -= 1
         
     | 
| 
       86 
87 
     | 
    
         
             
            			buffer << ("	" * indent)
         
     | 
| 
       87 
88 
     | 
    
         
             
            			buffer << "}"
         
     | 
| 
       88 
89 
     | 
    
         
             
            		when Array
         
     | 
| 
       89 
     | 
    
         
            -
            			 
     | 
| 
       90 
     | 
    
         
            -
            			 
     | 
| 
       91 
     | 
    
         
            -
            			object. 
     | 
| 
       92 
     | 
    
         
            -
            				 
     | 
| 
       93 
     | 
    
         
            -
            				 
     | 
| 
       94 
     | 
    
         
            -
            				 
     | 
| 
      
 90 
     | 
    
         
            +
            			new_lines = false
         
     | 
| 
      
 91 
     | 
    
         
            +
            			length = 0
         
     | 
| 
      
 92 
     | 
    
         
            +
            			items = object.map do |item|
         
     | 
| 
      
 93 
     | 
    
         
            +
            				pretty_item = pretty(item, indent: indent + 1)
         
     | 
| 
      
 94 
     | 
    
         
            +
            				new_lines = true if pretty_item.include?("\n")
         
     | 
| 
      
 95 
     | 
    
         
            +
            				length += pretty_item.bytesize
         
     | 
| 
      
 96 
     | 
    
         
            +
            				pretty_item
         
     | 
| 
      
 97 
     | 
    
         
            +
            			end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
            			if new_lines || length > max_width - (indent * indent_width)
         
     | 
| 
      
 100 
     | 
    
         
            +
            				"[\n#{indentation_bytes * (indent + 1)}#{items.join(",\n#{indentation_bytes * (indent + 1)}")},\n#{indentation_bytes * indent}]"
         
     | 
| 
      
 101 
     | 
    
         
            +
            			else
         
     | 
| 
      
 102 
     | 
    
         
            +
            				"[#{items.join(', ')}]"
         
     | 
| 
       95 
103 
     | 
    
         
             
            			end
         
     | 
| 
       96 
     | 
    
         
            -
            			indent -= 1
         
     | 
| 
       97 
     | 
    
         
            -
            			buffer << ("	" * indent)
         
     | 
| 
       98 
     | 
    
         
            -
            			buffer << "]"
         
     | 
| 
       99 
104 
     | 
    
         
             
            		when Set
         
     | 
| 
       100 
     | 
    
         
            -
            			 
     | 
| 
       101 
     | 
    
         
            -
            			 
     | 
| 
       102 
     | 
    
         
            -
            			object.to_a.sort!. 
     | 
| 
       103 
     | 
    
         
            -
            				 
     | 
| 
       104 
     | 
    
         
            -
            				 
     | 
| 
       105 
     | 
    
         
            -
            				 
     | 
| 
      
 105 
     | 
    
         
            +
            			new_lines = false
         
     | 
| 
      
 106 
     | 
    
         
            +
            			length = 0
         
     | 
| 
      
 107 
     | 
    
         
            +
            			items = object.to_a.sort!.map do |item|
         
     | 
| 
      
 108 
     | 
    
         
            +
            				pretty_item = pretty(item, indent: indent + 1)
         
     | 
| 
      
 109 
     | 
    
         
            +
            				new_lines = true if pretty_item.include?("\n")
         
     | 
| 
      
 110 
     | 
    
         
            +
            				length += pretty_item.bytesize
         
     | 
| 
      
 111 
     | 
    
         
            +
            				pretty_item
         
     | 
| 
       106 
112 
     | 
    
         
             
            			end
         
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
            			 
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
            			if new_lines || length > max_width - (indent * indent_width)
         
     | 
| 
      
 115 
     | 
    
         
            +
            				"Set[\n#{indentation_bytes * (indent + 1)}#{items.join(",\n#{indentation_bytes * (indent + 1)}")},\n#{indentation_bytes * indent}]"
         
     | 
| 
      
 116 
     | 
    
         
            +
            			else
         
     | 
| 
      
 117 
     | 
    
         
            +
            				"Set[#{items.join(', ')}]"
         
     | 
| 
      
 118 
     | 
    
         
            +
            			end
         
     | 
| 
      
 119 
     | 
    
         
            +
            		when Module
         
     | 
| 
      
 120 
     | 
    
         
            +
            			object.name
         
     | 
| 
       110 
121 
     | 
    
         
             
            		when Symbol, String, Integer, Float, Regexp, Range, Rational, Complex, true, false, nil
         
     | 
| 
       111 
     | 
    
         
            -
            			 
     | 
| 
      
 122 
     | 
    
         
            +
            			object.inspect
         
     | 
| 
       112 
123 
     | 
    
         
             
            		else
         
     | 
| 
       113 
     | 
    
         
            -
            			buffer  
     | 
| 
       114 
     | 
    
         
            -
            			 
     | 
| 
       115 
     | 
    
         
            -
            			 
     | 
| 
      
 124 
     | 
    
         
            +
            			buffer = +""
         
     | 
| 
      
 125 
     | 
    
         
            +
            			instance_variables = object.instance_variables
         
     | 
| 
      
 126 
     | 
    
         
            +
            			if instance_variables.length > 0
         
     | 
| 
      
 127 
     | 
    
         
            +
            				buffer << "#{object.class.name}(\n"
         
     | 
| 
      
 128 
     | 
    
         
            +
            				indent += 1
         
     | 
| 
      
 129 
     | 
    
         
            +
            				object.instance_variables.each do |name|
         
     | 
| 
      
 130 
     | 
    
         
            +
            					buffer << ("	" * indent)
         
     | 
| 
      
 131 
     | 
    
         
            +
            					buffer << ":#{name} => "
         
     | 
| 
      
 132 
     | 
    
         
            +
            					buffer << pretty(object.instance_variable_get(name), indent:)
         
     | 
| 
      
 133 
     | 
    
         
            +
            					buffer << ",\n"
         
     | 
| 
      
 134 
     | 
    
         
            +
            				end
         
     | 
| 
      
 135 
     | 
    
         
            +
            				indent -= 1
         
     | 
| 
       116 
136 
     | 
    
         
             
            				buffer << ("	" * indent)
         
     | 
| 
       117 
     | 
    
         
            -
            				buffer << " 
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
            				buffer << " 
     | 
| 
      
 137 
     | 
    
         
            +
            				buffer << ")"
         
     | 
| 
      
 138 
     | 
    
         
            +
            			else
         
     | 
| 
      
 139 
     | 
    
         
            +
            				buffer << "#{object.class.name}()"
         
     | 
| 
       120 
140 
     | 
    
         
             
            			end
         
     | 
| 
       121 
     | 
    
         
            -
            			indent -= 1
         
     | 
| 
       122 
     | 
    
         
            -
            			buffer << ("	" * indent)
         
     | 
| 
       123 
     | 
    
         
            -
            			buffer << ")"
         
     | 
| 
       124 
141 
     | 
    
         
             
            		end
         
     | 
| 
       125 
142 
     | 
    
         
             
            	end
         
     | 
| 
       126 
143 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: difftastic
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: x86_64-linux
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Joel Drapper
         
     | 
| 
       8 
8 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       9 
9 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       10 
     | 
    
         
            -
            date: 2025-01- 
     | 
| 
      
 10 
     | 
    
         
            +
            date: 2025-01-23 00:00:00.000000000 Z
         
     | 
| 
       11 
11 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       12 
12 
     | 
    
         
             
            email:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - joel@drapper.me
         
     | 
| 
         @@ -22,6 +22,7 @@ files: 
     | 
|
| 
       22 
22 
     | 
    
         
             
            - exe/difft
         
     | 
| 
       23 
23 
     | 
    
         
             
            - exe/x86_64-linux/difft
         
     | 
| 
       24 
24 
     | 
    
         
             
            - lib/difftastic.rb
         
     | 
| 
      
 25 
     | 
    
         
            +
            - lib/difftastic/ansi.rb
         
     | 
| 
       25 
26 
     | 
    
         
             
            - lib/difftastic/differ.rb
         
     | 
| 
       26 
27 
     | 
    
         
             
            - lib/difftastic/upstream.rb
         
     | 
| 
       27 
28 
     | 
    
         
             
            - lib/difftastic/version.rb
         
     |