这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(tui): configurable scrollback length #10247

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

Merged
merged 6 commits into from
Apr 7, 2025
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
21 changes: 19 additions & 2 deletions crates/turborepo-lib/src/config/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const TURBO_MAPPING: &[(&str, &str)] = [
("turbo_run_summary", "run_summary"),
("turbo_allow_no_turbo_json", "allow_no_turbo_json"),
("turbo_cache", "cache"),
("turbo_tui_scrollback_length", "tui_scrollback_length"),
]
.as_slice();

Expand Down Expand Up @@ -148,7 +149,15 @@ impl ResolvedConfigurationOptions for EnvVars {
.transpose()
.map_err(Error::InvalidUploadTimeout)?;

// Process experimentalUI
let tui_scrollback_length = self
.output_map
.get("tui_scrollback_length")
.filter(|s| !s.is_empty())
.map(|s| s.parse())
.transpose()
.map_err(Error::InvalidTuiScrollbackLength)?;

// Process ui
let ui =
self.truthy_value("ui")
.flatten()
Expand Down Expand Up @@ -218,6 +227,8 @@ impl ResolvedConfigurationOptions for EnvVars {
// Processed numbers
timeout,
upload_timeout,
tui_scrollback_length,

env_mode,
cache_dir,
root_turbo_json_path,
Expand Down Expand Up @@ -268,7 +279,7 @@ mod test {
use super::*;
use crate::{
cli::LogOrder,
config::{DEFAULT_API_URL, DEFAULT_LOGIN_URL},
config::{DEFAULT_API_URL, DEFAULT_LOGIN_URL, DEFAULT_TUI_SCROLLBACK_LENGTH},
};

#[test]
Expand Down Expand Up @@ -314,6 +325,7 @@ mod test {
env.insert("turbo_run_summary".into(), "true".into());
env.insert("turbo_allow_no_turbo_json".into(), "true".into());
env.insert("turbo_remote_cache_upload_timeout".into(), "200".into());
env.insert("turbo_tui_scrollback_length".into(), "2048".into());

let config = EnvVars::new(&env)
.unwrap()
Expand Down Expand Up @@ -365,6 +377,7 @@ mod test {
env.insert("turbo_remote_cache_read_only".into(), "".into());
env.insert("turbo_run_summary".into(), "".into());
env.insert("turbo_allow_no_turbo_json".into(), "".into());
env.insert("turbo_tui_scrollback_length".into(), "".into());

let config = EnvVars::new(&env)
.unwrap()
Expand All @@ -388,5 +401,9 @@ mod test {
assert!(!config.remote_cache_read_only());
assert!(!config.run_summary());
assert!(!config.allow_no_turbo_json());
assert_eq!(
config.tui_scrollback_length(),
DEFAULT_TUI_SCROLLBACK_LENGTH
);
}
}
12 changes: 12 additions & 0 deletions crates/turborepo-lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,18 @@ pub enum Error {
#[source_code]
text: NamedSource<String>,
},
#[error(
"TURBO_TUI_SCROLLBACK_LENGTH: Invalid value. Use a number for how many lines to keep in \
scrollback."
)]
InvalidTuiScrollbackLength(#[source] std::num::ParseIntError),
}

const DEFAULT_API_URL: &str = "https://vercel.com/api";
const DEFAULT_LOGIN_URL: &str = "https://vercel.com";
const DEFAULT_TIMEOUT: u64 = 30;
const DEFAULT_UPLOAD_TIMEOUT: u64 = 60;
const DEFAULT_TUI_SCROLLBACK_LENGTH: u64 = 2048;

// We intentionally don't derive Serialize so that different parts
// of the code that want to display the config can tune how they
Expand Down Expand Up @@ -290,6 +296,7 @@ pub struct ConfigurationOptions {
pub(crate) remote_cache_read_only: Option<bool>,
pub(crate) run_summary: Option<bool>,
pub(crate) allow_no_turbo_json: Option<bool>,
pub(crate) tui_scrollback_length: Option<u64>,
}

#[derive(Default)]
Expand Down Expand Up @@ -346,6 +353,11 @@ impl ConfigurationOptions {
self.upload_timeout.unwrap_or(DEFAULT_UPLOAD_TIMEOUT)
}

pub fn tui_scrollback_length(&self) -> u64 {
self.tui_scrollback_length
.unwrap_or(DEFAULT_TUI_SCROLLBACK_LENGTH)
}

pub fn ui(&self) -> UIMode {
// If we aren't hooked up to a TTY, then do not use TUI
if !atty::is(atty::Stream::Stdout) {
Expand Down
23 changes: 22 additions & 1 deletion crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct Opts {
pub run_opts: RunOpts,
pub runcache_opts: RunCacheOpts,
pub scope_opts: ScopeOpts,
pub tui_opts: TuiOpts,
}

impl Opts {
Expand Down Expand Up @@ -177,6 +178,7 @@ impl Opts {
let runcache_opts = RunCacheOpts::from(inputs);
let api_client_opts = APIClientOpts::from(inputs);
let repo_opts = RepoOpts::from(inputs);
let tui_opts = TuiOpts::from(inputs);

Ok(Self {
repo_opts,
Expand All @@ -185,6 +187,7 @@ impl Opts {
scope_opts,
runcache_opts,
api_client_opts,
tui_opts,
})
}
}
Expand Down Expand Up @@ -539,6 +542,19 @@ impl ScopeOpts {
}
}

#[derive(Clone, Debug, Serialize)]
pub struct TuiOpts {
pub(crate) scrollback_length: u64,
}

impl<'a> From<OptsInputs<'a>> for TuiOpts {
fn from(inputs: OptsInputs) -> Self {
TuiOpts {
scrollback_length: inputs.config.tui_scrollback_length(),
}
}
}

#[cfg(test)]
mod test {
use clap::Parser;
Expand All @@ -555,7 +571,7 @@ mod test {
cli::{Command, ContinueMode, DryRunMode, RunArgs},
commands::CommandBase,
config::ConfigurationOptions,
opts::{Opts, RunCacheOpts, ScopeOpts},
opts::{Opts, RunCacheOpts, ScopeOpts, TuiOpts},
run::task_id::TaskId,
turbo_json::{UIMode, CONFIG_FILE},
Args,
Expand Down Expand Up @@ -702,6 +718,10 @@ mod test {
.root_turbo_json_path(&AbsoluteSystemPathBuf::default())
.unwrap_or_else(|_| AbsoluteSystemPathBuf::default().join_component(CONFIG_FILE));

let tui_opts = TuiOpts {
scrollback_length: 2048,
};

let opts = Opts {
repo_opts: RepoOpts {
root_turbo_json_path,
Expand All @@ -722,6 +742,7 @@ mod test {
run_opts,
cache_opts,
runcache_opts,
tui_opts,
};
let synthesized = opts.synthesize_command();
assert_eq!(synthesized, expected);
Expand Down
10 changes: 9 additions & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,17 @@ impl Run {

let (sender, receiver) = TuiSender::new();
let color_config = self.color_config;
let scrollback_len = self.opts.tui_opts.scrollback_length;
let repo_root = self.repo_root.clone();
let handle = tokio::task::spawn(async move {
Ok(tui::run_app(task_names, receiver, color_config, &repo_root).await?)
Ok(tui::run_app(
task_names,
receiver,
color_config,
&repo_root,
scrollback_len,
)
.await?)
});

Ok(Some((sender, handle)))
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 @@ -28,7 +28,7 @@ crossterm = { version = "0.27.0", features = ["event-stream"] }
dialoguer = { workspace = true }
futures = { workspace = true }
indicatif = { workspace = true }
itertools.workspace = true
itertools = { workspace = true }
lazy_static = { workspace = true }
nix = { version = "0.26.2", features = ["signal"] }
ratatui = { workspace = true }
Expand Down
Loading
Loading