1pub mod bun;
4pub mod cargo;
5pub mod generic;
6pub mod git;
7pub mod npm;
8pub mod pnpm;
9pub mod pytest;
10pub mod tsc;
11
12use crate::context::AppContext;
13use bun::BunCompressor;
14use cargo::CargoCompressor;
15use generic::{strip_ansi, GenericCompressor};
16use git::GitCompressor;
17use npm::NpmCompressor;
18use pnpm::PnpmCompressor;
19use pytest::PytestCompressor;
20use tsc::TscCompressor;
21
22pub trait Compressor {
25 fn matches(&self, command: &str) -> bool;
28
29 fn compress(&self, command: &str, output: &str) -> String;
31}
32
33pub fn compress(command: &str, output: String, ctx: &AppContext) -> String {
35 if !ctx.config().experimental_bash_compress {
36 return output;
37 }
38
39 let stripped = strip_ansi(&output);
40 let compressors: [&dyn Compressor; 7] = [
41 &GitCompressor,
42 &CargoCompressor,
43 &TscCompressor,
44 &NpmCompressor,
45 &BunCompressor,
46 &PnpmCompressor,
47 &PytestCompressor,
48 ];
49 for compressor in compressors {
50 if compressor.matches(command) {
51 return compressor.compress(command, &stripped);
52 }
53 }
54
55 GenericCompressor.compress(command, &stripped)
56}