Added some rofi stuff for easier & quicker interaction

Looking actually pretty okay!
This commit is contained in:
2025-08-19 23:01:32 +01:00
parent 3f4af21a93
commit bcf68c8332
3 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
#!/bin/bash
CARDS=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser $@)
SELECTION=$(rofi -dmenu <<< "$CARDS")
CARD_OUTPUT=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser --exact $SELECTION)
rofi -e "$CARD_OUTPUT"

View File

@@ -78,6 +78,22 @@ pub fn update_db_with_file(file: PathBuf) -> bool {
true
}
// unsure if this should be in this file...
impl fmt::Display for DbCard {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.mana_cost {
Some(mc) => writeln!(f, "{}\t{}", self.name, mc)?,
None => writeln!(f, "{}", self.name)?,
}
match &self.oracle_text {
Some(ot) => writeln!(f, "{}", ot)?,
None => (),
}
Ok(())
}
}
#[derive(Debug)]
pub struct DbCard {
pub name: String,

View File

@@ -13,10 +13,22 @@ struct Args {
/// Download the latest bulk from Scryfall and update local db
#[arg(short, long)]
update: bool,
/// Search for the exact string
#[arg(short, long)]
exact: bool,
/// Text to search for card with
search_text: Vec<String>,
}
fn exact_search(search_strings: Vec<String>) {
let search_string = search_strings.join(" ");
let card = get_card_by_name(&search_string, GetNameType::Name);
if card.is_none() {
panic!("No card found with exact name of {}", search_string);
}
println!("{}", card.unwrap());
}
fn main() {
let args = Args::parse();
if args.update {
@@ -30,6 +42,12 @@ fn main() {
if args.search_text.is_empty() {
panic!("You need to put some card text to search");
}
if args.exact {
exact_search(args.search_text);
return;
}
let mut search_string = String::new();
for card in args.search_text {
search_string.push_str(&card.to_lowercase());
@@ -37,6 +55,7 @@ fn main() {
}
search_string.pop();
// This section should be replaced with a SQL command
let cards = get_all_lowercase_card_names();
let mut matching_cards = Vec::new();