riffdiff 1.0.20 → 1.0.32
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/.rubocop.yml +5 -0
- data/README.md +6 -0
- data/Rakefile +3 -0
- data/lib/colors.rb +1 -0
- data/lib/diff_string.rb +20 -6
- data/lib/refiner.rb +8 -4
- data/lib/version.rb +9 -0
- data/spec/diff_string_spec.rb +107 -0
- data/spec/refiner_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a903c564f968253a85a9e511353e4bea5cdb53e2
|
4
|
+
data.tar.gz: f6348bd244e212c8c63239f7534c16eb8854e453
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073ae0437959a08a2c62fa0e44ec1f49f828b06ee9b900648bf6b030ce6fe2c33fc6a3c46dc666a85be829a9a7e530a550082be5809bae1fe0d4d895dd25aa14
|
7
|
+
data.tar.gz: 4e35509f4eefd273ae0dc218798cc8f22bfe1bd6dd8eba4369b9bce8135f09c531e8aba18b212c70dfbd45e7e7aedd7b5933479e25c1f5526a98997a30374192
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,10 @@ Optionally followed by...
|
|
24
24
|
|
25
25
|
# TODO
|
26
26
|
* Think about highlighting whitespace errors like Git does
|
27
|
+
* OK: Make DiffString.add() take a color as well
|
28
|
+
* Add a whitespace analysis pass to the Refiner
|
29
|
+
* Let the Refiner highlight whitespace errors among the added lines in reverse
|
30
|
+
red.
|
27
31
|
* Think about how to visualize an added line break together with some
|
28
32
|
indentation on the following line.
|
29
33
|
* Do "git show 57f27da" and think about what rule we should use to get
|
@@ -122,3 +126,5 @@ globally on the system.
|
|
122
126
|
still show the comma in reverse video though. Do this when:
|
123
127
|
* One line is replaced by many
|
124
128
|
* The diff contains only additions
|
129
|
+
* When special highighting an expansion, highlight the added parts in green
|
130
|
+
reverse, rather than black reverse. Testcase: `git show 7ea6877`
|
data/Rakefile
CHANGED
data/lib/colors.rb
CHANGED
data/lib/diff_string.rb
CHANGED
@@ -9,22 +9,31 @@ class DiffString
|
|
9
9
|
|
10
10
|
# Note that the color argument can be the empty string
|
11
11
|
def initialize(prefix, color)
|
12
|
-
@reverse = false
|
13
12
|
@prefix = prefix
|
14
|
-
@
|
13
|
+
@base_color = color
|
14
|
+
|
15
15
|
@string = ''
|
16
|
+
|
17
|
+
@reverse = false
|
18
|
+
@color = @base_color
|
19
|
+
@reset_color = color.empty? ? DEFAULT_COLOR : color
|
16
20
|
end
|
17
21
|
|
18
|
-
|
22
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
23
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
24
|
+
def add(string, reverse, color = '')
|
25
|
+
color = @reset_color if color.empty?
|
26
|
+
|
19
27
|
if reverse && string == "\n"
|
20
|
-
add('↵', true)
|
28
|
+
add('↵', true, color)
|
21
29
|
add("\n", false)
|
22
30
|
return
|
23
31
|
end
|
24
32
|
|
25
33
|
if @string.empty?() || @string.end_with?("\n")
|
26
|
-
@string += @
|
34
|
+
@string += @base_color
|
27
35
|
@string += @prefix
|
36
|
+
@color = @reset_color
|
28
37
|
end
|
29
38
|
|
30
39
|
if reverse != @reverse
|
@@ -32,6 +41,11 @@ class DiffString
|
|
32
41
|
end
|
33
42
|
@reverse = reverse
|
34
43
|
|
44
|
+
if color != @color
|
45
|
+
@string += color
|
46
|
+
end
|
47
|
+
@color = color
|
48
|
+
|
35
49
|
@string += string
|
36
50
|
end
|
37
51
|
|
@@ -41,7 +55,7 @@ class DiffString
|
|
41
55
|
string = @string
|
42
56
|
string.chomp! if string.end_with? "\n"
|
43
57
|
|
44
|
-
suffix = @
|
58
|
+
suffix = @base_color.empty? ? '' : RESET
|
45
59
|
return string + suffix + "\n"
|
46
60
|
end
|
47
61
|
|
data/lib/refiner.rb
CHANGED
@@ -95,10 +95,12 @@ class Refiner
|
|
95
95
|
return try_highlight(old, new)
|
96
96
|
end
|
97
97
|
|
98
|
-
def render_refinement(prefix, color, string, highlights,
|
98
|
+
def render_refinement(prefix, color, string, highlights,
|
99
|
+
base_index: 0, highlight_color: '')
|
99
100
|
return_me = DiffString.new(prefix, color)
|
100
101
|
string.each_char.with_index do |char, index|
|
101
|
-
|
102
|
+
highlight = highlights.include?(index + base_index)
|
103
|
+
return_me.add(char, highlight, highlight ? highlight_color : '')
|
102
104
|
end
|
103
105
|
return return_me.to_s
|
104
106
|
end
|
@@ -132,13 +134,15 @@ class Refiner
|
|
132
134
|
|
133
135
|
@refined_old = ''
|
134
136
|
|
135
|
-
refined_line_1 =
|
137
|
+
refined_line_1 =
|
138
|
+
render_refinement(' ', '', lines[0], new_highlights,
|
139
|
+
highlight_color: GREEN)
|
136
140
|
|
137
141
|
line_2_index_0 = lines[0].length
|
138
142
|
refined_remaining_lines = render_refinement('+', GREEN,
|
139
143
|
lines[1..-1].join,
|
140
144
|
new_highlights,
|
141
|
-
line_2_index_0)
|
145
|
+
base_index: line_2_index_0)
|
142
146
|
|
143
147
|
@refined_new = refined_line_1 + refined_remaining_lines
|
144
148
|
|
data/lib/version.rb
CHANGED
@@ -45,4 +45,13 @@ module Version
|
|
45
45
|
def dirty?
|
46
46
|
return git_version(true).include?('-dirty')
|
47
47
|
end
|
48
|
+
|
49
|
+
def git_branch
|
50
|
+
git_result = `cd #{__dir__} ; git rev-parse --abbrev-ref HEAD 2> /dev/null`
|
51
|
+
if $CHILD_STATUS.success?
|
52
|
+
return git_result.chomp
|
53
|
+
else
|
54
|
+
return nil
|
55
|
+
end
|
56
|
+
end
|
48
57
|
end
|
data/spec/diff_string_spec.rb
CHANGED
@@ -29,6 +29,113 @@ RSpec.describe DiffString, '#add' do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
context 'single char special color, on green' do
|
33
|
+
diff_string = DiffString.new('+', GREEN)
|
34
|
+
diff_string.add('1', false)
|
35
|
+
diff_string.add('2', true, RED)
|
36
|
+
diff_string.add('3', false)
|
37
|
+
diff_string.add("\n", false)
|
38
|
+
|
39
|
+
it 'renders correctly' do
|
40
|
+
expect(diff_string.to_s).to eq(
|
41
|
+
"#{GREEN}+1#{reversed("#{RED}2")}#{GREEN}3#{RESET}\n")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'double char special color, on green' do
|
46
|
+
diff_string = DiffString.new('+', GREEN)
|
47
|
+
diff_string.add('1', false)
|
48
|
+
diff_string.add('2', true, RED)
|
49
|
+
diff_string.add('x', true, RED)
|
50
|
+
diff_string.add('3', false)
|
51
|
+
diff_string.add("\n", false)
|
52
|
+
|
53
|
+
it 'renders correctly' do
|
54
|
+
expect(diff_string.to_s).to eq(
|
55
|
+
"#{GREEN}+1#{reversed("#{RED}2x")}#{GREEN}3#{RESET}\n")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'special color at start, on green' do
|
60
|
+
diff_string = DiffString.new('+', GREEN)
|
61
|
+
diff_string.add('1', true, RED)
|
62
|
+
diff_string.add('2', false)
|
63
|
+
diff_string.add('3', false)
|
64
|
+
diff_string.add("\n", false)
|
65
|
+
|
66
|
+
it 'renders correctly' do
|
67
|
+
expect(diff_string.to_s).to eq(
|
68
|
+
"#{GREEN}+#{reversed("#{RED}1")}#{GREEN}23#{RESET}\n")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'special color at end, on green' do
|
73
|
+
diff_string = DiffString.new('+', GREEN)
|
74
|
+
diff_string.add('1', false)
|
75
|
+
diff_string.add('2', false)
|
76
|
+
diff_string.add('3', true, RED)
|
77
|
+
diff_string.add("\n", false)
|
78
|
+
|
79
|
+
it 'renders correctly' do
|
80
|
+
expect(diff_string.to_s).to eq(
|
81
|
+
"#{GREEN}+12#{reversed("#{RED}3")}#{GREEN}#{RESET}\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'special color before reverse, on green' do
|
86
|
+
diff_string = DiffString.new('+', GREEN)
|
87
|
+
diff_string.add('1', false)
|
88
|
+
diff_string.add('2', true, RED)
|
89
|
+
diff_string.add('3', true)
|
90
|
+
diff_string.add("\n", false)
|
91
|
+
|
92
|
+
it 'renders correctly' do
|
93
|
+
expect(diff_string.to_s).to eq(
|
94
|
+
"#{GREEN}+1#{reversed("#{RED}2#{GREEN}3")}#{RESET}\n")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'special color after reverse, on green' do
|
99
|
+
diff_string = DiffString.new('+', GREEN)
|
100
|
+
diff_string.add('1', false)
|
101
|
+
diff_string.add('2', true)
|
102
|
+
diff_string.add('3', true, RED)
|
103
|
+
diff_string.add("\n", false)
|
104
|
+
|
105
|
+
it 'renders correctly' do
|
106
|
+
expect(diff_string.to_s).to eq(
|
107
|
+
"#{GREEN}+1#{reversed("2#{RED}3")}#{GREEN}#{RESET}\n")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'special color at end of first line, on green' do
|
112
|
+
diff_string = DiffString.new('+', GREEN)
|
113
|
+
diff_string.add('1', false)
|
114
|
+
diff_string.add('2', true, RED)
|
115
|
+
diff_string.add("\n", false)
|
116
|
+
diff_string.add('3', false)
|
117
|
+
diff_string.add("\n", false)
|
118
|
+
|
119
|
+
it 'renders correctly' do
|
120
|
+
expect(diff_string.to_s).to eq(
|
121
|
+
"#{GREEN}+1#{reversed("#{RED}2")}#{GREEN}\n#{GREEN}+3#{RESET}\n")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'special color before reversed newline, on green' do
|
126
|
+
diff_string = DiffString.new('+', GREEN)
|
127
|
+
diff_string.add('1', false)
|
128
|
+
diff_string.add('2', true, RED)
|
129
|
+
diff_string.add("\n", true)
|
130
|
+
diff_string.add('3', false)
|
131
|
+
diff_string.add("\n", false)
|
132
|
+
|
133
|
+
it 'renders correctly' do
|
134
|
+
expect(diff_string.to_s).to eq(
|
135
|
+
"#{GREEN}+1#{reversed("#{RED}2#{GREEN}↵")}\n#{GREEN}+3#{RESET}\n")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
32
139
|
context 'multiline' do
|
33
140
|
it 'colors both lines' do
|
34
141
|
diff_string = DiffString.new('+', GREEN)
|
data/spec/refiner_spec.rb
CHANGED
@@ -108,7 +108,7 @@ RSpec.describe Refiner, '#new' do
|
|
108
108
|
it %(pretends first line is unchanged, but highlights comma) do
|
109
109
|
expect(refiner.refined_old).to eq('')
|
110
110
|
expect(refiner.refined_new).to eq(
|
111
|
-
%( abcde#{reversed(
|
111
|
+
%( abcde#{reversed("#{GREEN},")}#{DEFAULT_COLOR}\n) +
|
112
112
|
%(#{GREEN}+fffff,\n) +
|
113
113
|
%(#{GREEN}+ggggg#{RESET}\n))
|
114
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riffdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Walles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|