diff --git a/Cargo.lock b/Cargo.lock index c584d36..c548b8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,7 @@ dependencies = [ "clap", "futures", "num_cpus", + "rand", "walkdir", ] @@ -60,6 +61,12 @@ version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "clap" version = "3.2.16" @@ -183,6 +190,17 @@ dependencies = [ "slab", ] +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hashbrown" version = "0.9.1" @@ -344,6 +362,24 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + [[package]] name = "rnix" version = "0.10.2" @@ -468,6 +504,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "winapi" version = "0.3.9" diff --git a/src/alejandra_cli/Cargo.toml b/src/alejandra_cli/Cargo.toml index 8c32f9b..4a938b8 100644 --- a/src/alejandra_cli/Cargo.toml +++ b/src/alejandra_cli/Cargo.toml @@ -15,6 +15,7 @@ futures = { version = "*", default_features = false, features = [ "thread-pool" ] } num_cpus = { version = "*", default_features = false, features = [] } +rand = { version = "*", default-features = false, features = ["getrandom"] } walkdir = { version = "*", default_features = false, features = [] } [package] diff --git a/src/alejandra_cli/src/ads/donation.txt b/src/alejandra_cli/src/ads/donation.txt new file mode 100644 index 0000000..9c9bb69 --- /dev/null +++ b/src/alejandra_cli/src/ads/donation.txt @@ -0,0 +1,2 @@ +If Alejandra is useful to you, please sponsor its author. +Thank you! https://github.com/sponsors/kamadorueda diff --git a/src/alejandra_cli/src/ads/mod.rs b/src/alejandra_cli/src/ads/mod.rs new file mode 100644 index 0000000..c7857b1 --- /dev/null +++ b/src/alejandra_cli/src/ads/mod.rs @@ -0,0 +1,11 @@ +use rand::distributions::Distribution; +use rand::distributions::Uniform; +use rand::rngs::OsRng; + +pub(crate) fn random_ad() -> &'static str { + let ads = [include_str!("star.txt"), include_str!("donation.txt")]; + + let ads_index = Uniform::from(0..ads.len()).sample(&mut OsRng); + + ads[ads_index] +} diff --git a/src/alejandra_cli/src/ads/star.txt b/src/alejandra_cli/src/ads/star.txt new file mode 100644 index 0000000..a8157f2 --- /dev/null +++ b/src/alejandra_cli/src/ads/star.txt @@ -0,0 +1,2 @@ +If Alejandra is useful to you, please add your star to the repository. +Thank you! https://github.com/sponsors/kamadorueda diff --git a/src/alejandra_cli/src/cli.rs b/src/alejandra_cli/src/cli.rs index 7ac80a6..7bbd68c 100644 --- a/src/alejandra_cli/src/cli.rs +++ b/src/alejandra_cli/src/cli.rs @@ -5,6 +5,8 @@ use futures::future::RemoteHandle; use futures::stream::FuturesUnordered; use futures::task::SpawnExt; +use crate::ads::random_ad; + #[derive(Clone)] pub(crate) struct FormattedPath { pub path: String, @@ -81,8 +83,8 @@ pub(crate) fn simple( if !quiet { eprintln!( - "{} {paths_len} file{} using {threads} thread{}", - if in_place { "Formatting" } else { "Checking formatting in" }, + "{} {paths_len} file{} using {threads} thread{}.", + if in_place { "Formatting" } else { "Checking style in" }, if paths_len == 1 { "" } else { "s" }, if threads == 1 { "" } else { "s" }, ); @@ -182,7 +184,7 @@ pub fn main() -> std::io::Result<()> { if !args.quiet { eprintln!(); eprintln!( - "{}! {changed} file{} {}", + "{}! {changed} file{} {}.", if in_place { "Success" } else { "Alert" }, if changed == 1 { "" } else { "s" }, if changed == 1 { @@ -195,7 +197,8 @@ pub fn main() -> std::io::Result<()> { ); } if in_place { - ads(); + println!(); + print!("{}", random_ad()); } std::process::exit(if in_place { 0 } else { 2 }); @@ -203,11 +206,10 @@ pub fn main() -> std::io::Result<()> { if !args.quiet { eprintln!(); - eprintln!("Congratulations! Your code complies the Alejandra style"); - ads(); + eprintln!("Congratulations! Your code complies the Alejandra style."); + println!(); + print!("{}", random_ad()); } std::process::exit(0); } - -fn ads() {} diff --git a/src/alejandra_cli/src/lib.rs b/src/alejandra_cli/src/lib.rs index 665c2a0..2763e45 100644 --- a/src/alejandra_cli/src/lib.rs +++ b/src/alejandra_cli/src/lib.rs @@ -1,2 +1,3 @@ +pub mod ads; pub mod cli; pub mod find;