mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
feat: add some random ads at the end
This commit is contained in:
parent
e420f7c386
commit
b58e560971
7 changed files with 69 additions and 8 deletions
42
Cargo.lock
generated
42
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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]
|
||||
|
|
2
src/alejandra_cli/src/ads/donation.txt
Normal file
2
src/alejandra_cli/src/ads/donation.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
If Alejandra is useful to you, please sponsor its author.
|
||||
Thank you! https://github.com/sponsors/kamadorueda
|
11
src/alejandra_cli/src/ads/mod.rs
Normal file
11
src/alejandra_cli/src/ads/mod.rs
Normal file
|
@ -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]
|
||||
}
|
2
src/alejandra_cli/src/ads/star.txt
Normal file
2
src/alejandra_cli/src/ads/star.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
If Alejandra is useful to you, please add your star to the repository.
|
||||
Thank you! https://github.com/sponsors/kamadorueda
|
|
@ -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() {}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
pub mod ads;
|
||||
pub mod cli;
|
||||
pub mod find;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue