summaryrefslogtreecommitdiff
path: root/cli/src/main.rs
blob: 77c56def963cf39520509b6c85929784f0fe34c6 (plain)
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
use clap::Parser;
use std::io::BufRead;
use std::io::Write;

#[derive(Parser, Debug)]
struct Args {
    #[arg(short)]
    decode: bool
}


fn main() {
    let args = Args::parse();

    let mut stdin = std::io::stdin().lock();
    let mut input = Vec::new();
    stdin.read_until(0, &mut input).unwrap();

    let output = if args.decode {
        let input = input.into_iter().filter(|s| s.is_ascii() && !s.is_ascii_whitespace()).collect::<Vec<u8>>();
        base_keysmash::decode(&input[..])
    } else {
        base_keysmash::encode(&input)
    };

    std::io::stdout().lock().write_all(&output).unwrap();
}