Skip to content

Commit

Permalink
Cleaning up UI output
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed May 10, 2024
1 parent e185ce7 commit fe028d0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/run/mod.rs
Expand Up @@ -292,6 +292,7 @@ impl Run {
&self.engine,
&self.env_at_execution_start,
self.opts.scope_opts.pkg_inference_root.as_deref(),
self.experimental_ui,
)
.await?;

Expand Down
14 changes: 9 additions & 5 deletions crates/turborepo-lib/src/run/summary/mod.rs
Expand Up @@ -278,6 +278,7 @@ impl RunTracker {
engine: &'a Engine,
hash_tracker: TaskHashTracker,
env_at_execution_start: &'a EnvironmentVariableMap,
has_experimental_ui: bool,
) -> Result<(), Error> {
let end_time = Local::now();

Expand Down Expand Up @@ -305,7 +306,7 @@ impl RunTracker {
.await?;

run_summary
.finish(end_time, exit_code, pkg_dep_graph, ui)
.finish(end_time, exit_code, pkg_dep_graph, ui, has_experimental_ui)
.await
}

Expand Down Expand Up @@ -380,6 +381,7 @@ impl<'a> RunSummary<'a> {
exit_code: i32,
pkg_dep_graph: &PackageGraph,
ui: UI,
has_experimental_ui: bool,
) -> Result<(), Error> {
if matches!(self.run_type, RunType::DryJson | RunType::DryText) {
return self.close_dry_run(pkg_dep_graph, ui);
Expand All @@ -391,10 +393,12 @@ impl<'a> RunSummary<'a> {
}
}

if let Some(execution) = &self.execution {
let path = self.get_path();
let failed_tasks = self.get_failed_tasks();
execution.print(ui, path, failed_tasks);
if !has_experimental_ui {
if let Some(execution) = &self.execution {
let path = self.get_path();
let failed_tasks = self.get_failed_tasks();
execution.print(ui, path, failed_tasks);
}
}

if let Some(spaces_client_handle) = self.spaces_client_handle.take() {
Expand Down
34 changes: 25 additions & 9 deletions crates/turborepo-lib/src/run/watch.rs
Expand Up @@ -50,8 +50,8 @@ pub struct WatchClient {
base: CommandBase,
telemetry: CommandEventBuilder,
handler: SignalHandler,
sender: Option<AppSender>,
handle: Option<JoinHandle<Result<(), tui::Error>>>,
ui_sender: Option<AppSender>,
ui_handle: Option<JoinHandle<Result<(), tui::Error>>>,
}

#[derive(Debug, Error, Diagnostic)]
Expand Down Expand Up @@ -130,8 +130,8 @@ impl WatchClient {
handler,
telemetry,
persistent_tasks_handle: None,
sender,
handle,
ui_sender: sender,
ui_handle: handle,
})
}

Expand All @@ -141,7 +141,9 @@ impl WatchClient {

let mut events = client.package_changes().await?;

self.run.print_run_prelude();
if !self.run.has_experimental_ui() {
self.run.print_run_prelude();
}

let signal_subscriber = self.handler.subscribe().ok_or(Error::NoSignalHandler)?;

Expand Down Expand Up @@ -264,7 +266,7 @@ impl WatchClient {
.build(&signal_handler, telemetry)
.await?;

Ok(run.run(self.sender.clone()).await?)
Ok(run.run(self.ui_sender.clone()).await?)
}
ChangedPackages::All => {
let mut args = self.base.args().clone();
Expand Down Expand Up @@ -296,14 +298,28 @@ impl WatchClient {
.build(&self.handler, self.telemetry.clone())
.await?;

if self.run.has_experimental_ui() {
if let Some(handle) = &self.ui_handle {
handle.abort();
}

let (sender, handle) = self
.run
.has_experimental_ui()
.then(|| self.run.start_experimental_ui())
.unzip();
self.ui_sender = sender;
self.ui_handle = handle;
}

if self.run.has_persistent_tasks() {
// Abort old run
if let Some(run) = self.persistent_tasks_handle.take() {
run.abort();
}

let mut persistent_run = self.run.create_run_for_persistent_tasks();
let ui_sender = self.sender.clone();
let ui_sender = self.ui_sender.clone();
// If we have persistent tasks, we run them on a separate thread
// since persistent tasks don't finish
self.persistent_tasks_handle =
Expand All @@ -313,9 +329,9 @@ impl WatchClient {

// But we still run the regular tasks blocking
let mut non_persistent_run = self.run.create_run_without_persistent_tasks();
Ok(non_persistent_run.run(self.sender.clone()).await?)
Ok(non_persistent_run.run(self.ui_sender.clone()).await?)
} else {
Ok(self.run.run(self.sender.clone()).await?)
Ok(self.run.run(self.ui_sender.clone()).await?)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Expand Up @@ -346,6 +346,7 @@ impl<'a> Visitor<'a> {
engine: &Engine,
env_at_execution_start: &EnvironmentVariableMap,
pkg_inference_root: Option<&AnchoredSystemPath>,
has_experimental_ui: bool,
) -> Result<(), Error> {
let Self {
package_graph,
Expand Down Expand Up @@ -374,6 +375,7 @@ impl<'a> Visitor<'a> {
engine,
task_hasher.task_hash_tracker(),
env_at_execution_start,
has_experimental_ui,
)
.await?)
}
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-ui/src/tui/app.rs
Expand Up @@ -99,6 +99,7 @@ impl<I: std::io::Write> App<I> {
pub fn run_app(tasks: Vec<String>, receiver: AppReceiver) -> Result<(), Error> {
let mut terminal = startup()?;
let size = terminal.size()?;
terminal.clear()?;

// Figure out pane width?
let task_width_hint = TaskTable::width_hint(tasks.iter().map(|s| s.as_str()));
Expand Down

0 comments on commit fe028d0

Please sign in to comment.