diff --git a/Cargo.lock b/Cargo.lock index dcb2c99..126d3fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,56 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +dependencies = [ + "anstyle", + "once_cell", + "windows-sys", +] + [[package]] name = "autocfg" version = "1.4.0" @@ -111,6 +161,59 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "4.5.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "cli" +version = "0.1.0" +dependencies = [ + "clap", +] + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "either" version = "1.13.0" @@ -347,6 +450,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.13.0" @@ -624,6 +733,12 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "2.0.96" @@ -728,6 +843,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "version-compare" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index f7eee2f..5059401 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,9 @@ [workspace] -members = [ "cli", - "rmenu-core", +members = [ + "core", + "cli", ] +resolver = "2" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c1fb0b0..e7766f6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -4,3 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] +clap = { version = "4.5.27", features = ["derive"] } + diff --git a/rmenu-core/Cargo.lock b/core/Cargo.lock similarity index 100% rename from rmenu-core/Cargo.lock rename to core/Cargo.lock diff --git a/rmenu-core/Cargo.toml b/core/Cargo.toml similarity index 100% rename from rmenu-core/Cargo.toml rename to core/Cargo.toml diff --git a/rmenu-core/src/color.rs b/core/src/color.rs similarity index 100% rename from rmenu-core/src/color.rs rename to core/src/color.rs diff --git a/rmenu-core/src/font.rs b/core/src/font.rs similarity index 100% rename from rmenu-core/src/font.rs rename to core/src/font.rs diff --git a/rmenu-core/src/lib.rs b/core/src/lib.rs similarity index 76% rename from rmenu-core/src/lib.rs rename to core/src/lib.rs index b176c37..eefae12 100644 --- a/rmenu-core/src/lib.rs +++ b/core/src/lib.rs @@ -30,8 +30,10 @@ impl From for Error { pub struct Config { pub bottom: bool, - pub padding: usize, - pub lines: i32, + pub height: Option, + pub padding: Option, + pub lines: Option, + pub line_height: Option, pub font_family: String, pub font_size: usize, pub language: Option, @@ -45,30 +47,40 @@ impl Config { Font::load_from_string(self.font_family.as_str(), self.font_size).unwrap_or_default() } - fn line_height(&self, font_height: i32) -> i32 { + fn calc_line_height(&self, font_height: i32) -> i32 { font_height + 2 } - fn height(&self, line_height: i32) -> i32 { - if self.lines > 0 { - line_height + line_height * self.lines - } else { - line_height + fn calc_lines(&self) -> i32 { + self.lines.and_then(|n| n.try_into().ok()).unwrap_or(0) + } + + fn calc_height(&self, lines: i32, line_height: i32) -> i32 { + match lines { + 0 => line_height, + lines => line_height + line_height * lines, } } + fn calc_padding(&self, height: i32) -> i32 { + self.padding + .and_then(|n| n.try_into().ok()) + .unwrap_or_else(|| height / 2) + } + fn apply(self, wmenu: &mut WMenu) { let font = self.load_font(); let font_height = font.height(); - let line_height = self.line_height(font_height); - let height = self.height(line_height); + let lines = self.calc_lines(); + let line_height = self.calc_line_height(font_height); + let height = self.calc_height(lines, line_height); wmenu .height(height) .bottom(self.bottom) - .padding(self.padding.try_into().unwrap()) - .lines(self.lines.try_into().unwrap()) + .padding(self.calc_padding(height)) + .lines(lines) .line_height(line_height) .font(&font.to_string()) .normal_bg(self.normal_color.bg.into()) @@ -84,8 +96,10 @@ impl Default for Config { fn default() -> Self { Self { bottom: false, - lines: 0, - padding: 16, + height: None, + lines: None, + line_height: None, + padding: None, font_family: "monospace".to_string(), font_size: 12, language: None, diff --git a/rmenu-core/src/main.rs b/rmenu-core/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/rmenu-core/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}