summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 86d5b85389d21cd88f44e211f4662e28348e57cc (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
extern crate clap;
extern crate colored;

use colored::*;
use clap::{Arg, App};
use std::path::Path;
use std::process;
use std::thread;
use std::sync::mpsc;

mod cli;

fn main() {
    let app = App::new(env!("CARGO_PKG_NAME"))
        .version(env!("CARGO_PKG_VERSION"))
        .author("Yuval Adam")
        .about("A simple UPnP/DLNA casting player")
        .arg(Arg::with_name("FILE")
            .value_name("FILE")
            .help("Media file to stream")
            .index(1)
            .required(true));

    let matches = app.get_matches();
    let infile = matches.value_of("FILE").unwrap();

    if Path::new(infile).exists() {
        println!("\n{} {}\n", "Using input file:".green(), infile.green());
    }
    else {
        println!("\n{} {}\n", "Input file does not exist:".red(), infile.red());
        process::exit(1);
    }

    let (tx, rx) = mpsc::channel();

    let child = thread::spawn(move || {
        let mut controller = cli::Controller::init();
        loop {
            let c = controller.read();
            tx.send(c).unwrap();
            if c == 113 {
                break;
            }
        }
        controller.destroy();
    });

    for received in rx {
        println!("Got char: {}", received);
    }

    println!("Waiting for all thread");
    let _res = child.join();
    println!("Done!");

}