feat: theming through arguments
This commit is contained in:
@@ -1,8 +1,22 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
use crate::config::{FONT_COLOR, FONT_COLOR_ACTIVE, BACKGROUND_COLOR, BACKGROUND_COLOR_ACTIVE};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
pub struct Arguments {
|
pub struct Arguments {
|
||||||
#[arg(short, long, help = "The menu prompt message", default_value_t = String::from(""))]
|
#[arg(short, long, help = "The menu's prompt message", default_value_t = String::from(""))]
|
||||||
pub prompt: String,
|
pub prompt: String,
|
||||||
|
|
||||||
|
#[arg(long, help = "The default font color", default_value_t = String::from(FONT_COLOR))]
|
||||||
|
pub font_color: String,
|
||||||
|
|
||||||
|
#[arg(long, help = "The font color of the selected element", default_value_t = String::from(FONT_COLOR_ACTIVE))]
|
||||||
|
pub font_color_active: String,
|
||||||
|
|
||||||
|
#[arg(long, help = "The default font color", default_value_t = String::from(BACKGROUND_COLOR))]
|
||||||
|
pub background_color: String,
|
||||||
|
|
||||||
|
#[arg(long, help = "The font color of the selected element", default_value_t = String::from(BACKGROUND_COLOR_ACTIVE))]
|
||||||
|
pub background_color_active: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,14 @@ pub const LINE_SPACING: u16 = 2;
|
|||||||
pub const FONT_POINT_SIZE: u16 = 16;
|
pub const FONT_POINT_SIZE: u16 = 16;
|
||||||
|
|
||||||
pub const FONT_COLOR: &str = "#cdd6f4";
|
pub const FONT_COLOR: &str = "#cdd6f4";
|
||||||
pub const FONT_COLOR_SELECTED: &str = "#1e1e2e";
|
pub const FONT_COLOR_ACTIVE: &str = "#1e1e2e";
|
||||||
|
|
||||||
pub const BACKGROUND_COLOR: &str = "#1e1e2e";
|
pub const BACKGROUND_COLOR: &str = "#1e1e2e";
|
||||||
pub const BACKGROUND_COLOR_SELECTED: &str = "#89b4fa";
|
pub const BACKGROUND_COLOR_ACTIVE: &str = "#89b4fa";
|
||||||
|
|
||||||
|
pub struct RunnerMenuColors {
|
||||||
|
pub font_color: String,
|
||||||
|
pub font_color_active: String,
|
||||||
|
pub background_color: String,
|
||||||
|
pub background_color_active: String,
|
||||||
|
}
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@@ -5,13 +5,14 @@ use std::{
|
|||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use config::RunnerMenuColors;
|
||||||
use executables::get_executables;
|
use executables::get_executables;
|
||||||
use runner::Runner;
|
use runner::Runner;
|
||||||
|
|
||||||
mod arguments;
|
mod arguments;
|
||||||
|
mod config;
|
||||||
mod executables;
|
mod executables;
|
||||||
mod runner;
|
mod runner;
|
||||||
mod config;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
@@ -19,7 +20,16 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let executables = get_executables()?;
|
let executables = get_executables()?;
|
||||||
|
|
||||||
let mut runner = Runner::new(args.prompt, executables);
|
let mut runner = Runner::new(
|
||||||
|
args.prompt,
|
||||||
|
executables,
|
||||||
|
RunnerMenuColors {
|
||||||
|
font_color: args.font_color,
|
||||||
|
font_color_active: args.font_color_active,
|
||||||
|
background_color: args.background_color,
|
||||||
|
background_color_active: args.background_color_active,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(program) = runner.run() {
|
if let Some(program) = runner.run() {
|
||||||
run_program(program);
|
run_program(program);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{ops::Add, time::Duration};
|
use std::time::Duration;
|
||||||
|
|
||||||
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
|
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
|
||||||
use sdl2::{
|
use sdl2::{
|
||||||
@@ -12,10 +12,7 @@ use sdl2::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{
|
config::{RunnerMenuColors, FONT_POINT_SIZE, LINE_SPACING, MAX_ITEM_DISPLAY_COUNT, PADDING},
|
||||||
BACKGROUND_COLOR, BACKGROUND_COLOR_SELECTED, FONT_COLOR, FONT_COLOR_SELECTED,
|
|
||||||
FONT_POINT_SIZE, LINE_SPACING, MAX_ITEM_DISPLAY_COUNT, PADDING,
|
|
||||||
},
|
|
||||||
utils::color_from_hex,
|
utils::color_from_hex,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,10 +24,11 @@ pub struct Runner {
|
|||||||
ttf: ttf::Sdl2TtfContext,
|
ttf: ttf::Sdl2TtfContext,
|
||||||
input: String,
|
input: String,
|
||||||
window_size: (u32, u32),
|
window_size: (u32, u32),
|
||||||
|
colors: RunnerMenuColors,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Runner {
|
impl Runner {
|
||||||
pub fn new(prompt: String, executables: Vec<String>) -> Self {
|
pub fn new(prompt: String, executables: Vec<String>, colors: RunnerMenuColors) -> Self {
|
||||||
let context = sdl2::init().expect("Error creating SDL context");
|
let context = sdl2::init().expect("Error creating SDL context");
|
||||||
|
|
||||||
let ttf = ttf::init().expect("Error creating SDL TTF context");
|
let ttf = ttf::init().expect("Error creating SDL TTF context");
|
||||||
@@ -75,6 +73,7 @@ impl Runner {
|
|||||||
input: String::from(""),
|
input: String::from(""),
|
||||||
ttf,
|
ttf,
|
||||||
window_size,
|
window_size,
|
||||||
|
colors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +83,10 @@ impl Runner {
|
|||||||
let mut selection_index: u16 = 0;
|
let mut selection_index: u16 = 0;
|
||||||
let mut filtered_executables = self.executables.clone();
|
let mut filtered_executables = self.executables.clone();
|
||||||
|
|
||||||
let background_color = color_from_hex(BACKGROUND_COLOR).unwrap();
|
let background_color = color_from_hex(&self.colors.background_color).unwrap();
|
||||||
let background_color_selected = color_from_hex(BACKGROUND_COLOR_SELECTED).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 font_path = String::from("/usr/share/fonts/OTF/GeistMonoNerdFontMono-Regular.otf");
|
let font_path = String::from("/usr/share/fonts/OTF/GeistMonoNerdFontMono-Regular.otf");
|
||||||
|
|
||||||
@@ -94,10 +95,6 @@ impl Runner {
|
|||||||
.load_font(font_path.clone(), FONT_POINT_SIZE)
|
.load_font(font_path.clone(), FONT_POINT_SIZE)
|
||||||
.expect(&format!("Error loading font {}", font_path));
|
.expect(&format!("Error loading font {}", font_path));
|
||||||
|
|
||||||
let font_color = color_from_hex(FONT_COLOR).expect("Error loading FONT_COLOR");
|
|
||||||
let font_color_selected =
|
|
||||||
color_from_hex(FONT_COLOR_SELECTED).expect("Error loading FONT_COLOR_SELECTED");
|
|
||||||
|
|
||||||
let creator = self.canvas.texture_creator();
|
let creator = self.canvas.texture_creator();
|
||||||
|
|
||||||
let mut event_pump = self.context.event_pump().unwrap();
|
let mut event_pump = self.context.event_pump().unwrap();
|
||||||
@@ -228,7 +225,7 @@ impl Runner {
|
|||||||
.blended(if i != selection_index {
|
.blended(if i != selection_index {
|
||||||
font_color
|
font_color
|
||||||
} else {
|
} else {
|
||||||
font_color_selected
|
font_color_active
|
||||||
})
|
})
|
||||||
.expect("Error rendering text");
|
.expect("Error rendering text");
|
||||||
|
|
||||||
@@ -245,7 +242,7 @@ impl Runner {
|
|||||||
self.canvas.set_draw_color(if i != selection_index {
|
self.canvas.set_draw_color(if i != selection_index {
|
||||||
background_color
|
background_color
|
||||||
} else {
|
} else {
|
||||||
background_color_selected
|
background_color_active
|
||||||
});
|
});
|
||||||
|
|
||||||
let _ = self.canvas.fill_rect(background_rect);
|
let _ = self.canvas.fill_rect(background_rect);
|
||||||
|
|||||||
Reference in New Issue
Block a user