Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(turborepo): avoid starting ui on too small terminals #8457

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i3
.build(&handler, telemetry)
.await?;

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

let result = run.run(sender.clone()).await;

Expand Down
3 changes: 3 additions & 0 deletions crates/turborepo-lib/src/run/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use miette::Diagnostic;
use thiserror::Error;
use turborepo_repository::package_graph;
use turborepo_ui::tui;

use super::graph_visualizer;
use crate::{
Expand Down Expand Up @@ -51,4 +52,6 @@ pub enum Error {
SignalHandler(std::io::Error),
#[error(transparent)]
Daemon(#[from] daemon::DaemonError),
#[error(transparent)]
Tui(#[from] tui::Error),
}
19 changes: 14 additions & 5 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,30 @@ impl Run {
self.experimental_ui
}

pub fn start_experimental_ui(&self) -> Option<(AppSender, JoinHandle<Result<(), tui::Error>>)> {
pub fn should_start_ui(&self) -> Result<bool, Error> {
Ok(self.experimental_ui
&& self.opts.run_opts.dry_run.is_none()
&& tui::terminal_big_enough()?)
}

#[allow(clippy::type_complexity)]
pub fn start_experimental_ui(
&self,
) -> Result<Option<(AppSender, JoinHandle<Result<(), tui::Error>>)>, Error> {
// Print prelude here as this needs to happen before the UI is started
if self.should_print_prelude {
self.print_run_prelude();
}
// Don't start UI if doing a dry run
if !self.experimental_ui || self.opts.run_opts.dry_run.is_some() {
return None;

if !self.should_start_ui()? {
return Ok(None);
}

let task_names = self.engine.tasks_with_command(&self.pkg_dep_graph);
let (sender, receiver) = AppSender::new();
let handle = tokio::task::spawn_blocking(move || tui::run_app(task_names, receiver));

Some((sender, handle))
Ok(Some((sender, handle)))
}

pub async fn run(&mut self, experimental_ui_sender: Option<AppSender>) -> Result<i32, Error> {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl WatchClient {

let watched_packages = run.get_relevant_packages();

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

let connector = DaemonConnector {
can_start_server: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workspace = true
[dependencies]
atty = { workspace = true }
console = { workspace = true }
crossterm = "0.26.1"
crossterm = "0.27.0"
dialoguer = { workspace = true }
indicatif = { workspace = true }
lazy_static = { workspace = true }
Expand Down
9 changes: 8 additions & 1 deletion crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ 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()?;

// Figure out pane width?
let task_width_hint = TaskTable::width_hint(tasks.iter().map(|s| s.as_str()));
// Want to maximize pane width
Expand Down Expand Up @@ -160,6 +159,14 @@ fn poll(input_options: InputOptions, receiver: &AppReceiver, deadline: Instant)
}
}

const MIN_HEIGHT: u16 = 10;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are completely arbitrary. Open to suggestions on what they should actually be

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are completely reasonable. If I'm accounting for borders correctly 20x10 term would probably lead to a 12x8 terminal pane. Not sure if that's usable, but anything smaller is definitely not usable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment that it's arbitrary?

const MIN_WIDTH: u16 = 20;

pub fn terminal_big_enough() -> Result<bool, Error> {
let (width, height) = crossterm::terminal::size()?;
Ok(width >= MIN_WIDTH && height >= MIN_HEIGHT)
}

/// Configures terminal for rendering App
fn startup() -> io::Result<Terminal<CrosstermBackend<Stdout>>> {
crossterm::terminal::enable_raw_mode()?;
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-ui/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod spinner;
mod table;
mod task;

pub use app::run_app;
pub use app::{run_app, terminal_big_enough};
use event::{Event, TaskResult};
pub use handle::{AppReceiver, AppSender, TuiTask};
use input::{input, InputOptions};
Expand Down
Loading