From 16d78ed36a7dde690e4ca2995ea6dd6f71e9f8bb Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Mon, 23 Feb 2026 19:10:26 +0000 Subject: [PATCH] Consolidate style rendering and centralize color function --- crates/pollard-cli/src/io.rs | 21 +----- crates/pollard-cli/src/main.rs | 5 ++ crates/pollard-cli/src/mutate/apply.rs | 18 +---- crates/pollard-cli/src/mutate/describe.rs | 30 ++++---- crates/pollard-cli/src/mutate/generate.rs | 46 ++++++------ crates/pollard-cli/src/mutate/mod.rs | 2 + crates/pollard-cli/src/mutate/view.rs | 8 +- .../src/steps/apply_mutant_to_workspace.rs | 13 +--- crates/pollard-cli/src/steps/cleanup.rs | 12 +-- .../src/steps/create_workspaces.rs | 16 +--- .../pollard-cli/src/steps/derive_mutants.rs | 13 +--- crates/pollard-cli/src/steps/find_files.rs | 13 +--- crates/pollard-cli/src/steps/mod.rs | 27 +------ .../pollard-cli/src/steps/reset_workspace.rs | 9 +-- crates/pollard-core/src/io.rs | 8 ++ .../pollard-core/src/languages/javascript.rs | 4 + .../pollard-core/src/languages/typescript.rs | 4 + crates/pollard-core/src/lib.rs | 23 +++--- crates/pollard-session/src/lib.rs | 4 +- ideal.config.toml | 75 +++++++++++++++++++ 20 files changed, 183 insertions(+), 168 deletions(-) create mode 100644 ideal.config.toml diff --git a/crates/pollard-cli/src/io.rs b/crates/pollard-cli/src/io.rs index 54206d48..22af5931 100644 --- a/crates/pollard-cli/src/io.rs +++ b/crates/pollard-cli/src/io.rs @@ -1,7 +1,7 @@ use serde::Serialize; use std::path::PathBuf; -pub use pollard_core::io::{DiffStyle, Render, Style, hashed_path}; +pub use pollard_core::io::{DiffStyle, Render, Style, color, hashed_path}; pub use pollard_session::{Report, Session}; #[derive(Debug, Clone, Serialize)] @@ -62,16 +62,10 @@ impl Action { } } -fn color(code: &str, text: &str, no_color: bool) -> String { - if no_color { - text.to_string() - } else { - format!("{code}{text}\x1b[0m") - } -} impl Render for Action { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -79,7 +73,7 @@ impl Render for Action { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => match self { + Style::Plain | Style::Pretty | Style::Markdown => match self { Action::WriteFile { path, .. } => { println!( "write {}", @@ -109,15 +103,6 @@ impl Render for Action { ); } }, - Style::Plain | Style::Markdown => match self { - Action::WriteFile { path, .. } => println!("write {}", path.display()), - Action::CreateJjWorkspace { name, path } => { - println!("jj workspace add {} at {}", name, path.display()); - } - Action::ForgetJjWorkspace { name } => println!("jj workspace forget {}", name), - Action::RemoveDir { path } => println!("rm -r {}", path.display()), - Action::RemoveFile { path } => println!("rm {}", path.display()), - }, } } } diff --git a/crates/pollard-cli/src/main.rs b/crates/pollard-cli/src/main.rs index 9aec33e8..8274f261 100644 --- a/crates/pollard-cli/src/main.rs +++ b/crates/pollard-cli/src/main.rs @@ -7,6 +7,7 @@ use clap_complete::Shell; use io::{Action, Render, Report}; use pollard_core::Hash; use pollard_session::{PartialSession, Session, SessionSkipped, discover_config, read_config}; +use std::io::IsTerminal; use std::path::PathBuf; #[derive(Debug, Parser)] @@ -145,6 +146,10 @@ fn build_session(cli: Cli) -> (Session, Command) { session.normalize_paths(); + if !std::io::stdout().is_terminal() { + session.no_color = true; + } + (session, cli.command) } diff --git a/crates/pollard-cli/src/mutate/apply.rs b/crates/pollard-cli/src/mutate/apply.rs index c2b2df9d..9571df58 100644 --- a/crates/pollard-cli/src/mutate/apply.rs +++ b/crates/pollard-cli/src/mutate/apply.rs @@ -5,13 +5,7 @@ use pollard_core::{Hash, SourceFile}; use serde::Serialize; use std::path::{Path, PathBuf}; -fn color(code: &str, text: &str, no_color: bool) -> String { - if no_color { - text.to_string() - } else { - format!("{code}{text}\x1b[0m") - } -} +use crate::io::color; pub fn run( language: &LanguageId, @@ -44,6 +38,7 @@ pub struct ApplyReport { impl Render for ApplyReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -51,7 +46,7 @@ impl Render for ApplyReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( "Will apply mutation {} to {}", color("\x1b[33m", &self.mutated_hash.to_string(), no_color), @@ -62,13 +57,6 @@ impl Render for ApplyReport { ), ); } - Style::Plain | Style::Markdown => { - println!( - "Will apply mutation {} to {}", - self.mutated_hash, - self.source_path.display(), - ); - } } } } diff --git a/crates/pollard-cli/src/mutate/describe.rs b/crates/pollard-cli/src/mutate/describe.rs index d44531f8..e86197eb 100644 --- a/crates/pollard-cli/src/mutate/describe.rs +++ b/crates/pollard-cli/src/mutate/describe.rs @@ -5,6 +5,8 @@ use pollard_core::{Hash, MutationKind, SourceFile}; use serde::Serialize; use std::path::{Path, PathBuf}; +use crate::io::color; + pub fn run(language: &LanguageId, input: &Path, hash: &Hash) -> (Vec, DescribeReport) { let file = SourceFile::read(input).expect("failed to read input file"); let desc = find_description(language, &file, hash); @@ -12,6 +14,7 @@ pub fn run(language: &LanguageId, input: &Path, hash: &Hash) -> (Vec, De let report = DescribeReport { path: desc.path, kind: desc.kind, + code_tag: desc.code_tag, start_line: desc.start_line, start_char: desc.start_char, end_line: desc.end_line, @@ -28,6 +31,7 @@ pub fn run(language: &LanguageId, input: &Path, hash: &Hash) -> (Vec, De pub struct DescribeReport { pub path: PathBuf, pub kind: MutationKind, + pub code_tag: &'static str, pub mutated_hash: Hash, pub start_line: usize, pub start_char: usize, @@ -69,21 +73,21 @@ impl Render for DescribeReport { println!("\n"); println!("**File:** `{path}`\n"); println!("**Location:** {loc}\n"); - println!("**Original:**\n```\n{}\n```\n", self.original); - println!("**Replacement:**\n```\n{}\n```", self.replacement); - } - Style::Pretty => { - print!("\x1b[1m"); - self.kind.render(style, no_color, depth + 1); - println!("\x1b[0m at \x1b[36m{path}:{loc}\x1b[0m"); - println!("\x1b[31m{}\x1b[0m", self.original); - println!("\x1b[32m{}\x1b[0m", self.replacement); + let tag = self.code_tag; + println!("**Original:**\n```{tag}\n{}\n```\n", self.original); + println!("**Replacement:**\n```{tag}\n{}\n```", self.replacement); } - Style::Plain => { + Style::Plain | Style::Pretty => { + let no_color = no_color || matches!(style, Style::Plain); + print!("{}", if no_color { "" } else { "\x1b[1m" }); self.kind.render(style, no_color, depth + 1); - println!(" at {path}:{loc}"); - println!("{}", self.original); - println!("{}", self.replacement); + println!( + "{} at {}", + if no_color { "" } else { "\x1b[0m" }, + color("\x1b[36m", &format!("{path}:{loc}"), no_color), + ); + println!("{}", color("\x1b[31m", &self.original, no_color)); + println!("{}", color("\x1b[32m", &self.replacement, no_color)); } } } diff --git a/crates/pollard-cli/src/mutate/generate.rs b/crates/pollard-cli/src/mutate/generate.rs index 5d57c4ae..94549eec 100644 --- a/crates/pollard-cli/src/mutate/generate.rs +++ b/crates/pollard-cli/src/mutate/generate.rs @@ -63,8 +63,11 @@ pub struct GenerateReport { pub replacement: String, } +use crate::io::color; + impl Render for GenerateReport { - fn render(&self, style: &Style, _no_color: bool, _depth: u8) { + fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -72,32 +75,25 @@ impl Render for GenerateReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { - println!( - "\x1b[33m{}\x1b[0m {} \x1b[1m{:?}\x1b[0m \x1b[36m{}:{}-{}:{}\x1b[0m\n\x1b[31m{}\x1b[0m\n\x1b[32m{}\x1b[0m\n", - self.mutated_hash, - self.source_path.display(), - self.kind, - self.start_line + 1, - self.start_char + 1, - self.end_line + 1, - self.end_char + 1, - self.original, - self.replacement, - ); - } - Style::Plain | Style::Markdown => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( - "{} {} {:?} {}:{}-{}:{}\n{}\n{}\n", - self.mutated_hash, + "{} {} {} {}\n{}\n{}\n", + color("\x1b[33m", &self.mutated_hash.to_string(), no_color), self.source_path.display(), - self.kind, - self.start_line + 1, - self.start_char + 1, - self.end_line + 1, - self.end_char + 1, - self.original, - self.replacement, + color("\x1b[1m", &format!("{:?}", self.kind), no_color), + color( + "\x1b[36m", + &format!( + "{}:{}-{}:{}", + self.start_line + 1, + self.start_char + 1, + self.end_line + 1, + self.end_char + 1, + ), + no_color, + ), + color("\x1b[31m", &self.original, no_color), + color("\x1b[32m", &self.replacement, no_color), ); } } diff --git a/crates/pollard-cli/src/mutate/mod.rs b/crates/pollard-cli/src/mutate/mod.rs index 09023616..31ea8c4d 100644 --- a/crates/pollard-cli/src/mutate/mod.rs +++ b/crates/pollard-cli/src/mutate/mod.rs @@ -45,6 +45,7 @@ fn find_mutated<'a>( pub struct MutationDescription { pub path: PathBuf, pub kind: MutationKind, + pub code_tag: &'static str, pub start_line: usize, pub start_char: usize, pub end_line: usize, @@ -68,6 +69,7 @@ where return Some(MutationDescription { path: file.path().to_owned(), kind: point.kind.into(), + code_tag: L::code_tag(), start_line: point.span.start.line, start_char: point.span.start.char, end_line: point.span.end.line, diff --git a/crates/pollard-cli/src/mutate/view.rs b/crates/pollard-cli/src/mutate/view.rs index 985b0817..25dff6eb 100644 --- a/crates/pollard-cli/src/mutate/view.rs +++ b/crates/pollard-cli/src/mutate/view.rs @@ -56,13 +56,7 @@ impl Report for ViewReport { } -fn color(code: &str, text: &str, no_color: bool) -> String { - if no_color { - text.to_string() - } else { - format!("{code}{text}\x1b[0m") - } -} +use crate::io::color; fn render_unified(old: &str, new: &str, path: &str, no_color: bool) { let diff = TextDiff::from_lines(old, new); diff --git a/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs b/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs index e501157a..970742fa 100644 --- a/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs +++ b/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs @@ -1,6 +1,7 @@ use crate::io::{Action, Render, Report, Style, hashed_path}; use pollard_session::Session; -use crate::steps::{color, find_workspace, read_plan, read_workspace_manifest}; +use crate::io::color; +use crate::steps::{find_workspace, read_plan, read_workspace_manifest}; use pollard_core::Hash; use serde::Serialize; use std::path::PathBuf; @@ -68,6 +69,7 @@ pub struct ApplyMutantToWorkspaceReport { impl Render for ApplyMutantToWorkspaceReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -75,7 +77,7 @@ impl Render for ApplyMutantToWorkspaceReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( "Will apply mutation {} to {}", color("\x1b[33m", &self.mutated_hash.to_string(), no_color), @@ -86,13 +88,6 @@ impl Render for ApplyMutantToWorkspaceReport { ), ); } - Style::Plain | Style::Markdown => { - println!( - "Will apply mutation {} to {}", - self.mutated_hash, - self.source_path.display(), - ); - } } } } diff --git a/crates/pollard-cli/src/steps/cleanup.rs b/crates/pollard-cli/src/steps/cleanup.rs index e02c5210..97b99b2b 100644 --- a/crates/pollard-cli/src/steps/cleanup.rs +++ b/crates/pollard-cli/src/steps/cleanup.rs @@ -1,6 +1,7 @@ use crate::io::{Action, Render, Report, Style, hashed_path}; use pollard_session::Session; -use crate::steps::{color, expand_glob}; +use crate::io::color; +use crate::steps::expand_glob; use serde::Serialize; use std::path::PathBuf; @@ -53,6 +54,7 @@ pub struct CleanupReport { impl Render for CleanupReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -60,19 +62,13 @@ impl Render for CleanupReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( "Will clean up {} workspaces from {} manifests", color("\x1b[33m", &self.workspace_count.to_string(), no_color), color("\x1b[36m", &self.manifest_count.to_string(), no_color), ); } - Style::Plain | Style::Markdown => { - println!( - "Will clean up {} workspaces from {} manifests", - self.workspace_count, self.manifest_count, - ); - } } } } diff --git a/crates/pollard-cli/src/steps/create_workspaces.rs b/crates/pollard-cli/src/steps/create_workspaces.rs index 6011571b..8b945dd3 100644 --- a/crates/pollard-cli/src/steps/create_workspaces.rs +++ b/crates/pollard-cli/src/steps/create_workspaces.rs @@ -1,6 +1,7 @@ use crate::io::{Action, Render, Report, Style, hashed_path}; use pollard_session::Session; -use crate::steps::{color, content_id}; +use crate::io::color; +use crate::steps::content_id; use pollard_core::config::Vcs; use serde::Serialize; use std::path::PathBuf; @@ -65,6 +66,7 @@ pub struct CreateWorkspacesReport { impl Render for CreateWorkspacesReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -72,7 +74,7 @@ impl Render for CreateWorkspacesReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( "Will create {} workspaces, manifest: {}", color("\x1b[33m", &self.workspaces.len().to_string(), no_color), @@ -82,16 +84,6 @@ impl Render for CreateWorkspacesReport { println!(" {}", color("\x1b[33m", ws, no_color)); } } - Style::Plain | Style::Markdown => { - println!( - "Will create {} workspaces, manifest: {}", - self.workspaces.len(), - self.manifest.display() - ); - for ws in &self.workspaces { - println!(" {ws}"); - } - } } } } diff --git a/crates/pollard-cli/src/steps/derive_mutants.rs b/crates/pollard-cli/src/steps/derive_mutants.rs index ebe9e091..0227c6ae 100644 --- a/crates/pollard-cli/src/steps/derive_mutants.rs +++ b/crates/pollard-cli/src/steps/derive_mutants.rs @@ -1,6 +1,7 @@ use crate::io::{Action, Render, Report, Style, hashed_path}; use pollard_session::Session; -use crate::steps::{color, content_id}; +use crate::io::color; +use crate::steps::content_id; use pollard_core::config::LanguageId; use pollard_core::languages::javascript::JavaScript; use pollard_core::languages::typescript::TypeScript; @@ -79,6 +80,7 @@ pub struct DeriveMutantsReport { impl Render for DeriveMutantsReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -86,20 +88,13 @@ impl Render for DeriveMutantsReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( "Derived {} mutations, will write to {}", color("\x1b[33m", &self.count.to_string(), no_color), color("\x1b[36m", &self.path.display().to_string(), no_color), ); } - Style::Plain | Style::Markdown => { - println!( - "Derived {} mutations, will write to {}", - self.count, - self.path.display() - ); - } } } } diff --git a/crates/pollard-cli/src/steps/find_files.rs b/crates/pollard-cli/src/steps/find_files.rs index b869dbd4..0142bdda 100644 --- a/crates/pollard-cli/src/steps/find_files.rs +++ b/crates/pollard-cli/src/steps/find_files.rs @@ -23,6 +23,7 @@ pub struct FindFilesReport { impl Render for FindFilesReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -30,22 +31,16 @@ impl Render for FindFilesReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( "{} files match {}", - crate::steps::color("\x1b[33m", &self.files.len().to_string(), no_color), - crate::steps::color("\x1b[36m", &self.pattern, no_color), + crate::io::color("\x1b[33m", &self.files.len().to_string(), no_color), + crate::io::color("\x1b[36m", &self.pattern, no_color), ); for f in &self.files { println!(" {}", f.display()); } } - Style::Plain | Style::Markdown => { - println!("{} files match {}", self.files.len(), self.pattern); - for f in &self.files { - println!(" {}", f.display()); - } - } } } } diff --git a/crates/pollard-cli/src/steps/mod.rs b/crates/pollard-cli/src/steps/mod.rs index e64fa8e8..e93a6183 100644 --- a/crates/pollard-cli/src/steps/mod.rs +++ b/crates/pollard-cli/src/steps/mod.rs @@ -124,13 +124,7 @@ fn run_in_workspace( }) } -fn color(code: &str, text: &str, no_color: bool) -> String { - if no_color { - text.to_string() - } else { - format!("{code}{text}\x1b[0m") - } -} +use crate::io::color; #[derive(Serialize)] pub struct CommandReport { @@ -142,6 +136,7 @@ pub struct CommandReport { impl Render for CommandReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -151,22 +146,8 @@ impl Render for CommandReport { } Style::Plain | Style::Pretty | Style::Markdown => { let (status, output) = match &self.result { - Ok(stdout) => ( - if no_color { - "OK".to_string() - } else { - color("\x1b[32m", "OK", false) - }, - stdout, - ), - Err(stderr) => ( - if no_color { - "FAIL".to_string() - } else { - color("\x1b[31m", "FAIL", false) - }, - stderr, - ), + Ok(stdout) => (color("\x1b[32m", "OK", no_color), stdout), + Err(stderr) => (color("\x1b[31m", "FAIL", no_color), stderr), }; println!( "{} {} in {} [{}]", diff --git a/crates/pollard-cli/src/steps/reset_workspace.rs b/crates/pollard-cli/src/steps/reset_workspace.rs index 8497d522..dd7e9fe9 100644 --- a/crates/pollard-cli/src/steps/reset_workspace.rs +++ b/crates/pollard-cli/src/steps/reset_workspace.rs @@ -1,6 +1,7 @@ use crate::io::{Action, Render, Report, Style, hashed_path}; use pollard_session::Session; -use crate::steps::{color, find_workspace, read_workspace_manifest}; +use crate::io::color; +use crate::steps::{find_workspace, read_workspace_manifest}; use pollard_core::config::Vcs; use serde::Serialize; use std::path::PathBuf; @@ -52,6 +53,7 @@ pub struct ResetWorkspaceReport { impl Render for ResetWorkspaceReport { fn render(&self, style: &Style, no_color: bool, _depth: u8) { + let no_color = no_color || matches!(style, Style::Plain); match style { Style::Json => { println!( @@ -59,16 +61,13 @@ impl Render for ResetWorkspaceReport { serde_json::to_string(self).expect("failed to serialize") ); } - Style::Pretty => { + Style::Plain | Style::Pretty | Style::Markdown => { println!( "Will reset {} to {}", color("\x1b[33m", &self.workspace, no_color), color("\x1b[36m", &self.rev, no_color), ); } - Style::Plain | Style::Markdown => { - println!("Will reset {} to {}", self.workspace, self.rev); - } } } } diff --git a/crates/pollard-core/src/io.rs b/crates/pollard-core/src/io.rs index d5398b8f..58dc254e 100644 --- a/crates/pollard-core/src/io.rs +++ b/crates/pollard-core/src/io.rs @@ -22,6 +22,14 @@ pub trait Render { fn render(&self, style: &Style, no_color: bool, depth: u8); } +pub fn color(code: &str, text: &str, no_color: bool) -> String { + if no_color { + text.to_string() + } else { + format!("{code}{text}\x1b[0m") + } +} + pub fn hashed_path(dir: &PathBuf, content: &str, label: &str) -> PathBuf { dir.join(format!("{}.{label}.json", Hash::of(content))) } diff --git a/crates/pollard-core/src/languages/javascript.rs b/crates/pollard-core/src/languages/javascript.rs index 55f8e4a6..caef099c 100644 --- a/crates/pollard-core/src/languages/javascript.rs +++ b/crates/pollard-core/src/languages/javascript.rs @@ -21,6 +21,10 @@ impl From for MutationKind { impl Language for JavaScript { type Kind = JsMutationKind; + fn code_tag() -> &'static str { + "javascript" + } + fn tree_sitter_language() -> tree_sitter::Language { tree_sitter_javascript::LANGUAGE.into() } diff --git a/crates/pollard-core/src/languages/typescript.rs b/crates/pollard-core/src/languages/typescript.rs index 4ae16607..9c9545b7 100644 --- a/crates/pollard-core/src/languages/typescript.rs +++ b/crates/pollard-core/src/languages/typescript.rs @@ -21,6 +21,10 @@ impl From for MutationKind { impl Language for TypeScript { type Kind = TsMutationKind; + fn code_tag() -> &'static str { + "typescript" + } + fn tree_sitter_language() -> tree_sitter::Language { tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into() } diff --git a/crates/pollard-core/src/lib.rs b/crates/pollard-core/src/lib.rs index 88ba4337..e1f4f0d2 100644 --- a/crates/pollard-core/src/lib.rs +++ b/crates/pollard-core/src/lib.rs @@ -262,6 +262,7 @@ pub enum BinaryOpKind { pub trait Language { type Kind: Into; + fn code_tag() -> &'static str; fn tree_sitter_language() -> tree_sitter::Language; fn mutation_kind_for_node<'a>( node: tree_sitter::Node<'_>, @@ -383,24 +384,20 @@ where println!("\n"); println!("**File:** `{path}`\n"); println!("**Location:** {loc}\n"); - println!("**Original:**\n```\n{original}\n```\n"); + let tag = L::code_tag(); + println!("**Original:**\n```{tag}\n{original}\n```\n"); println!( - "**Replacement:**\n```\n{}\n```", + "**Replacement:**\n```{tag}\n{}\n```", self.replacement ); } - io::Style::Pretty => { - print!("\x1b[1m"); + io::Style::Plain | io::Style::Pretty => { + let no_color = no_color || matches!(style, io::Style::Plain); + print!("{}", io::color("\x1b[1m", "", no_color)); kind.render(style, no_color, depth + 1); - println!("\x1b[0m at \x1b[36m{path}:{loc}\x1b[0m"); - println!("\x1b[31m{original}\x1b[0m"); - println!("\x1b[32m{}\x1b[0m", self.replacement); - } - io::Style::Plain => { - kind.render(style, no_color, depth + 1); - println!(" at {path}:{loc}"); - println!("{original}"); - println!("{}", self.replacement); + println!(" at {}", io::color("\x1b[36m", &format!("{path}:{loc}"), no_color)); + println!("{}", io::color("\x1b[31m", original, no_color)); + println!("{}", io::color("\x1b[32m", &self.replacement, no_color)); } } } diff --git a/crates/pollard-session/src/lib.rs b/crates/pollard-session/src/lib.rs index ef6b6ea8..34b6124f 100644 --- a/crates/pollard-session/src/lib.rs +++ b/crates/pollard-session/src/lib.rs @@ -1,7 +1,7 @@ mod config; pub use config::{discover_config, read_config, ConfigError, SEARCH_PATHS}; -pub use pollard_core::io::{DiffStyle, Render, Style, hashed_path}; +pub use pollard_core::io::{DiffStyle, Render, Style, color, hashed_path}; use pollard_core::config::{LanguageId, Ordering, Vcs}; use pollard_session_derive::Settings; @@ -66,7 +66,7 @@ pub struct Session { pub ignore_mutants: Vec, #[setting(flatten)] pub timeout: Timeout, - #[setting(default = "Style::Plain")] + #[setting(default = "Style::Pretty")] pub style: Style, #[setting(default = "DiffStyle::Unified")] pub diff: DiffStyle, diff --git a/ideal.config.toml b/ideal.config.toml new file mode 100644 index 00000000..85559518 --- /dev/null +++ b/ideal.config.toml @@ -0,0 +1,75 @@ +vcs = "jj" +parallelism = 1 +ordering = "random" + +[dirs] +working = "/tmp/pollard/work" +reports = "/tmp/pollard/report" +logs = "/tmp/pollard/logs" + +[vitest] + +# Things like pwd, env, and TreatAs config should be inherited UP. +# when running vitest.test we should default them to values in vitest, then in root +# allows project config with narrowing specificity + +treat_timeouts_as = "Missed" # or Caught + +[vitest.init] +pwd = "./examples/vitest" +commands = ["npm install"] + +[vitest.reset] +pwd = "./examples/vitest" +commands = ["npm clean"] + +[vitest.test] +pwd = "./examples/vitest" +timeout.absolute = 30 +timeout.relative = 3 +env = { NODE_ENV = "production" } +commands = [ + "npx run build", + "npx run test", +] + +[vitest.mutate.js] +#must be tree-sitter id +files.include = ["**/*.js", "**/*.jsx"] +files.exclude = ["**/*__mocks__*"] +mutants.skip = [ + { lisp = "((fn 'describe') @ignore)" } , + { kind = { "BinaryOp" = "Add" } } +] + +[vitest.mutate.rust] +#must be tree-sitter id +files.include = ["**/*.rs"] +mutants.skip = [ + { lisp = "((fn 'describe') @ignore)" } , + { kind = { "BinaryOp" = "Add" } } +] + +[cargo] +pwd = "./examples/cargo" +[cargo.test] +timeout.absolute = 30 +timeout.relative = 3 +commands = ["cargo test"] + +[cargo.mutate.js] +#must be tree-sitter id +files.include = ["**/*.js", "**/*.jsx"] +files.exclude = ["**/*__mocks__*"] +mutants.skip = [ + { lisp = "((fn 'describe') @ignore)" } , + { kind = { "BinaryOp" = "Add" } } +] + +[cargo.mutate.rust] +#must be tree-sitter id +files.include = ["**/*.rs"] +mutants.skip = [ + { lisp = "((fn 'describe') @ignore)" } , + { kind = { "BinaryOp" = "Add" } } +] -- knotmirror 0.0.1