| 321 | } |
| 322 | |
| 323 | func (h *hunk) writeTo(sb *strings.Builder, color ColorConfig) { |
| 324 | sb.WriteString(color[Frag]) |
| 325 | sb.WriteString("@@ -") |
| 326 | |
| 327 | if h.fromCount == 1 { |
| 328 | sb.WriteString(strconv.Itoa(h.fromLine)) |
| 329 | } else { |
| 330 | sb.WriteString(strconv.Itoa(h.fromLine)) |
| 331 | sb.WriteByte(',') |
| 332 | sb.WriteString(strconv.Itoa(h.fromCount)) |
| 333 | } |
| 334 | |
| 335 | sb.WriteString(" +") |
| 336 | |
| 337 | if h.toCount == 1 { |
| 338 | sb.WriteString(strconv.Itoa(h.toLine)) |
| 339 | } else { |
| 340 | sb.WriteString(strconv.Itoa(h.toLine)) |
| 341 | sb.WriteByte(',') |
| 342 | sb.WriteString(strconv.Itoa(h.toCount)) |
| 343 | } |
| 344 | |
| 345 | sb.WriteString(" @@") |
| 346 | sb.WriteString(color.Reset(Frag)) |
| 347 | |
| 348 | if h.ctxPrefix != "" { |
| 349 | sb.WriteByte(' ') |
| 350 | sb.WriteString(color[Func]) |
| 351 | sb.WriteString(h.ctxPrefix) |
| 352 | sb.WriteString(color.Reset(Func)) |
| 353 | } |
| 354 | |
| 355 | sb.WriteByte('\n') |
| 356 | |
| 357 | for _, op := range h.ops { |
| 358 | op.writeTo(sb, color) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | func (h *hunk) AddOp(t Operation, ss ...string) { |
| 363 | n := len(ss) |