adding short arguments

This commit is contained in:
e3b 2020-01-04 23:40:30 +01:00
parent 585dcab39b
commit 2190524a38
1 changed files with 27 additions and 21 deletions

View File

@ -121,7 +121,7 @@ struct Orientation {
vector: (f32, f32), vector: (f32, f32),
new_state: &'static str, new_state: &'static str,
x_state: &'static str, x_state: &'static str,
matrix: [&'static str; 9] matrix: [&'static str; 9],
} }
fn main() -> Result<(), String> { fn main() -> Result<(), String> {
@ -151,27 +151,31 @@ fn main() -> Result<(), String> {
Arg::with_name("sleep") Arg::with_name("sleep")
.default_value("500") .default_value("500")
.long("sleep") .long("sleep")
.short("s")
.value_name("SLEEP") .value_name("SLEEP")
.help("Set sleep millis") .help("Set sleep millis")
.takes_value(true), .takes_value(true),
Arg::with_name("display") Arg::with_name("display")
.default_value("eDP-1") .default_value("eDP-1")
.long("display") .long("display")
.short("d")
.value_name("DISPLAY") .value_name("DISPLAY")
.help("Set Display Device") .help("Set Display Device")
.takes_value(true), .takes_value(true),
Arg::with_name("touchscreen") Arg::with_name("touchscreen")
.default_value("ELAN0732:00 04F3:22E1") .default_value("ELAN0732:00 04F3:22E1")
.long("touchscreen") .long("touchscreen")
.short("i")
.value_name("TOUCHSCREEN") .value_name("TOUCHSCREEN")
.help("Set Touchscreen Device (X11)") .help("Set Touchscreen input Device (X11 only)")
.takes_value(true), .takes_value(true),
Arg::with_name("threshold") Arg::with_name("threshold")
.default_value("0.5") .default_value("0.5")
.long("threshold") .long("threshold")
.short("t")
.value_name("THRESHOLD") .value_name("THRESHOLD")
.help("Set a rotation threshold between 0 and 1") .help("Set a rotation threshold between 0 and 1")
.takes_value(true) .takes_value(true),
]; ];
match backend { match backend {
@ -181,15 +185,13 @@ fn main() -> Result<(), String> {
.long("disable-keyboard") .long("disable-keyboard")
.short("k") .short("k")
.help("Disable keyboard for tablet modes (Sway only)") .help("Disable keyboard for tablet modes (Sway only)")
.takes_value(false) .takes_value(false),
); );
} }
Backend::Xorg => { /* Keyboard disabling in Xorg is not supported yet */ } Backend::Xorg => { /* Keyboard disabling in Xorg is not supported yet */ }
} }
let cmd_lines = App::new("rot8") let cmd_lines = App::new("rot8").version("0.1.1").args(&args);
.version("0.1.1")
.args(&args);
let matches = cmd_lines.get_matches(); let matches = cmd_lines.get_matches();
@ -225,26 +227,26 @@ fn main() -> Result<(), String> {
vector: (0.0, -1.0), vector: (0.0, -1.0),
new_state: "normal", new_state: "normal",
x_state: "normal", x_state: "normal",
matrix: ["1", "0", "0", "0", "1", "0", "0", "0", "1"] matrix: ["1", "0", "0", "0", "1", "0", "0", "0", "1"],
}, },
Orientation { Orientation {
vector: (0.0, 1.0), vector: (0.0, 1.0),
new_state: "180", new_state: "180",
x_state: "inverted", x_state: "inverted",
matrix: ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"] matrix: ["-1", "0", "1", "0", "-1", "1", "0", "0", "1"],
}, },
Orientation { Orientation {
vector: (-1.0, 0.0), vector: (-1.0, 0.0),
new_state: "90", new_state: "90",
x_state: "right", x_state: "right",
matrix: ["0", "-1", "1", "1", "0", "0", "0", "0", "1"] matrix: ["0", "-1", "1", "1", "0", "0", "0", "0", "1"],
}, },
Orientation { Orientation {
vector: (1.0, 0.0), vector: (1.0, 0.0),
new_state: "270", new_state: "270",
x_state: "left", x_state: "left",
matrix: ["0", "1", "0", "-1", "0", "1", "0", "0", "1"] matrix: ["0", "1", "0", "-1", "0", "1", "0", "0", "1"],
} },
]; ];
let mut current_orient: &Orientation = &orientations[0]; let mut current_orient: &Orientation = &orientations[0];
@ -272,7 +274,11 @@ fn main() -> Result<(), String> {
matrix = current_orient.matrix; matrix = current_orient.matrix;
if new_state != old_state { if new_state != old_state {
let keyboard_state = if new_state == "normal" { "enabled" } else { "disabled" }; let keyboard_state = if new_state == "normal" {
"enabled"
} else {
"disabled"
};
match backend { match backend {
Backend::Sway => { Backend::Sway => {
Command::new("swaymsg") Command::new("swaymsg")