Added some rofi stuff for easier & quicker interaction
Looking actually pretty okay!
This commit is contained in:
9
scryfall_deser/scripts/search_with_rofi.sh
Executable file
9
scryfall_deser/scripts/search_with_rofi.sh
Executable 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"
|
||||||
@@ -78,6 +78,22 @@ pub fn update_db_with_file(file: PathBuf) -> bool {
|
|||||||
true
|
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)]
|
#[derive(Debug)]
|
||||||
pub struct DbCard {
|
pub struct DbCard {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|||||||
@@ -13,10 +13,22 @@ struct Args {
|
|||||||
/// Download the latest bulk from Scryfall and update local db
|
/// Download the latest bulk from Scryfall and update local db
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
update: bool,
|
update: bool,
|
||||||
|
/// Search for the exact string
|
||||||
|
#[arg(short, long)]
|
||||||
|
exact: bool,
|
||||||
/// Text to search for card with
|
/// Text to search for card with
|
||||||
search_text: Vec<String>,
|
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() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
if args.update {
|
if args.update {
|
||||||
@@ -30,6 +42,12 @@ fn main() {
|
|||||||
if args.search_text.is_empty() {
|
if args.search_text.is_empty() {
|
||||||
panic!("You need to put some card text to search");
|
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();
|
let mut search_string = String::new();
|
||||||
for card in args.search_text {
|
for card in args.search_text {
|
||||||
search_string.push_str(&card.to_lowercase());
|
search_string.push_str(&card.to_lowercase());
|
||||||
@@ -37,6 +55,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
search_string.pop();
|
search_string.pop();
|
||||||
|
|
||||||
|
// This section should be replaced with a SQL command
|
||||||
let cards = get_all_lowercase_card_names();
|
let cards = get_all_lowercase_card_names();
|
||||||
|
|
||||||
let mut matching_cards = Vec::new();
|
let mut matching_cards = Vec::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user