Skip to content

Commit

Permalink
reworking new UI to accommodate watch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Apr 17, 2024
1 parent 79e53e7 commit 2050124
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 30 deletions.
12 changes: 8 additions & 4 deletions crates/turborepo-lib/src/run/watch.rs
Expand Up @@ -79,9 +79,13 @@ impl WatchClient {
.build(&handler, telemetry.clone())
.await?;

let (sender, handle) = run.start_experimental_ui();

run.print_run_prelude();
let (sender, handle) = if run.has_experimental_ui() {

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / JS Native Package Tests (ubuntu, self-hosted, linux, x64, metal)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / JS Native Package Tests (ubuntu, self-hosted, linux, x64, metal)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust check

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, self-hosted, linux, x64, metal)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (macos, macos-latest)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / JS Native Package Tests (macos, macos-latest)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (windows, windows-latest)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (ubuntu-latest)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / JS Native Package Tests (macos, macos-latest)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on ubuntu

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (macos-latest)

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on macos

unused variable: `handle`

Check warning on line 82 in crates/turborepo-lib/src/run/watch.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (windows-latest)

unused variable: `handle`
let (sender, handle) = run.start_experimental_ui();
(Some(sender), Some(handle))
} else {
run.print_run_prelude();
(None, None)
};

let has_persistent_tasks = run.has_persistent_tasks();
let mut filtered_pkgs = run.filtered_pkgs;
Expand Down Expand Up @@ -110,7 +114,7 @@ impl WatchClient {
&handler,
&mut main_run_handle,
has_persistent_tasks,
Some(sender.clone()),
sender.clone(),
)
.await?;
}
Expand Down
9 changes: 7 additions & 2 deletions crates/turborepo-ui/src/tui/app.rs
Expand Up @@ -123,12 +123,12 @@ fn run_app_inner<B: Backend>(
// Render initial state to paint the screen
terminal.draw(|f| view(&mut app, f))?;
let mut last_render = Instant::now();

while let Some(event) = poll(app.interact, &receiver, last_render + FRAMERATE) {
if let Some(message) = update(terminal, &mut app, event)? {
persist_bytes(terminal, &message)?;
}
if app.done {
println!("done");
break;
}
if FRAMERATE <= last_render.elapsed() {
Expand All @@ -137,6 +137,8 @@ fn run_app_inner<B: Backend>(
}
}

eprintln!("DONE 2");

let started_tasks = app.table.tasks_started().collect();
app.pane.render_remaining(started_tasks, terminal)?;

Expand All @@ -150,7 +152,10 @@ fn poll(interact: bool, receiver: &AppReceiver, deadline: Instant) -> Option<Eve
Ok(Some(event)) => Some(event),
Ok(None) => receiver.recv(deadline).ok(),
// Unable to read from stdin, shut down and attempt to clean up
Err(_) => Some(Event::Stop),
Err(_) => {
eprintln!("unable to read from stdin");
Some(Event::Stop)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/turborepo-ui/src/tui/handle.rs
Expand Up @@ -77,7 +77,10 @@ impl AppReceiver {
match self.primary.recv_deadline(deadline) {
Ok(event) => Ok(event),
Err(mpsc::RecvTimeoutError::Timeout) => Ok(Event::Tick),
Err(mpsc::RecvTimeoutError::Disconnected) => Err(mpsc::RecvError),
Err(mpsc::RecvTimeoutError::Disconnected) => {
println!("disconnected!!");
Err(mpsc::RecvError)
}
}
}
}
Expand Down
68 changes: 46 additions & 22 deletions crates/turborepo-ui/src/tui/table.rs
Expand Up @@ -77,30 +77,54 @@ impl TaskTable {
/// Mark the given planned task as started
/// Errors if given task wasn't a planned task
pub fn start_task(&mut self, task: &str) -> Result<(), Error> {
let planned_idx = self
if let Ok(planned_idx) = self
.planned
.binary_search_by(|planned_task| planned_task.name().cmp(task))
.map_err(|_| {
debug!("could not find '{task}' to start");
Error::TaskNotFound { name: task.into() }
})?;
let planned = self.planned.remove(planned_idx);
let old_row_idx = self.finished.len() + self.running.len() + planned_idx;
let new_row_idx = self.finished.len() + self.running.len();
let running = planned.start();
self.running.push(running);
{
let planned = self.planned.remove(planned_idx);
let old_row_idx = self.finished.len() + self.running.len() + planned_idx;
let new_row_idx = self.finished.len() + self.running.len();
let running = planned.start();
self.running.push(running);

if let Some(selected_idx) = self.scroll.selected() {
// If task that was just started is selected, then update selection to follow
// task
if selected_idx == old_row_idx {
self.scroll.select(Some(new_row_idx));
} else if new_row_idx <= selected_idx && selected_idx < old_row_idx {
// If the selected task is between the old and new row positions
// then increment the selection index to keep selection the same.
self.scroll.select(Some(selected_idx + 1));
if let Some(selected_idx) = self.scroll.selected() {
// If task that was just started is selected, then update selection to follow
// task
if selected_idx == old_row_idx {
self.scroll.select(Some(new_row_idx));
} else if new_row_idx <= selected_idx && selected_idx < old_row_idx {
// If the selected task is between the old and new row positions
// then increment the selection index to keep selection the same.
self.scroll.select(Some(selected_idx + 1));
}
}
} else if let Some(finished_idx) = self
.finished
.iter()
.position(|finished_task| finished_task.name() == task)
{
let finished = self.finished.remove(finished_idx);
let old_row_idx = finished_idx;
let new_row_idx = self.finished.len() + self.running.len();
let running = finished.start();
self.running.push(running);

if let Some(selected_idx) = self.scroll.selected() {
// If task that was just started is selected, then update selection to follow
// task
if selected_idx == old_row_idx {
self.scroll.select(Some(new_row_idx));
} else if new_row_idx <= selected_idx && selected_idx < old_row_idx {
// If the selected task is between the old and new row positions
// then increment the selection index to keep selection the same.
self.scroll.select(Some(selected_idx + 1));
}
}
} else {
debug!("could not find '{task}' to start");
return Err(Error::TaskNotFound { name: task.into() });
}

self.tick();
Ok(())
}
Expand Down Expand Up @@ -195,7 +219,7 @@ impl TaskTable {
duration_width,
self.start,
self.current,
task.start(),
task.start_time(),
Some(task.end()),
)),
])
Expand Down Expand Up @@ -266,9 +290,9 @@ impl<'a> StatefulWidget for &'a TaskTable {
.constraints([Constraint::Min(2), Constraint::Length(2)])
.split(area);
let table = Table::new(
self.finished_rows(status_width)
self.planned_rows(status_width)
.chain(self.running_rows(status_width))
.chain(self.planned_rows(status_width)),
.chain(self.finished_rows(status_width)),
[
Constraint::Min(name_width),
Constraint::Length(status_width),
Expand Down
10 changes: 9 additions & 1 deletion crates/turborepo-ui/src/tui/task.rs
Expand Up @@ -65,9 +65,17 @@ impl Task<Running> {
}

impl Task<Finished> {
pub fn start(&self) -> Instant {
pub fn start_time(&self) -> Instant {
self.state.start
}
pub fn start(self) -> Task<Running> {
Task {
name: self.name,
state: Running {
start: Instant::now(),
},
}
}

pub fn end(&self) -> Instant {
self.state.end
Expand Down

0 comments on commit 2050124

Please sign in to comment.