|
1 | 1 | use super::utils::graphrow::{ |
2 | 2 | SYM_BRANCH_DOWN, SYM_BRANCH_UP, SYM_BRANCH_UP_RIGHT, SYM_COMMIT, |
3 | 3 | SYM_COMMIT_BRANCH, SYM_COMMIT_MERGE, SYM_COMMIT_STASH, |
4 | | - SYM_COMMIT_UNCOMMITTED, SYM_HORIZONTAL, SYM_MERGE_BRIDGE_END, |
| 4 | + SYM_COMMIT_UNCOMMITTED, SYM_CROSS, SYM_HORIZONTAL, SYM_MERGE_BRIDGE_END, |
5 | 5 | SYM_MERGE_BRIDGE_MID, SYM_MERGE_BRIDGE_START, SYM_SPACE, |
6 | 6 | SYM_VERTICAL, SYM_VERTICAL_DOTTED, |
7 | 7 | }; |
@@ -46,6 +46,15 @@ use std::{ |
46 | 46 | const ELEMENTS_PER_LINE: usize = 9; |
47 | 47 | const SLICE_SIZE: usize = 1200; |
48 | 48 |
|
| 49 | +const GRAPH_COLORS: &[Color] = &[ |
| 50 | + Color::Blue, |
| 51 | + Color::Yellow, |
| 52 | + Color::Magenta, |
| 53 | + Color::Cyan, |
| 54 | + Color::Green, |
| 55 | + Color::Red, |
| 56 | +]; |
| 57 | + |
49 | 58 | /// |
50 | 59 | pub struct CommitList { |
51 | 60 | repo: RepoPathRef, |
@@ -487,76 +496,80 @@ impl CommitList { |
487 | 496 | ) -> Vec<Span<'a>> { |
488 | 497 | let mut spans = Vec::new(); |
489 | 498 |
|
490 | | - let graph_color = |
491 | | - self.theme.commit_hash(false).fg.unwrap_or(Color::Reset); |
492 | | - |
493 | 499 | for (lane_index, conn) in row.lanes.iter().enumerate() { |
494 | 500 | if empty_lanes.contains(&lane_index) { |
495 | 501 | continue; |
496 | 502 | } |
497 | | - let (sym, color) = match conn { |
| 503 | + let (sym, graph_color) = match conn { |
498 | 504 | None => (SYM_SPACE, Color::Reset), |
499 | | - Some((ConnType::Vertical, _)) => { |
500 | | - (SYM_VERTICAL, graph_color) |
| 505 | + Some((ConnType::Vertical, color_idx)) => { |
| 506 | + (SYM_VERTICAL, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
| 507 | + } |
| 508 | + Some((ConnType::VerticalDotted, color_idx)) => { |
| 509 | + (SYM_VERTICAL_DOTTED, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
501 | 510 | } |
502 | | - Some((ConnType::VerticalDotted, _)) => { |
503 | | - (SYM_VERTICAL_DOTTED, graph_color) |
| 511 | + Some((ConnType::Cross, color_idx)) => { |
| 512 | + (SYM_CROSS, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
504 | 513 | } |
505 | | - Some((ConnType::CommitNormal, _)) => { |
506 | | - (SYM_COMMIT, graph_color) |
| 514 | + Some((ConnType::CommitNormal, color_idx)) => { |
| 515 | + (SYM_COMMIT, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
507 | 516 | } |
508 | | - Some((ConnType::CommitBranch, _)) => { |
509 | | - (SYM_COMMIT_BRANCH, graph_color) |
| 517 | + Some((ConnType::CommitBranch, color_idx)) => { |
| 518 | + (SYM_COMMIT_BRANCH, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
510 | 519 | } |
511 | | - Some((ConnType::CommitMerge, _)) => { |
512 | | - (SYM_COMMIT_MERGE, graph_color) |
| 520 | + Some((ConnType::CommitMerge, color_idx)) => { |
| 521 | + (SYM_COMMIT_MERGE, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
513 | 522 | } |
514 | | - Some((ConnType::CommitStash, _)) => { |
515 | | - (SYM_COMMIT_STASH, graph_color) |
| 523 | + Some((ConnType::CommitStash, color_idx)) => { |
| 524 | + (SYM_COMMIT_STASH, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
516 | 525 | } |
517 | | - Some((ConnType::CommitUncommitted, _)) => { |
518 | | - (SYM_COMMIT_UNCOMMITTED, graph_color) |
| 526 | + Some((ConnType::CommitUncommitted, color_idx)) => { |
| 527 | + (SYM_COMMIT_UNCOMMITTED, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
519 | 528 | } |
520 | | - Some((ConnType::MergeBridgeStart, _)) => { |
521 | | - (SYM_MERGE_BRIDGE_START, graph_color) |
| 529 | + Some((ConnType::MergeBridgeStart, color_idx)) => { |
| 530 | + (SYM_MERGE_BRIDGE_START, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
522 | 531 | } |
523 | | - Some((ConnType::MergeBridgeMid, _)) => { |
524 | | - (SYM_MERGE_BRIDGE_MID, graph_color) |
| 532 | + Some((ConnType::MergeBridgeMid, color_idx)) => { |
| 533 | + (SYM_MERGE_BRIDGE_MID, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
525 | 534 | } |
526 | | - Some((ConnType::MergeBridgeEnd, _)) => { |
527 | | - (SYM_MERGE_BRIDGE_END, graph_color) |
| 535 | + Some((ConnType::MergeBridgeEnd, color_idx)) => { |
| 536 | + (SYM_MERGE_BRIDGE_END, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
528 | 537 | } |
529 | | - Some((ConnType::BranchDown, _)) => { |
530 | | - (SYM_BRANCH_DOWN, graph_color) |
| 538 | + Some((ConnType::BranchDown, color_idx)) => { |
| 539 | + (SYM_BRANCH_DOWN, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
531 | 540 | } |
532 | | - Some((ConnType::BranchUp, _)) => { |
533 | | - (SYM_BRANCH_UP, graph_color) |
| 541 | + Some((ConnType::BranchUp, color_idx)) => { |
| 542 | + (SYM_BRANCH_UP, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
534 | 543 | } |
535 | | - Some((ConnType::BranchUpRight, _)) => { |
536 | | - (SYM_BRANCH_UP_RIGHT, graph_color) |
| 544 | + Some((ConnType::BranchUpRight, color_idx)) => { |
| 545 | + (SYM_BRANCH_UP_RIGHT, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()]) |
537 | 546 | } |
538 | 547 | }; |
539 | | - spans.push(Span::styled(sym, Style::default().fg(color))); |
| 548 | + spans.push(Span::styled(sym, Style::default().fg(graph_color))); |
540 | 549 |
|
541 | 550 | // Spacer |
542 | 551 | let mut is_bridge_lane = false; |
| 552 | + let mut spacer_color = graph_color; |
543 | 553 |
|
544 | 554 | if let Some((from, to)) = row.merge_bridge { |
545 | 555 | if lane_index >= from && lane_index < to { |
546 | 556 | is_bridge_lane = true; |
| 557 | + spacer_color = GRAPH_COLORS[row.commit_lane % GRAPH_COLORS.len()]; |
547 | 558 | } |
548 | 559 | } |
549 | 560 |
|
550 | 561 | for &(from, to) in &row.branches { |
551 | 562 | if lane_index >= from && lane_index < to { |
552 | 563 | is_bridge_lane = true; |
| 564 | + let branch_lane = if row.commit_lane == from { to } else { from }; |
| 565 | + spacer_color = GRAPH_COLORS[branch_lane % GRAPH_COLORS.len()]; |
553 | 566 | } |
554 | 567 | } |
555 | 568 |
|
556 | 569 | if is_bridge_lane { |
557 | 570 | spans.push(Span::styled( |
558 | 571 | SYM_HORIZONTAL, |
559 | | - Style::default().fg(graph_color), |
| 572 | + Style::default().fg(spacer_color), |
560 | 573 | )); |
561 | 574 | continue; |
562 | 575 | } |
@@ -1324,7 +1337,8 @@ mod tests { |
1324 | 1337 | let empty_lanes = std::collections::HashSet::new(); |
1325 | 1338 | let spans = cl.build_graph_spans(&row, 1, &empty_lanes); |
1326 | 1339 |
|
1327 | | - assert_eq!(spans.len(), 1); |
| 1340 | + assert_eq!(spans.len(), 2); |
1328 | 1341 | assert_eq!(spans[0].content, Cow::from(SYM_COMMIT)); |
| 1342 | + assert_eq!(spans[1].content, Cow::from(SYM_SPACE)); |
1329 | 1343 | } |
1330 | 1344 | } |
0 commit comments