difftastic 0.6.1-aarch64-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 +7 -0
- data/LICENSE-DEPENDENCIES.md +3509 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/exe/aarch64-linux/difft +0 -0
- data/exe/difft +7 -0
- data/lib/difftastic/ansi.rb +23 -0
- data/lib/difftastic/differ.rb +374 -0
- data/lib/difftastic/upstream.rb +15 -0
- data/lib/difftastic/version.rb +5 -0
- data/lib/difftastic.rb +79 -0
- metadata +67 -0
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Joel Drapper
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Difftastic Ruby
|
|
2
|
+
|
|
3
|
+
A Ruby interface and wrapper for the wonderful [Difftastic](https://difftastic.wilfred.me.uk) CLI tool.
|
|
4
|
+
|
|
5
|
+
## Creating a Differ
|
|
6
|
+
|
|
7
|
+
First, create a differ with your configuration:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
MY_DIFFER = Difftastic::Differ.new(
|
|
11
|
+
background: :dark,
|
|
12
|
+
color: :always,
|
|
13
|
+
left_label: "Expected",
|
|
14
|
+
right_label: "Actual"
|
|
15
|
+
)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Diffing Objects
|
|
19
|
+
|
|
20
|
+
You can diff objects with different configurations:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
a = { foo: 1, bar: [2, 3, 4] }
|
|
24
|
+
b = { foo: 1, bar: [2, 4, 3] }
|
|
25
|
+
|
|
26
|
+
puts MY_DIFFER.diff_objects(a, b)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Diffing Ruby Code
|
|
30
|
+
|
|
31
|
+
You can diff Ruby code:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
a = <<~RUBY
|
|
35
|
+
def hello
|
|
36
|
+
puts "Hello, world!"
|
|
37
|
+
end
|
|
38
|
+
RUBY
|
|
39
|
+
|
|
40
|
+
b = <<~RUBY
|
|
41
|
+
def hello
|
|
42
|
+
puts "Goodbye, world!"
|
|
43
|
+
end
|
|
44
|
+
RUBY
|
|
45
|
+
|
|
46
|
+
puts MY_DIFFER.diff_ruby(a, b)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Additional File Type Methods
|
|
50
|
+
|
|
51
|
+
You can also diff other file types using the following methods:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
a = "<html>\n\t<body>\n\t\t<h1>Hello, world!</h1>\n\t</body>\n</html>"
|
|
55
|
+
b = "<html>\n\t<body>\n\t\t<h1>Goodbye, world!</h1>\n\t</body>\n</html>"
|
|
56
|
+
|
|
57
|
+
puts MY_DIFFER.diff_html(a, b)
|
|
58
|
+
|
|
59
|
+
a = '{ "foo": 1, "bar": 2 }'
|
|
60
|
+
b = '{ "foo": 1, "bar": 3 }'
|
|
61
|
+
|
|
62
|
+
puts MY_DIFFER.diff_json(a, b)
|
|
63
|
+
|
|
64
|
+
a = "body { color: red; }"
|
|
65
|
+
b = "body { color: blue; }"
|
|
66
|
+
|
|
67
|
+
puts MY_DIFFER.diff_css(a, b)
|
|
68
|
+
|
|
69
|
+
a = "<note><to>Tove</to><from>Jani</from></note>"
|
|
70
|
+
b = "<note><to>Tove</to><from>John</from></note>"
|
|
71
|
+
|
|
72
|
+
puts MY_DIFFER.diff_xml(a, b)
|
|
73
|
+
|
|
74
|
+
a = "foo: 1\nbar: 2"
|
|
75
|
+
b = "foo: 1\nbar: 3"
|
|
76
|
+
|
|
77
|
+
puts MY_DIFFER.diff_yaml(a, b)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Configuring Difftastic::Differ
|
|
81
|
+
|
|
82
|
+
You can configure the `Difftastic::Differ` instance with various options:
|
|
83
|
+
|
|
84
|
+
- `background`: Set the background color (`:dark` or `:light`).
|
|
85
|
+
- `color`: Set the color mode (`:always`, `:never`, or `:auto`).
|
|
86
|
+
- `syntax_highlight`: Enable or disable syntax highlighting (`:on` or `:off`).
|
|
87
|
+
- `context`: Set the number of context lines to display.
|
|
88
|
+
- `width`: Use this many columns when calculating line wrapping. If not specified, difftastic will detect the terminal width.
|
|
89
|
+
- `tab_width`: Set the tab width for indentation.
|
|
90
|
+
- `parse_error_limit`: Set the limit for parse errors.
|
|
91
|
+
- `underline_highlights`: Enable or disable underlining highlights (`true` or `false`).
|
|
92
|
+
- `left_label`: Set the label for the left side of the diff.
|
|
93
|
+
- `right_label`: Set the label for the right side of the diff.
|
|
94
|
+
- `display`: Set the display mode (`"side-by-side-show-both"`, `"side-by-side"`, or `"inline"`).
|
|
95
|
+
|
|
96
|
+
## Pretty Method
|
|
97
|
+
|
|
98
|
+
The `Difftastic` module includes a `pretty` method for formatting objects:
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
object = { foo: 1, bar: [2, 3, 4] }
|
|
102
|
+
formatted_object = Difftastic.pretty(object)
|
|
103
|
+
puts formatted_object
|
|
104
|
+
```
|
|
Binary file
|
data/exe/difft
ADDED
|
@@ -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
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Difftastic::Differ
|
|
4
|
+
DEFAULT_TAB_WIDTH = 2
|
|
5
|
+
|
|
6
|
+
def initialize(background: nil, color: nil, syntax_highlight: nil, context: nil, width: nil, tab_width: nil, parse_error_limit: nil, underline_highlights: true, left_label: nil, right_label: nil, display: "side-by-side-show-both")
|
|
7
|
+
@show_paths = false
|
|
8
|
+
@background = background => :dark | :light | nil
|
|
9
|
+
@color = color => :always | :never | :auto | nil
|
|
10
|
+
@syntax_highlight = syntax_highlight => :on | :off | nil
|
|
11
|
+
@context = context => Integer | nil
|
|
12
|
+
@width = width => Integer | nil
|
|
13
|
+
@tab_width = tab_width => Integer | nil
|
|
14
|
+
@parse_error_limit = parse_error_limit => Integer | nil
|
|
15
|
+
@underline_highlights = underline_highlights => true | false
|
|
16
|
+
@left_label = left_label => String | nil
|
|
17
|
+
@right_label = right_label => String | nil
|
|
18
|
+
@display = display
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def diff_objects(old, new)
|
|
22
|
+
tab_width = @tab_width || DEFAULT_TAB_WIDTH
|
|
23
|
+
|
|
24
|
+
old = Difftastic.pretty(old, tab_width:)
|
|
25
|
+
new = Difftastic.pretty(new, tab_width:)
|
|
26
|
+
|
|
27
|
+
diff_strings(old, new, file_extension: "rb")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def diff_ada(old, new)
|
|
31
|
+
diff_strings(old, new, file_extension: "ada")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def diff_apex(old, new)
|
|
35
|
+
diff_strings(old, new, file_extension: "apex")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def diff_bash(old, new)
|
|
39
|
+
diff_strings(old, new, file_extension: "sh")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def diff_c(old, new)
|
|
43
|
+
diff_strings(old, new, file_extension: "c")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def diff_cpp(old, new)
|
|
47
|
+
diff_strings(old, new, file_extension: "cpp")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def diff_csharp(old, new)
|
|
51
|
+
diff_strings(old, new, file_extension: "cs")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def diff_clojure(old, new)
|
|
55
|
+
diff_strings(old, new, file_extension: "clj")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def diff_cmake(old, new)
|
|
59
|
+
diff_strings(old, new, file_extension: "cmake")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def diff_commonlisp(old, new)
|
|
63
|
+
diff_strings(old, new, file_extension: "lisp")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def diff_dart(old, new)
|
|
67
|
+
diff_strings(old, new, file_extension: "dart")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def diff_devicetree(old, new)
|
|
71
|
+
diff_strings(old, new, file_extension: "dts")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def diff_elixir(old, new)
|
|
75
|
+
diff_strings(old, new, file_extension: "ex")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def diff_elm(old, new)
|
|
79
|
+
diff_strings(old, new, file_extension: "elm")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def diff_elvish(old, new)
|
|
83
|
+
diff_strings(old, new, file_extension: "elv")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def diff_erlang(old, new)
|
|
87
|
+
diff_strings(old, new, file_extension: "erl")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def diff_elisp(old, new)
|
|
91
|
+
diff_strings(old, new, file_extension: "el")
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def diff_fsharp(old, new)
|
|
95
|
+
diff_strings(old, new, file_extension: "fs")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def diff_gleam(old, new)
|
|
99
|
+
diff_strings(old, new, file_extension: "gleam")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def diff_go(old, new)
|
|
103
|
+
diff_strings(old, new, file_extension: "go")
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def diff_hack(old, new)
|
|
107
|
+
diff_strings(old, new, file_extension: "hack")
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def diff_hare(old, new)
|
|
111
|
+
diff_strings(old, new, file_extension: "ha")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def diff_haskell(old, new)
|
|
115
|
+
diff_strings(old, new, file_extension: "hs")
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def diff_janet(old, new)
|
|
119
|
+
diff_strings(old, new, file_extension: "janet")
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def diff_java(old, new)
|
|
123
|
+
diff_strings(old, new, file_extension: "java")
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def diff_javascript(old, new)
|
|
127
|
+
diff_strings(old, new, file_extension: "js")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def diff_jsx(old, new)
|
|
131
|
+
diff_strings(old, new, file_extension: "jsx")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def diff_julia(old, new)
|
|
135
|
+
diff_strings(old, new, file_extension: "jl")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def diff_kotlin(old, new)
|
|
139
|
+
diff_strings(old, new, file_extension: "kt")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def diff_lua(old, new)
|
|
143
|
+
diff_strings(old, new, file_extension: "lua")
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def diff_make(old, new)
|
|
147
|
+
diff_strings(old, new, file_extension: "mk")
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def diff_nix(old, new)
|
|
151
|
+
diff_strings(old, new, file_extension: "nix")
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def diff_objc(old, new)
|
|
155
|
+
diff_strings(old, new, file_extension: "m")
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def diff_ocaml(old, new)
|
|
159
|
+
diff_strings(old, new, file_extension: "ml")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def diff_perl(old, new)
|
|
163
|
+
diff_strings(old, new, file_extension: "pl")
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def diff_php(old, new)
|
|
167
|
+
diff_strings(old, new, file_extension: "php")
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def diff_python(old, new)
|
|
171
|
+
diff_strings(old, new, file_extension: "py")
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def diff_qml(old, new)
|
|
175
|
+
diff_strings(old, new, file_extension: "qml")
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def diff_r(old, new)
|
|
179
|
+
diff_strings(old, new, file_extension: "r")
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def diff_racket(old, new)
|
|
183
|
+
diff_strings(old, new, file_extension: "rkt")
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def diff_ruby(old, new)
|
|
187
|
+
diff_strings(old, new, file_extension: "rb")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def diff_rust(old, new)
|
|
191
|
+
diff_strings(old, new, file_extension: "rs")
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def diff_scala(old, new)
|
|
195
|
+
diff_strings(old, new, file_extension: "scala")
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def diff_scheme(old, new)
|
|
199
|
+
diff_strings(old, new, file_extension: "scm")
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def diff_smali(old, new)
|
|
203
|
+
diff_strings(old, new, file_extension: "smali")
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def diff_solidity(old, new)
|
|
207
|
+
diff_strings(old, new, file_extension: "sol")
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def diff_sql(old, new)
|
|
211
|
+
diff_strings(old, new, file_extension: "sql")
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def diff_swift(old, new)
|
|
215
|
+
diff_strings(old, new, file_extension: "swift")
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def diff_typescript(old, new)
|
|
219
|
+
diff_strings(old, new, file_extension: "ts")
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def diff_tsx(old, new)
|
|
223
|
+
diff_strings(old, new, file_extension: "tsx")
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def diff_vhdl(old, new)
|
|
227
|
+
diff_strings(old, new, file_extension: "vhdl")
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def diff_zig(old, new)
|
|
231
|
+
diff_strings(old, new, file_extension: "zig")
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def diff_css(old, new)
|
|
235
|
+
diff_strings(old, new, file_extension: "css")
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def diff_hcl(old, new)
|
|
239
|
+
diff_strings(old, new, file_extension: "hcl")
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def diff_html(old, new)
|
|
243
|
+
diff_strings(old, new, file_extension: "html")
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def diff_json(old, new)
|
|
247
|
+
diff_strings(old, new, file_extension: "json")
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def diff_latex(old, new)
|
|
251
|
+
diff_strings(old, new, file_extension: "tex")
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def diff_newick(old, new)
|
|
255
|
+
diff_strings(old, new, file_extension: "newick")
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def diff_scss(old, new)
|
|
259
|
+
diff_strings(old, new, file_extension: "scss")
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def diff_toml(old, new)
|
|
263
|
+
diff_strings(old, new, file_extension: "toml")
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def diff_xml(old, new)
|
|
267
|
+
diff_strings(old, new, file_extension: "xml")
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def diff_yaml(old, new)
|
|
271
|
+
diff_strings(old, new, file_extension: "yaml")
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def diff_strings(old, new, file_extension: nil)
|
|
275
|
+
old_file = Tempfile.new(["old", ".#{file_extension}"])
|
|
276
|
+
new_file = Tempfile.new(["new", ".#{file_extension}"])
|
|
277
|
+
|
|
278
|
+
old_file.write(old)
|
|
279
|
+
new_file.write(new)
|
|
280
|
+
|
|
281
|
+
old_file.close
|
|
282
|
+
new_file.close
|
|
283
|
+
|
|
284
|
+
diff_files(old_file, new_file)
|
|
285
|
+
ensure
|
|
286
|
+
old_file.unlink
|
|
287
|
+
new_file.unlink
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def diff_files(old_file, new_file)
|
|
291
|
+
options = [
|
|
292
|
+
(file_to_path(old_file)),
|
|
293
|
+
(file_to_path(new_file)),
|
|
294
|
+
("--color=#{@color}" if @color),
|
|
295
|
+
("--context=#{@context}" if @context),
|
|
296
|
+
("--background=#{@background}" if @background),
|
|
297
|
+
("--syntax-highlight=#{@syntax_highlight}" if @syntax_highlight),
|
|
298
|
+
("--tab-width=#{@tab_width}" if @tab_width),
|
|
299
|
+
("--display=#{@display}" if @display),
|
|
300
|
+
("--width=#{@width}" if @width),
|
|
301
|
+
].compact!
|
|
302
|
+
|
|
303
|
+
result = Difftastic.execute(options.join(" ")).lstrip.sub(/\n{2}\z/, "")
|
|
304
|
+
|
|
305
|
+
unless @show_paths
|
|
306
|
+
new_line_index = (result.index("\n") || 0) + 1
|
|
307
|
+
result = result.byteslice(new_line_index, result.bytesize - new_line_index)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
if @left_label || @right_label
|
|
311
|
+
# Get the first content line to calculate offset
|
|
312
|
+
offset_line = @show_paths ? 1 : 0
|
|
313
|
+
first_line = result.split("\n")[offset_line]
|
|
314
|
+
|
|
315
|
+
# Calculate padding needed between labels
|
|
316
|
+
offset = right_label_offset(first_line)
|
|
317
|
+
|
|
318
|
+
left_part = if @left_label
|
|
319
|
+
Difftastic::ANSI.red(@left_label.to_s.ljust(offset))
|
|
320
|
+
else
|
|
321
|
+
" " * offset
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
right_part = if @right_label
|
|
325
|
+
Difftastic::ANSI.green(@right_label.to_s)
|
|
326
|
+
else
|
|
327
|
+
""
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
# Insert formatted labels at the top
|
|
331
|
+
result = "#{left_part}#{right_part}#{Difftastic::ANSI.reset}\n#{result}"
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Removed due to inconsistencies in the original output. Need to improve the pattern matching.
|
|
335
|
+
# if @underline_highlights
|
|
336
|
+
# result.gsub!(/\e\[([0-9;]*)m/) {
|
|
337
|
+
# codes = $1
|
|
338
|
+
# if codes =~ /9[12];1|1;9[12]/ # Matches 91;1, 92;1, 1;91, or 1;92
|
|
339
|
+
# "\e[#{codes};4m"
|
|
340
|
+
# else
|
|
341
|
+
# "\e[#{codes}m"
|
|
342
|
+
# end
|
|
343
|
+
# }
|
|
344
|
+
# end
|
|
345
|
+
|
|
346
|
+
result
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
private
|
|
350
|
+
|
|
351
|
+
def right_label_offset(line)
|
|
352
|
+
tab_width = @tab_width || DEFAULT_TAB_WIDTH
|
|
353
|
+
stripped_line = ::Difftastic::ANSI.strip_formatting(line)
|
|
354
|
+
_lhs, rhs = stripped_line.split(/\s{#{tab_width},}/, 2)
|
|
355
|
+
|
|
356
|
+
index = stripped_line.index("#{' ' * tab_width}#{rhs}")
|
|
357
|
+
index = @width / 2 if @width && index.nil?
|
|
358
|
+
index = 0 if index.nil?
|
|
359
|
+
|
|
360
|
+
offset = index + tab_width
|
|
361
|
+
minimum_offset = 29
|
|
362
|
+
|
|
363
|
+
[minimum_offset, offset].max
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
def file_to_path(file)
|
|
367
|
+
return file if file.is_a?(String)
|
|
368
|
+
return file.path if file.is_a?(File)
|
|
369
|
+
return file.path if file.is_a?(Tempfile)
|
|
370
|
+
return file.to_s if file.is_a?(Pathname) # just to be explicit
|
|
371
|
+
|
|
372
|
+
file.to_s
|
|
373
|
+
end
|
|
374
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Difftastic
|
|
4
|
+
module Upstream
|
|
5
|
+
VERSION = "0.62.0"
|
|
6
|
+
|
|
7
|
+
NATIVE_PLATFORMS = {
|
|
8
|
+
"arm64-darwin" => "difft-aarch64-apple-darwin.tar.gz",
|
|
9
|
+
"arm64-linux" => "difft-aarch64-unknown-linux-gnu.tar.gz",
|
|
10
|
+
"aarch64-linux" => "difft-aarch64-unknown-linux-gnu.tar.gz",
|
|
11
|
+
"x86_64-darwin" => "difft-x86_64-apple-darwin.tar.gz",
|
|
12
|
+
"x86_64-linux" => "difft-x86_64-unknown-linux-gnu.tar.gz",
|
|
13
|
+
}.freeze
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/difftastic.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "difftastic/version"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
require "pretty_please"
|
|
6
|
+
|
|
7
|
+
module Difftastic
|
|
8
|
+
autoload :ANSI, "difftastic/ansi"
|
|
9
|
+
autoload :Differ, "difftastic/differ"
|
|
10
|
+
autoload :Upstream, "difftastic/upstream"
|
|
11
|
+
|
|
12
|
+
GEM_NAME = "difftastic"
|
|
13
|
+
DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "exe"))
|
|
14
|
+
|
|
15
|
+
class ExecutableNotFoundException < StandardError
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.execute(command)
|
|
19
|
+
`#{executable} #{command}`
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.platform
|
|
23
|
+
[:cpu, :os].map { |m| Gem::Platform.local.__send__(m) }.join("-")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.executable(exe_path: DEFAULT_DIR)
|
|
27
|
+
difftastic_install_dir = ENV["DIFFTASTIC_INSTALL_DIR"]
|
|
28
|
+
|
|
29
|
+
if difftastic_install_dir
|
|
30
|
+
if File.directory?(difftastic_install_dir)
|
|
31
|
+
warn "NOTE: using DIFFTASTIC_INSTALL_DIR to find difftastic executable: #{difftastic_install_dir}"
|
|
32
|
+
exe_path = difftastic_install_dir
|
|
33
|
+
exe_file = File.expand_path(File.join(difftastic_install_dir, "difft"))
|
|
34
|
+
else
|
|
35
|
+
raise DirectoryNotFoundException.new(<<~MESSAGE)
|
|
36
|
+
DIFFTASTIC_INSTALL_DIR is set to #{difftastic_install_dir}, but that directory does not exist.
|
|
37
|
+
MESSAGE
|
|
38
|
+
end
|
|
39
|
+
else
|
|
40
|
+
if Difftastic::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }
|
|
41
|
+
raise UnsupportedPlatformException.new(<<~MESSAGE)
|
|
42
|
+
difftastic-ruby does not support the #{platform} platform
|
|
43
|
+
Please install difftastic following instructions at https://difftastic.io/install
|
|
44
|
+
MESSAGE
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
exe_file = Dir.glob(File.expand_path(File.join(exe_path, "**", "difft"))).find do |f|
|
|
48
|
+
Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if exe_file.nil? || !File.exist?(exe_file)
|
|
53
|
+
raise ExecutableNotFoundException.new(<<~MESSAGE)
|
|
54
|
+
Cannot find the difftastic executable for #{platform} in #{exe_path}
|
|
55
|
+
|
|
56
|
+
If you're using bundler, please make sure you're on the latest bundler version:
|
|
57
|
+
|
|
58
|
+
gem install bundler
|
|
59
|
+
bundle update --bundler
|
|
60
|
+
|
|
61
|
+
Then make sure your lock file includes this platform by running:
|
|
62
|
+
|
|
63
|
+
bundle lock --add-platform #{platform}
|
|
64
|
+
bundle install
|
|
65
|
+
|
|
66
|
+
See `bundle lock --help` output for details.
|
|
67
|
+
|
|
68
|
+
If you're still seeing this message after taking those steps, try running
|
|
69
|
+
`bundle config` and ensure `force_ruby_platform` isn't set to `true`.
|
|
70
|
+
MESSAGE
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
exe_file
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.pretty(object, indent: 0, tab_width: 2, max_width: 60, max_depth: 5, max_items: 10)
|
|
77
|
+
PrettyPlease.prettify(object, indent:, tab_width:, max_width:, max_depth:, max_items:)
|
|
78
|
+
end
|
|
79
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: difftastic
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.6.1
|
|
5
|
+
platform: aarch64-linux
|
|
6
|
+
authors:
|
|
7
|
+
- Joel Drapper
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2025-12-19 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: pretty_please
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
email:
|
|
27
|
+
- joel@drapper.me
|
|
28
|
+
executables:
|
|
29
|
+
- difft
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- LICENSE-DEPENDENCIES.md
|
|
34
|
+
- LICENSE.txt
|
|
35
|
+
- README.md
|
|
36
|
+
- exe/aarch64-linux/difft
|
|
37
|
+
- exe/difft
|
|
38
|
+
- lib/difftastic.rb
|
|
39
|
+
- lib/difftastic/ansi.rb
|
|
40
|
+
- lib/difftastic/differ.rb
|
|
41
|
+
- lib/difftastic/upstream.rb
|
|
42
|
+
- lib/difftastic/version.rb
|
|
43
|
+
homepage: https://github.com/joeldrapper/difftastic-ruby
|
|
44
|
+
licenses:
|
|
45
|
+
- MIT
|
|
46
|
+
metadata:
|
|
47
|
+
homepage_uri: https://github.com/joeldrapper/difftastic-ruby
|
|
48
|
+
rubygems_mfa_required: 'true'
|
|
49
|
+
changelog_uri: https://github.com/joeldrapper/difftastic-ruby/releases
|
|
50
|
+
rdoc_options: []
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: 3.1.0
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
requirements: []
|
|
64
|
+
rubygems_version: 3.6.2
|
|
65
|
+
specification_version: 4
|
|
66
|
+
summary: Integrate Difftastic with the RubyGems infrastructure.
|
|
67
|
+
test_files: []
|