tvrs/src/tv.rs

55 lines
1.8 KiB
Rust
Raw Normal View History

2019-04-30 16:10:33 +02:00
#[macro_use]
extern crate clap;
use clap::{Arg, App, AppSettings};
2018-09-26 14:49:52 +02:00
use tvrs::MultiScreen;
2018-09-26 13:46:46 +02:00
fn main() {
2018-09-26 14:49:52 +02:00
2019-04-30 16:10:33 +02:00
let matches = App::new(crate_name!())
.author(crate_authors!(" "))
.version(crate_version!())
.setting(AppSettings::ColoredHelp)
2018-09-26 16:58:39 +02:00
.arg(Arg::with_name("action")
.help("Action to do")
.takes_value(true)
.value_name("ACTION")
2019-04-08 09:53:53 +02:00
.possible_values(&["disable", "duplicate", "enable","only-secondary"])
2018-09-26 16:58:39 +02:00
.required(true))
2018-09-26 14:49:52 +02:00
.arg(Arg::with_name("position")
.help("Specify the position of the second screen")
2018-09-26 16:58:39 +02:00
.possible_values(&["left", "right", "above", "below"])
.required_if("action", "enable"))
2018-12-10 14:49:38 +01:00
.arg(Arg::with_name("sound")
.help("Outputs the sound to the HDMI (requires pulseaudio)")
.short("s")
.long("sound"))
2018-09-26 14:49:52 +02:00
.get_matches();
let screens = MultiScreen::detect()
2018-09-26 13:46:46 +02:00
.expect("An error happened while finding screens");
2018-12-10 14:49:38 +01:00
let sound = matches.occurrences_of("sound") > 0;
2018-09-26 14:49:52 +02:00
2018-09-26 16:58:39 +02:00
let result = match matches.value_of("action") {
Some("disable") => screens.only_primary(),
Some("duplicate") => screens.duplicate(),
Some("enable") => {
// Can never fail, clap will crash before this
let side = matches.value_of("position").unwrap().parse().unwrap();
screens.two_screens(side)
},
2019-04-08 09:53:53 +02:00
Some("only-secondary") => screens.only_secondary(),
2018-09-26 16:58:39 +02:00
// Can never happen, clap will crash before this
_ => Ok(())
};
2018-12-10 14:49:38 +01:00
if sound {
if let Err(e) = screens.enable_hdmi_sound_if_present() {
eprintln!("Error: couldn't set hdmi sound: {:?}", e);
}
}
2018-09-26 16:58:39 +02:00
result.expect("An error happenned while executing the command");
2018-09-26 13:46:46 +02:00
}