MCPcopy Create free account
hub / github.com/Mic92/nix-diff-rs / format_string_diff

Method format_string_diff

src/render.rs:241–276  ·  view source on GitHub ↗
(&self, output: &mut Vec<u8>, diff: &StringDiff, indent: usize)

Source from the content-addressed store, hash-verified

239 }
240
241 fn format_string_diff(&self, output: &mut Vec<u8>, diff: &StringDiff, indent: usize) {
242 let StringDiff { old, new } = diff;
243 if self.inline_highlight {
244 // Single-line pair: run a word-level diff once and highlight only
245 // the changed segments on each side. This makes store-path hash
246 // changes and version bumps immediately visible.
247 let old_toks = tokenize_path(old);
248 let new_toks = tokenize_path(new);
249 let ops = similar::capture_diff_slices(similar::Algorithm::Myers, &old_toks, &new_toks);
250 self.write_inline_line(
251 output,
252 indent,
253 self.red(),
254 b"- ",
255 &ops,
256 &old_toks,
257 &new_toks,
258 true,
259 );
260 self.write_inline_line(
261 output,
262 indent,
263 self.green(),
264 b"+ ",
265 &ops,
266 &old_toks,
267 &new_toks,
268 false,
269 );
270 } else {
271 self.write_indent(output, indent);
272 extend!(output, self.red(), b"- ", old, self.reset(), b"\n");
273 self.write_indent(output, indent);
274 extend!(output, self.green(), b"+ ", new, self.reset(), b"\n");
275 }
276 }
277
278 /// Write one side of an old/new pair with reverse-video highlighting on
279 /// the segments that differ. Tokenization is done by the caller so the

Callers 4

format_output_diffMethod · 0.80
format_env_var_diffMethod · 0.80

Calls 5

tokenize_pathFunction · 0.85
write_inline_lineMethod · 0.80
redMethod · 0.80
greenMethod · 0.80
write_indentMethod · 0.80

Tested by 1