1use super::args::Args;
2use pipe_trait::*;
3use std::io::{stdin, stdout, Read, Write};
4
5pub struct App {
6 pub input: String,
7}
8
9impl App {
10 pub fn from_args(args: Args) -> Self {
11 let Args { text } = args;
12 let input = if let Some(input) = text {
13 input
14 } else {
15 let mut buf = String::new();
16 stdin().read_to_string(&mut buf).expect("read from stdin");
17 buf
18 };
19 App { input }
20 }
21
22 pub fn exec(self) {
23 self.input
24 .pipe(strip_ansi_escapes::strip)
25 .expect("strip ansi symbols")
26 .pipe(|output| stdout().write(&output))
27 .expect("write to stdout");
28 }
29}