Skip to content

Commit

Permalink
fix(tui): respect --no-color (#9369)
Browse files Browse the repository at this point in the history
### Description

Look ma, no color!

### Testing Instructions

<img width="1160" alt="Screenshot 2024-11-01 at 1 25 52 PM"
src="https://github.com/user-attachments/assets/128f98aa-6bae-4aad-8c3e-f6dfac5569c6">
  • Loading branch information
chris-olszewski authored Nov 1, 2024
1 parent 5f7e80a commit 73637f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 4 additions & 2 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ impl Run {
}

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

Ok(Some((sender, handle)))
}
Expand Down
22 changes: 16 additions & 6 deletions crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ use super::{
search::SearchResults,
AppReceiver, Debouncer, Error, Event, InputOptions, SizeInfo, TaskTable, TerminalPane,
};
use crate::tui::{
task::{Task, TasksByStatus},
term_output::TerminalOutput,
use crate::{
tui::{
task::{Task, TasksByStatus},
term_output::TerminalOutput,
},
ColorConfig,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -559,8 +562,12 @@ impl<W: Write> App<W> {

/// Handle the rendering of the `App` widget based on events received by
/// `receiver`
pub async fn run_app(tasks: Vec<String>, receiver: AppReceiver) -> Result<(), Error> {
let mut terminal = startup()?;
pub async fn run_app(
tasks: Vec<String>,
receiver: AppReceiver,
color_config: ColorConfig,
) -> Result<(), Error> {
let mut terminal = startup(color_config)?;
let size = terminal.size()?;

let mut app: App<Box<dyn io::Write + Send>> = App::new(size.height, size.width, tasks);
Expand Down Expand Up @@ -673,7 +680,10 @@ pub fn terminal_big_enough() -> Result<bool, Error> {

/// Configures terminal for rendering App
#[tracing::instrument]
fn startup() -> io::Result<Terminal<CrosstermBackend<Stdout>>> {
fn startup(color_config: ColorConfig) -> io::Result<Terminal<CrosstermBackend<Stdout>>> {
if color_config.should_strip_ansi {
crossterm::style::force_color_output(false);
}
crossterm::terminal::enable_raw_mode()?;
let mut stdout = io::stdout();
// Ensure all pending writes are flushed before we switch to alternative screen
Expand Down

0 comments on commit 73637f8

Please sign in to comment.