1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use super::args::Args;
use pipe_trait::*;
use std::io::{stdin, stdout, Read, Write};

pub struct App {
    pub input: String,
}

impl App {
    pub fn from_args(args: Args) -> Self {
        let Args { text } = args;
        let input = if let Some(input) = text {
            input
        } else {
            let mut buf = String::new();
            stdin().read_to_string(&mut buf).expect("read from stdin");
            buf
        };
        App { input }
    }

    pub fn exec(self) {
        self.input
            .pipe(strip_ansi_escapes::strip)
            .expect("strip ansi symbols")
            .pipe(|output| stdout().write(&output))
            .expect("write to stdout");
    }
}