@@ -46,6 +46,11 @@ pub fn search(
46
46
. map ( |desc| truncate_with_ellipsis ( & desc. replace ( "\n " , " " ) , description_length) )
47
47
} ) ;
48
48
49
+ let mut shell = config. shell ( ) ;
50
+ let stdout = shell. out ( ) ;
51
+ let good = style:: GOOD . render ( ) ;
52
+ let reset = anstyle:: Reset . render ( ) ;
53
+
49
54
for ( name, description) in names. into_iter ( ) . zip ( descriptions) {
50
55
let line = match description {
51
56
Some ( desc) => {
@@ -58,22 +63,20 @@ pub fn search(
58
63
} ;
59
64
let mut fragments = line. split ( query) . peekable ( ) ;
60
65
while let Some ( fragment) = fragments. next ( ) {
61
- let _ = config . shell ( ) . write_stdout ( fragment , & style :: NOP ) ;
66
+ let _ = write ! ( stdout , "{fragment}" ) ;
62
67
if fragments. peek ( ) . is_some ( ) {
63
- let _ = config . shell ( ) . write_stdout ( query , & style :: GOOD ) ;
68
+ let _ = write ! ( stdout , "{good}{query}{reset}" ) ;
64
69
}
65
70
}
66
- let _ = config . shell ( ) . write_stdout ( " \n " , & style :: NOP ) ;
71
+ let _ = writeln ! ( stdout ) ;
67
72
}
68
73
69
74
let search_max_limit = 100 ;
70
75
if total_crates > limit && limit < search_max_limit {
71
- let _ = config. shell ( ) . write_stdout (
72
- format_args ! (
73
- "... and {} crates more (use --limit N to see more)\n " ,
74
- total_crates - limit
75
- ) ,
76
- & style:: NOP ,
76
+ let _ = writeln ! (
77
+ stdout,
78
+ "... and {} crates more (use --limit N to see more)" ,
79
+ total_crates - limit
77
80
) ;
78
81
} else if total_crates > limit && limit >= search_max_limit {
79
82
let extra = if source_ids. original . is_crates_io ( ) {
@@ -82,9 +85,11 @@ pub fn search(
82
85
} else {
83
86
String :: new ( )
84
87
} ;
85
- let _ = config. shell ( ) . write_stdout (
86
- format_args ! ( "... and {} crates more{}\n " , total_crates - limit, extra) ,
87
- & style:: NOP ,
88
+ let _ = writeln ! (
89
+ stdout,
90
+ "... and {} crates more{}" ,
91
+ total_crates - limit,
92
+ extra
88
93
) ;
89
94
}
90
95
0 commit comments