mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +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",
|
"clap",
|
||||||
"futures",
|
"futures",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
|
"rand",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -60,6 +61,12 @@ version = "1.0.73"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "3.2.16"
|
version = "3.2.16"
|
||||||
|
@ -183,6 +190,17 @@ dependencies = [
|
||||||
"slab",
|
"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]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
|
@ -344,6 +362,24 @@ dependencies = [
|
||||||
"proc-macro2",
|
"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]]
|
[[package]]
|
||||||
name = "rnix"
|
name = "rnix"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
@ -468,6 +504,12 @@ dependencies = [
|
||||||
"winapi-util",
|
"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]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|
|
@ -15,6 +15,7 @@ futures = { version = "*", default_features = false, features = [
|
||||||
"thread-pool"
|
"thread-pool"
|
||||||
] }
|
] }
|
||||||
num_cpus = { version = "*", default_features = false, features = [] }
|
num_cpus = { version = "*", default_features = false, features = [] }
|
||||||
|
rand = { version = "*", default-features = false, features = ["getrandom"] }
|
||||||
walkdir = { version = "*", default_features = false, features = [] }
|
walkdir = { version = "*", default_features = false, features = [] }
|
||||||
|
|
||||||
[package]
|
[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::stream::FuturesUnordered;
|
||||||
use futures::task::SpawnExt;
|
use futures::task::SpawnExt;
|
||||||
|
|
||||||
|
use crate::ads::random_ad;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct FormattedPath {
|
pub(crate) struct FormattedPath {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
|
@ -81,8 +83,8 @@ pub(crate) fn simple(
|
||||||
|
|
||||||
if !quiet {
|
if !quiet {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{} {paths_len} file{} using {threads} thread{}",
|
"{} {paths_len} file{} using {threads} thread{}.",
|
||||||
if in_place { "Formatting" } else { "Checking formatting in" },
|
if in_place { "Formatting" } else { "Checking style in" },
|
||||||
if paths_len == 1 { "" } else { "s" },
|
if paths_len == 1 { "" } else { "s" },
|
||||||
if threads == 1 { "" } else { "s" },
|
if threads == 1 { "" } else { "s" },
|
||||||
);
|
);
|
||||||
|
@ -182,7 +184,7 @@ pub fn main() -> std::io::Result<()> {
|
||||||
if !args.quiet {
|
if !args.quiet {
|
||||||
eprintln!();
|
eprintln!();
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}! {changed} file{} {}",
|
"{}! {changed} file{} {}.",
|
||||||
if in_place { "Success" } else { "Alert" },
|
if in_place { "Success" } else { "Alert" },
|
||||||
if changed == 1 { "" } else { "s" },
|
if changed == 1 { "" } else { "s" },
|
||||||
if changed == 1 {
|
if changed == 1 {
|
||||||
|
@ -195,7 +197,8 @@ pub fn main() -> std::io::Result<()> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if in_place {
|
if in_place {
|
||||||
ads();
|
println!();
|
||||||
|
print!("{}", random_ad());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::process::exit(if in_place { 0 } else { 2 });
|
std::process::exit(if in_place { 0 } else { 2 });
|
||||||
|
@ -203,11 +206,10 @@ pub fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
if !args.quiet {
|
if !args.quiet {
|
||||||
eprintln!();
|
eprintln!();
|
||||||
eprintln!("Congratulations! Your code complies the Alejandra style");
|
eprintln!("Congratulations! Your code complies the Alejandra style.");
|
||||||
ads();
|
println!();
|
||||||
|
print!("{}", random_ad());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ads() {}
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
pub mod ads;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod find;
|
pub mod find;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue