aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMroik <mroik@delayed.space>2025-03-05 10:01:11 +0100
committerMroik <mroik@delayed.space>2025-03-05 13:02:29 +0100
commit2e1fb0a60a671cd609ff603fa5a371341b7e0fe9 (patch)
tree65f27eed111575e2830ac35b6edd3bbf8724bb2b /src/main.rs
parent749c06e16980768d460e72bc5856db8d0ea94afb (diff)
Add capability to pipe in text0.0.2
Can now pipe in text instead of specifying the filename.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 4803c26..ad66a3e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,7 +5,12 @@ pub mod error;
pub mod event;
pub mod state;
-use std::{error::Error, fs::read_to_string, path::Path};
+use std::{
+ error::Error,
+ fs::read_to_string,
+ io::{stdin, IsTerminal, Read},
+ path::Path,
+};
use app::App;
use clap::Parser;
@@ -36,13 +41,18 @@ fn generate_quotes(path: &Path) -> Result<Vec<String>, Box<dyn Error>> {
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
- let args = Args::parse();
- let path = Path::new(&args.quote);
- let mut quotes = generate_quotes(path).unwrap();
- let mut rng = thread_rng();
- let chosen = rng.gen_range(0..quotes.len());
- let quote = quotes.remove(chosen);
- drop(quotes);
+ let quote = if !stdin().is_terminal() {
+ let mut b = Vec::new();
+ stdin().read_to_end(&mut b).unwrap();
+ String::from_utf8(b).unwrap()
+ } else {
+ let args = Args::parse();
+ let path = Path::new(&args.quote);
+ let mut quotes = generate_quotes(path).unwrap();
+ let mut rng = thread_rng();
+ let chosen = rng.gen_range(0..quotes.len());
+ quotes.remove(chosen)
+ };
// TODO Add more options to choose quotes
let mut app = App::new(&quote);
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj