@@ -114,15 +114,11 @@ pub fn color_repo(enabled: bool, name: &str) -> String {
114
114
return name. to_string ( ) ;
115
115
}
116
116
117
- let mut col: u32 = 5 ;
118
-
119
- for & b in name. as_bytes ( ) {
120
- col = ( b as u32 ) . wrapping_add ( ( col << 4 ) . wrapping_add ( col) ) ;
121
- }
122
-
123
- col = ( col % 6 ) + 9 ;
124
- let col = Style :: from ( Color :: Fixed ( col as u8 ) ) . bold ( ) ;
125
- col. paint ( name) . to_string ( )
117
+ let color = 9 + ( name. len ( ) % 6 ) as u8 ;
118
+ Style :: from ( Color :: Fixed ( color) )
119
+ . bold ( )
120
+ . paint ( name)
121
+ . to_string ( )
126
122
}
127
123
128
124
pub fn print_target ( targ : & str , quiet : bool ) {
@@ -443,13 +439,38 @@ pub fn print_install_verbose(config: &Config, actions: &Actions, devel: &HashSet
443
439
} ) ;
444
440
445
441
for pkg in & install {
446
- println ! (
447
- "{:<package_len$} {:<old_len$} {:<new_len$} {}" ,
448
- format!( "{}/{}" , pkg. pkg. db( ) . unwrap( ) . name( ) , pkg. pkg. name( ) ) ,
442
+ let repo_name = pkg. pkg . db ( ) . unwrap ( ) . name ( ) ;
443
+ let colored_repo = color_repo ( config. color . enabled , repo_name) ;
444
+ let pkg_str = format ! ( "{}/{}" , colored_repo, pkg. pkg. name( ) ) ;
445
+ let visible_width = repo_name. len ( ) + 1 + pkg. pkg . name ( ) . len ( ) ; // Calculate visible width without ANSI codes
446
+ let padding = " " . repeat ( package_len. saturating_sub ( visible_width) ) ;
447
+
448
+ let ( old_colored, new_colored) = colorize_version_diff (
449
449
db. pkg ( pkg. pkg . name ( ) )
450
450
. map ( |pkg| pkg. version ( ) . as_str ( ) )
451
451
. unwrap_or ( "" ) ,
452
452
pkg. pkg . version ( ) . as_str ( ) ,
453
+ ) ;
454
+
455
+ // Calculate visible width of the colored versions
456
+ let old_visible_width = db
457
+ . pkg ( pkg. pkg . name ( ) )
458
+ . map ( |pkg| pkg. version ( ) . as_str ( ) . len ( ) )
459
+ . unwrap_or ( 0 ) ;
460
+ let new_visible_width = pkg. pkg . version ( ) . as_str ( ) . len ( ) ;
461
+
462
+ // Add padding to maintain alignment
463
+ let old_padding = " " . repeat ( old_len. saturating_sub ( old_visible_width) ) ;
464
+ let new_padding = " " . repeat ( new_len. saturating_sub ( new_visible_width) ) ;
465
+
466
+ println ! (
467
+ "{}{} {}{} {}{} {}" ,
468
+ pkg_str,
469
+ padding,
470
+ old_colored,
471
+ old_padding,
472
+ new_colored,
473
+ new_padding,
453
474
if pkg. make { & yes } else { & no }
454
475
) ;
455
476
}
@@ -516,3 +537,53 @@ pub fn print_install_verbose(config: &Config, actions: &Actions, devel: &HashSet
516
537
517
538
println ! ( ) ;
518
539
}
540
+
541
+ fn colorize_version_diff ( old_ver : & str , new_ver : & str ) -> ( String , String ) {
542
+ if old_ver. is_empty ( ) {
543
+ return (
544
+ String :: new ( ) ,
545
+ Style :: new ( ) . fg ( Color :: Green ) . paint ( new_ver) . to_string ( ) , // all green for new version
546
+ ) ;
547
+ }
548
+
549
+ let mut old_colored = String :: new ( ) ;
550
+ let mut new_colored = String :: new ( ) ;
551
+
552
+ // Split versions into characters
553
+ let old_chars: Vec < char > = old_ver. chars ( ) . collect ( ) ;
554
+ let new_chars: Vec < char > = new_ver. chars ( ) . collect ( ) ;
555
+
556
+ // Find common prefix
557
+ let mut common_len = 0 ;
558
+ for ( a, b) in old_chars. iter ( ) . zip ( new_chars. iter ( ) ) {
559
+ if a == b {
560
+ common_len += 1 ;
561
+ } else {
562
+ break ;
563
+ }
564
+ }
565
+
566
+ // Color the old version (red for different parts)
567
+ old_colored. push_str ( & old_ver[ ..common_len] ) ;
568
+ if common_len < old_ver. len ( ) {
569
+ old_colored. push_str (
570
+ & Style :: new ( )
571
+ . fg ( Color :: Red )
572
+ . paint ( & old_ver[ common_len..] )
573
+ . to_string ( ) ,
574
+ ) ;
575
+ }
576
+
577
+ // Color the new version (green for different parts)
578
+ new_colored. push_str ( & new_ver[ ..common_len] ) ;
579
+ if common_len < new_ver. len ( ) {
580
+ new_colored. push_str (
581
+ & Style :: new ( )
582
+ . fg ( Color :: Green )
583
+ . paint ( & new_ver[ common_len..] )
584
+ . to_string ( ) ,
585
+ ) ;
586
+ }
587
+
588
+ ( old_colored, new_colored)
589
+ }
0 commit comments