@@ -6,6 +6,7 @@ use vite_path::RelativePath;
66
77use crate :: {
88 cache:: { CacheMiss , FingerprintMismatch } ,
9+ config:: { DisplayOptions , ResolvedTask } ,
910 fingerprint:: PostRunFingerprintMismatch ,
1011 schedule:: { CacheStatus , ExecutionFailure , ExecutionSummary , PreExecutionStatus } ,
1112} ;
@@ -22,27 +23,38 @@ impl<T: owo_colors::OwoColorize> ColorizeExt for T {
2223 }
2324}
2425
26+ const COMMAND_STYLE : Style = Style :: new ( ) . cyan ( ) ;
27+ const CACHE_MISS_STYLE : Style = Style :: new ( ) . purple ( ) ;
28+
29+ pub fn get_display_command ( display_options : DisplayOptions , task : & ResolvedTask ) -> Option < String > {
30+ let display_command = if display_options. hide_command {
31+ if let Ok ( outer_command) = std:: env:: var ( "VITE_OUTER_COMMAND" ) {
32+ outer_command
33+ } else {
34+ return None ;
35+ }
36+ } else {
37+ task. resolved_command . fingerprint . command . to_string ( )
38+ } ;
39+
40+ let cwd = task. resolved_command . fingerprint . cwd . as_str ( ) ;
41+ Some ( format ! (
42+ "{}$ {}" ,
43+ if cwd. is_empty( ) { format_args!( "" ) } else { format_args!( "~/{}" , cwd) } ,
44+ display_command
45+ ) )
46+ }
47+
2548/// Displayed before the task is executed
2649impl Display for PreExecutionStatus {
2750 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
28- let display_command = format ! ( "$ {}" , & self . task. resolved_command. fingerprint. command) ;
29- let outer_command =
30- format ! ( "$ {}" , std:: env:: var( "VITE_OUTER_COMMAND" ) . unwrap_or_default( ) ) ;
31- let display_command: Option < Styled < & String > > = if self . display_options . hide_command {
32- if outer_command != "$ " {
33- Some ( outer_command. style ( Style :: new ( ) . cyan ( ) ) )
34- } else {
35- None
36- }
37- } else {
38- Some ( display_command. style ( Style :: new ( ) . cyan ( ) ) )
39- } ;
51+ let display_command = self . display_command . as_ref ( ) . map ( |cmd| cmd. style ( COMMAND_STYLE ) ) ;
4052
4153 // Print cache status with improved, shorter messages
4254 match & self . cache_status {
4355 CacheStatus :: CacheMiss ( CacheMiss :: NotFound ) => {
4456 // No message for "Cache not found" as requested
45- tracing:: debug!( "{}" , "Cache not found" . style( Style :: new ( ) . yellow ( ) ) ) ;
57+ tracing:: debug!( "{}" , "Cache not found" . style( CACHE_MISS_STYLE ) ) ;
4658 if let Some ( display_command) = & display_command {
4759 writeln ! ( f, "{}" , display_command) ?;
4860 }
@@ -86,7 +98,7 @@ impl Display for PreExecutionStatus {
8698 format_args!( "✗ cache miss: {}, executing" , reason) ,
8799 if display_command. is_some( ) { ")" } else { "" } ,
88100 )
89- . style( Style :: new ( ) . yellow ( ) . dimmed( ) )
101+ . style( CACHE_MISS_STYLE . dimmed( ) )
90102 ) ?;
91103 }
92104 CacheStatus :: CacheHit => {
@@ -166,7 +178,7 @@ impl Display for ExecutionSummary {
166178 "Statistics:" . style( Style :: new( ) . bold( ) ) ,
167179 format!( "{} tasks" , total) . style( Style :: new( ) . bright_white( ) ) ,
168180 format!( "• {} cache hits" , cache_hits) . style( Style :: new( ) . green( ) ) ,
169- format!( "• {} cache misses" , cache_misses) . style( Style :: new ( ) . yellow ( ) ) ,
181+ format!( "• {} cache misses" , cache_misses) . style( CACHE_MISS_STYLE ) ,
170182 if failed > 0 {
171183 format!( "• {} failed" , failed) . style( Style :: new( ) . red( ) ) . to_string( )
172184 } else if skipped > 0 {
@@ -186,7 +198,7 @@ impl Display for ExecutionSummary {
186198 cache_rate. to_string( ) . style( if cache_rate >= 75 {
187199 Style :: new( ) . green( ) . bold( )
188200 } else if cache_rate >= 50 {
189- Style :: new ( ) . yellow ( )
201+ CACHE_MISS_STYLE
190202 } else {
191203 Style :: new( ) . red( )
192204 } )
@@ -212,6 +224,10 @@ impl Display for ExecutionSummary {
212224 task_name. style( Style :: new( ) . bright_white( ) . bold( ) )
213225 ) ?;
214226
227+ if let Some ( display_command) = & status. pre_execution_status . display_command {
228+ write ! ( f, ": {}" , display_command. style( COMMAND_STYLE ) ) ?;
229+ }
230+
215231 // Execution result icon and status
216232 match & status. execution_result {
217233 Ok ( exit_status) if * exit_status == 0 => {
@@ -246,14 +262,14 @@ impl Display for ExecutionSummary {
246262 ) ?;
247263 }
248264 CacheStatus :: CacheMiss ( miss) => {
249- write ! ( f, " {}" , "→ Cache miss: " . style( Style :: new ( ) . yellow ( ) ) ) ?;
265+ write ! ( f, " {}" , "→ Cache miss: " . style( CACHE_MISS_STYLE ) ) ?;
250266
251267 match miss {
252268 CacheMiss :: NotFound => {
253269 writeln ! (
254270 f,
255271 "{}" ,
256- "no previous cache entry found" . style( Style :: new ( ) . yellow ( ) )
272+ "no previous cache entry found" . style( CACHE_MISS_STYLE )
257273 ) ?;
258274 }
259275 CacheMiss :: FingerprintMismatch ( mismatch) => {
@@ -336,13 +352,13 @@ impl Display for ExecutionSummary {
336352 writeln ! (
337353 f,
338354 "{}" ,
339- "configuration changed" . style( Style :: new ( ) . yellow ( ) )
355+ "configuration changed" . style( CACHE_MISS_STYLE )
340356 ) ?;
341357 } else {
342358 writeln ! (
343359 f,
344360 "{}" ,
345- changes. join( "; " ) . style( Style :: new ( ) . yellow ( ) )
361+ changes. join( "; " ) . style( CACHE_MISS_STYLE )
346362 ) ?;
347363 }
348364 }
@@ -353,7 +369,7 @@ impl Display for ExecutionSummary {
353369 f,
354370 "{}" ,
355371 format!( "content of input '{}' changed" , path)
356- . style( Style :: new ( ) . yellow ( ) )
372+ . style( CACHE_MISS_STYLE )
357373 ) ?;
358374 }
359375 }
0 commit comments