Skip to content

Commit a0624ea

Browse files
committed
feat: add taskbar progress reporting
1 parent 4a8fd9b commit a0624ea

File tree

5 files changed

+225
-17
lines changed

5 files changed

+225
-17
lines changed

src/cargo/core/compiler/job_queue/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ impl<'gctx> DrainState<'gctx> {
854854
}
855855

856856
fn handle_error(
857-
&self,
857+
&mut self,
858858
shell: &mut Shell,
859859
err_state: &mut ErrorsDuringDrain,
860860
new_err: impl Into<ErrorToHandle>,
@@ -863,6 +863,7 @@ impl<'gctx> DrainState<'gctx> {
863863
if new_err.print_always || err_state.count == 0 {
864864
crate::display_error(&new_err.error, shell);
865865
if err_state.count == 0 && !self.active.is_empty() {
866+
self.progress.indicate_error();
866867
let _ = shell.warn("build failed, waiting for other jobs to finish...");
867868
}
868869
err_state.count += 1;

src/cargo/core/shell.rs

+24
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl Shell {
5656
stderr_tty: std::io::stderr().is_terminal(),
5757
stdout_unicode: supports_unicode(&std::io::stdout()),
5858
stderr_unicode: supports_unicode(&std::io::stderr()),
59+
stderr_term_integration: supports_term_integration(&std::io::stderr()),
5960
},
6061
verbosity: Verbosity::Verbose,
6162
needs_clear: false,
@@ -122,6 +123,18 @@ impl Shell {
122123
}
123124
}
124125

126+
pub fn is_err_term_integration_available(&self) -> bool {
127+
if let ShellOut::Stream {
128+
stderr_term_integration,
129+
..
130+
} = self.output
131+
{
132+
stderr_term_integration
133+
} else {
134+
false
135+
}
136+
}
137+
125138
/// Gets a reference to the underlying stdout writer.
126139
pub fn out(&mut self) -> &mut dyn Write {
127140
if self.needs_clear {
@@ -426,6 +439,7 @@ enum ShellOut {
426439
hyperlinks: bool,
427440
stdout_unicode: bool,
428441
stderr_unicode: bool,
442+
stderr_term_integration: bool,
429443
},
430444
}
431445

@@ -575,6 +589,16 @@ fn supports_hyperlinks() -> bool {
575589
supports_hyperlinks::supports_hyperlinks()
576590
}
577591

592+
/// Determines whether the terminal supports ANSI OSC 9;4.
593+
#[allow(clippy::disallowed_methods)] // Read environment variables to detect terminal
594+
fn supports_term_integration(stream: &dyn IsTerminal) -> bool {
595+
let windows_terminal = std::env::var("WT_SESSION").is_ok();
596+
let conemu = std::env::var("ConEmuANSI").ok() == Some("ON".into());
597+
let wezterm = std::env::var("TERM_PROGRAM").ok() == Some("WezTerm".into());
598+
599+
(windows_terminal || conemu || wezterm) && stream.is_terminal()
600+
}
601+
578602
pub struct Hyperlink<D: fmt::Display> {
579603
url: Option<D>,
580604
}

src/cargo/util/context/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,8 @@ pub struct TermConfig {
28322832
pub struct ProgressConfig {
28332833
pub when: ProgressWhen,
28342834
pub width: Option<usize>,
2835+
/// Communicate progress status with a terminal
2836+
pub term_integration: Option<bool>,
28352837
}
28362838

28372839
#[derive(Debug, Default, Deserialize)]
@@ -2864,10 +2866,12 @@ where
28642866
"auto" => Ok(Some(ProgressConfig {
28652867
when: ProgressWhen::Auto,
28662868
width: None,
2869+
term_integration: None,
28672870
})),
28682871
"never" => Ok(Some(ProgressConfig {
28692872
when: ProgressWhen::Never,
28702873
width: None,
2874+
term_integration: None,
28712875
})),
28722876
"always" => Err(E::custom("\"always\" progress requires a `width` key")),
28732877
_ => Err(E::unknown_variant(s, &["auto", "never"])),
@@ -2889,6 +2893,7 @@ where
28892893
if let ProgressConfig {
28902894
when: ProgressWhen::Always,
28912895
width: None,
2896+
..
28922897
} = pc
28932898
{
28942899
return Err(serde::de::Error::custom(

0 commit comments

Comments
 (0)