1
5
mirror of https://github.com/vinc/moros.git synced 2024-06-15 05:36:38 +00:00
moros/src/usr/keyboard.rs
Vincent Ollivier e4ce2ab59c
Use exit code to set status var (#360)
* Use exit code

* Add macro_use to sys module

* Replace ExitCode with Result<usize, usize>

* Add status var

* Fix status code

* Replace status with ?

* Fix regex for var substitution

* Remove warnings

* Add temporary fix for failing tests

* Add q shortcut to calc

* Use usize for exit code

* Use process exit codes

* Reintroduce ExitCode enum

* Use ExitCode::UsageError where needed

* Display usage error in find command

* Add doc
2022-06-29 19:23:01 +02:00

45 lines
1.3 KiB
Rust

use crate::sys;
use crate::api::console::Style;
use crate::api::process::ExitCode;
pub fn main(args: &[&str]) -> Result<(), ExitCode> {
if args.len() == 1 {
help();
return Err(ExitCode::UsageError);
}
match args[1] {
"set" => {
if args.len() == 2 {
error!("Keyboard layout missing");
Err(ExitCode::Failure)
} else {
let layout = args[2];
if sys::keyboard::set_keyboard(layout) {
Ok(())
} else {
error!("Unknown keyboard layout");
Err(ExitCode::Failure)
}
}
}
"-h" | "--help" | "help" => {
help();
Ok(())
}
_ => {
error!("Invalid command");
Err(ExitCode::Failure)
}
}
}
fn help() {
let csi_option = Style::color("LightCyan");
let csi_title = Style::color("Yellow");
let csi_reset = Style::reset();
println!("{}Usage:{} keyboard {}<command>{}", csi_title, csi_reset, csi_option, csi_reset);
println!();
println!("{}Commands:{}", csi_title, csi_reset);
println!(" {0}set <layout>{1} Set keyboard layout", csi_option, csi_reset);
}