summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: faab23ca0d7faa72e169c350a5277210092b488b (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
mod os;

use ::std::io;
use ::termion::raw::IntoRawMode;
use ::tui::backend::TermionBackend;

use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "what")]
struct Opt {
    #[structopt(short, long)]
    interface: String,
}

fn main() {
    #[cfg(not(target_os = "linux"))]
    compile_error!(
        "Sorry, no implementations for platforms other than linux yet :( - PRs welcome!"
    );

    use os::{get_datalink_channel, get_interface, get_open_sockets, KeyboardEvents};

    let opt = Opt::from_args();
    let stdout = io::stdout().into_raw_mode().unwrap();
    let terminal_backend = TermionBackend::new(stdout);

    let keyboard_events = Box::new(KeyboardEvents);
    let network_interface = get_interface(&opt.interface).unwrap();
    let network_frames = get_datalink_channel(&network_interface);

    let os_input = what::OsInput {
        network_interface,
        network_frames,
        get_open_sockets,
        keyboard_events,
    };

    what::start(terminal_backend, os_input)
}