chore: setup cli
This commit is contained in:
parent
eec5377347
commit
023427e3f9
9 changed files with 155 additions and 19 deletions
121
Cargo.lock
generated
121
Cargo.lock
generated
|
@ -11,6 +11,56 @@ dependencies = [
|
||||||
"memchr",
|
"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]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -111,6 +161,59 @@ dependencies = [
|
||||||
"libloading",
|
"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]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
|
@ -347,6 +450,12 @@ dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
@ -624,6 +733,12 @@ version = "1.13.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.96"
|
version = "2.0.96"
|
||||||
|
@ -728,6 +843,12 @@ version = "1.0.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243"
|
checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version-compare"
|
name = "version-compare"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
members = [ "cli",
|
members = [
|
||||||
"rmenu-core",
|
"core",
|
||||||
|
"cli",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,5 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = { version = "4.5.27", features = ["derive"] }
|
||||||
|
|
||||||
|
|
0
rmenu-core/Cargo.lock → core/Cargo.lock
generated
0
rmenu-core/Cargo.lock → core/Cargo.lock
generated
|
@ -30,8 +30,10 @@ impl From<MenuError> for Error {
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub bottom: bool,
|
pub bottom: bool,
|
||||||
pub padding: usize,
|
pub height: Option<usize>,
|
||||||
pub lines: i32,
|
pub padding: Option<usize>,
|
||||||
|
pub lines: Option<usize>,
|
||||||
|
pub line_height: Option<usize>,
|
||||||
pub font_family: String,
|
pub font_family: String,
|
||||||
pub font_size: usize,
|
pub font_size: usize,
|
||||||
pub language: Option<String>,
|
pub language: Option<String>,
|
||||||
|
@ -45,30 +47,40 @@ impl Config {
|
||||||
Font::load_from_string(self.font_family.as_str(), self.font_size).unwrap_or_default()
|
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
|
font_height + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn height(&self, line_height: i32) -> i32 {
|
fn calc_lines(&self) -> i32 {
|
||||||
if self.lines > 0 {
|
self.lines.and_then(|n| n.try_into().ok()).unwrap_or(0)
|
||||||
line_height + line_height * self.lines
|
|
||||||
} else {
|
|
||||||
line_height
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
fn apply(self, wmenu: &mut WMenu) {
|
||||||
let font = self.load_font();
|
let font = self.load_font();
|
||||||
|
|
||||||
let font_height = font.height();
|
let font_height = font.height();
|
||||||
let line_height = self.line_height(font_height);
|
let lines = self.calc_lines();
|
||||||
let height = self.height(line_height);
|
let line_height = self.calc_line_height(font_height);
|
||||||
|
let height = self.calc_height(lines, line_height);
|
||||||
|
|
||||||
wmenu
|
wmenu
|
||||||
.height(height)
|
.height(height)
|
||||||
.bottom(self.bottom)
|
.bottom(self.bottom)
|
||||||
.padding(self.padding.try_into().unwrap())
|
.padding(self.calc_padding(height))
|
||||||
.lines(self.lines.try_into().unwrap())
|
.lines(lines)
|
||||||
.line_height(line_height)
|
.line_height(line_height)
|
||||||
.font(&font.to_string())
|
.font(&font.to_string())
|
||||||
.normal_bg(self.normal_color.bg.into())
|
.normal_bg(self.normal_color.bg.into())
|
||||||
|
@ -84,8 +96,10 @@ impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
bottom: false,
|
bottom: false,
|
||||||
lines: 0,
|
height: None,
|
||||||
padding: 16,
|
lines: None,
|
||||||
|
line_height: None,
|
||||||
|
padding: None,
|
||||||
font_family: "monospace".to_string(),
|
font_family: "monospace".to_string(),
|
||||||
font_size: 12,
|
font_size: 12,
|
||||||
language: None,
|
language: None,
|
|
@ -1,3 +0,0 @@
|
||||||
fn main() {
|
|
||||||
println!("Hello, world!");
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue