feat: row argument
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use clap::Parser;
|
||||
|
||||
use crate::config::{FONT_COLOR, FONT_COLOR_ACTIVE, BACKGROUND_COLOR, BACKGROUND_COLOR_ACTIVE};
|
||||
use crate::config::{
|
||||
BACKGROUND_COLOR, BACKGROUND_COLOR_ACTIVE, FONT_COLOR, FONT_COLOR_ACTIVE,
|
||||
MAX_ITEM_DISPLAY_COUNT,
|
||||
};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
@@ -19,4 +22,7 @@ pub struct Arguments {
|
||||
|
||||
#[arg(long, help = "The background color of the active item", default_value_t = String::from(BACKGROUND_COLOR_ACTIVE))]
|
||||
pub background_color_active: String,
|
||||
|
||||
#[arg(short, long, help = "The amount of items to display at once", default_value_t = MAX_ITEM_DISPLAY_COUNT)]
|
||||
pub rows: u16,
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ pub const FONT_COLOR_ACTIVE: &str = "#1e1e2e";
|
||||
pub const BACKGROUND_COLOR: &str = "#1e1e2e";
|
||||
pub const BACKGROUND_COLOR_ACTIVE: &str = "#89b4fa";
|
||||
|
||||
pub struct RunnerMenuColors {
|
||||
pub struct RunnerMenuSettings {
|
||||
pub font_color: String,
|
||||
pub font_color_active: String,
|
||||
pub background_color: String,
|
||||
pub background_color_active: String,
|
||||
pub rows: u16,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::{
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use clap::Parser;
|
||||
use config::RunnerMenuColors;
|
||||
use config::RunnerMenuSettings;
|
||||
use executables::get_executables;
|
||||
use runner::Runner;
|
||||
|
||||
@@ -23,11 +23,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut runner = Runner::new(
|
||||
args.prompt,
|
||||
executables,
|
||||
RunnerMenuColors {
|
||||
RunnerMenuSettings {
|
||||
font_color: args.font_color,
|
||||
font_color_active: args.font_color_active,
|
||||
background_color: args.background_color,
|
||||
background_color_active: args.background_color_active,
|
||||
rows: args.rows,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use sdl2::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config::{RunnerMenuColors, FONT_POINT_SIZE, LINE_SPACING, MAX_ITEM_DISPLAY_COUNT, PADDING},
|
||||
config::{RunnerMenuSettings, FONT_POINT_SIZE, LINE_SPACING, MAX_ITEM_DISPLAY_COUNT, PADDING},
|
||||
utils::color_from_hex,
|
||||
};
|
||||
|
||||
@@ -24,11 +24,11 @@ pub struct Runner {
|
||||
ttf: ttf::Sdl2TtfContext,
|
||||
input: String,
|
||||
window_size: (u32, u32),
|
||||
colors: RunnerMenuColors,
|
||||
settings: RunnerMenuSettings,
|
||||
}
|
||||
|
||||
impl Runner {
|
||||
pub fn new(prompt: String, executables: Vec<String>, colors: RunnerMenuColors) -> Self {
|
||||
pub fn new(prompt: String, executables: Vec<String>, colors: RunnerMenuSettings) -> Self {
|
||||
let context = sdl2::init().expect("Error creating SDL context");
|
||||
|
||||
let ttf = ttf::init().expect("Error creating SDL TTF context");
|
||||
@@ -73,7 +73,7 @@ impl Runner {
|
||||
input: String::from(""),
|
||||
ttf,
|
||||
window_size,
|
||||
colors,
|
||||
settings: colors,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,10 +83,11 @@ impl Runner {
|
||||
let mut selection_index: u16 = 0;
|
||||
let mut filtered_executables = self.executables.clone();
|
||||
|
||||
let background_color = color_from_hex(&self.colors.background_color).unwrap();
|
||||
let background_color_active = color_from_hex(&self.colors.background_color_active).unwrap();
|
||||
let font_color = color_from_hex(&self.colors.font_color).unwrap();
|
||||
let font_color_active = color_from_hex(&self.colors.font_color_active).unwrap();
|
||||
let background_color = color_from_hex(&self.settings.background_color).unwrap();
|
||||
let background_color_active =
|
||||
color_from_hex(&self.settings.background_color_active).unwrap();
|
||||
let font_color = color_from_hex(&self.settings.font_color).unwrap();
|
||||
let font_color_active = color_from_hex(&self.settings.font_color_active).unwrap();
|
||||
|
||||
let font_path = String::from("/usr/share/fonts/OTF/GeistMonoNerdFontMono-Regular.otf");
|
||||
|
||||
@@ -210,9 +211,9 @@ impl Runner {
|
||||
// try to keep the selection centered
|
||||
let executables_len: u16 = filtered_executables.len() as u16;
|
||||
let start: u16 = selection_index
|
||||
.saturating_sub(MAX_ITEM_DISPLAY_COUNT.div_euclid(2))
|
||||
.min(executables_len.saturating_sub(MAX_ITEM_DISPLAY_COUNT));
|
||||
let end: u16 = (start + MAX_ITEM_DISPLAY_COUNT).min(executables_len);
|
||||
.saturating_sub(self.settings.rows.div_euclid(2))
|
||||
.min(executables_len.saturating_sub(self.settings.rows));
|
||||
let end: u16 = (start + self.settings.rows).min(executables_len);
|
||||
// ---
|
||||
|
||||
let mut display_count: u16 = 0;
|
||||
|
||||
Reference in New Issue
Block a user