Compare commits
3 Commits
3df07d7622
...
6b5034c544
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b5034c544 | |||
| 43a75c0b92 | |||
| 130287caa7 |
@@ -90,7 +90,11 @@ Fingers crossed that all compiled and stuff... then copy the bin
|
||||
cp build/rofi ~/bin
|
||||
```
|
||||
|
||||
## TODO & Features That Could be Good
|
||||
## FIXME, TODO & Features That Could be Good
|
||||
* Remove the non-card cards. Examples I've come across are:
|
||||
** Planes: Black Lotus Lounge
|
||||
** Art Cards: https://scryfall.com/card/altr/15/%C3%A9owyn-fearless-knight-%C3%A9owyn-fearless-knight?utm_source=api
|
||||
* Allow exiting the script early (i.e. I hit CTRL+g just exits everything)
|
||||
* Misspelled cards, if only 1 hit that makes sense, could just work
|
||||
* Display the actual card image (probably won't do this)
|
||||
* Some kind of auto-magic direct link between the return codes set out in `main.r`s and the `rofi` scripts. Currently I need to manually make sure they're the same between the `rust` code and the `sh` code.
|
||||
|
||||
@@ -1,64 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Note to self in this... The whitespace seemed to fuck the ifs up. Not sure why.
|
||||
# This is why it's all flat and ugly
|
||||
|
||||
CARDS=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser $@)
|
||||
RETURN=$?
|
||||
echo $RETURN
|
||||
|
||||
#######################
|
||||
## Cards to select from
|
||||
#######################
|
||||
if [ $RETURN -eq 0 ]; then
|
||||
|
||||
SELECTION=$(rofi -dmenu -i << EOF
|
||||
$CARDS
|
||||
EOF
|
||||
)
|
||||
|
||||
CARD_OUTPUT=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser --exact $SELECTION)
|
||||
|
||||
# If you double check the first rofi selection it seems to prevent the error window from popping up
|
||||
# I think this is because it registers the second click as a click outside the window which exits
|
||||
# the rofi -e message
|
||||
sleep 0.05
|
||||
|
||||
rofi -e "$CARD_OUTPUT"
|
||||
fi
|
||||
|
||||
##########################
|
||||
## Not even one card that matched - try a close string
|
||||
##########################
|
||||
if [ $RETURN -eq 105 ]; then
|
||||
|
||||
# TODO do something different with no matching string at all - perhaps even a different ExitCode?
|
||||
|
||||
SELECTION=$(rofi -dmenu -p "Did you mean?" -i << EOF
|
||||
$CARDS
|
||||
EOF
|
||||
)
|
||||
|
||||
CARDS=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser $SELECTION)
|
||||
|
||||
SELECTION=$(rofi -dmenu -i << EOF
|
||||
$CARDS
|
||||
EOF
|
||||
)
|
||||
|
||||
CARD_OUTPUT=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser --exact $SELECTION)
|
||||
|
||||
sleep 0.05
|
||||
|
||||
rofi -e "$CARD_OUTPUT"
|
||||
|
||||
fi
|
||||
|
||||
###############################
|
||||
## No seach string input at all
|
||||
###############################
|
||||
if [ $RETURN -eq 101 ]; then
|
||||
|
||||
rofi -e "No search string found"
|
||||
|
||||
fi
|
||||
SEARCH_STRING=$(rofi -l 0 -dmenu)
|
||||
/home/arthurr/code/mini_projects/scryfall_deser/scripts/search_with_rofi_with_args.sh $SEARCH_STRING
|
||||
|
||||
74
scryfall_deser/scripts/search_with_rofi_with_args.sh
Executable file
74
scryfall_deser/scripts/search_with_rofi_with_args.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Note to self in this... The whitespace seemed to fuck the ifs up. Not sure why.
|
||||
# This is why it's all flat and ugly
|
||||
|
||||
CARDS=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser $@)
|
||||
RETURN=$?
|
||||
echo $RETURN
|
||||
|
||||
#######################
|
||||
## Exact card found - just print the card
|
||||
#######################
|
||||
if [ $RETURN -eq 200 ]; then
|
||||
|
||||
rofi -e "$CARDS"
|
||||
|
||||
fi
|
||||
|
||||
|
||||
#######################
|
||||
## Cards to select from
|
||||
#######################
|
||||
if [ $RETURN -eq 0 ]; then
|
||||
|
||||
SELECTION=$(rofi -dmenu -i << EOF
|
||||
$CARDS
|
||||
EOF
|
||||
)
|
||||
|
||||
CARD_OUTPUT=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser --exact $SELECTION)
|
||||
|
||||
# If you double check the first rofi selection it seems to prevent the error window from popping up
|
||||
# I think this is because it registers the second click as a click outside the window which exits
|
||||
# the rofi -e message
|
||||
sleep 0.05
|
||||
|
||||
rofi -e "$CARD_OUTPUT"
|
||||
fi
|
||||
|
||||
##########################
|
||||
## Not even one card that matched - try a close string
|
||||
##########################
|
||||
if [ $RETURN -eq 105 ]; then
|
||||
|
||||
# TODO do something different with no matching string at all - perhaps even a different ExitCode?
|
||||
|
||||
SELECTION=$(rofi -dmenu -p "Did you mean?" -i << EOF
|
||||
$CARDS
|
||||
EOF
|
||||
)
|
||||
|
||||
CARDS=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser $SELECTION)
|
||||
|
||||
SELECTION=$(rofi -dmenu -i << EOF
|
||||
$CARDS
|
||||
EOF
|
||||
)
|
||||
|
||||
CARD_OUTPUT=$(/home/arthurr/code/mini_projects/scryfall_deser/target/debug/scryfall_deser --exact $SELECTION)
|
||||
|
||||
sleep 0.05
|
||||
|
||||
rofi -e "$CARD_OUTPUT"
|
||||
|
||||
fi
|
||||
|
||||
###############################
|
||||
## No seach string input at all
|
||||
###############################
|
||||
if [ $RETURN -eq 101 ]; then
|
||||
|
||||
rofi -e "No search string found"
|
||||
|
||||
fi
|
||||
@@ -105,6 +105,8 @@ pub fn get_card_by_name(name: &str, name_type: GetNameType) -> Option<DbCard> {
|
||||
FROM cards WHERE lowercase_name = (?1)"
|
||||
}
|
||||
};
|
||||
dbg!(name);
|
||||
dbg!(&sql);
|
||||
let mut stmt = conn.prepare(sql).unwrap();
|
||||
let mut rows = stmt.query([name]).unwrap();
|
||||
match rows.next().unwrap() {
|
||||
|
||||
@@ -17,12 +17,16 @@ impl Termination for MtgCardExit {
|
||||
MtgCardExit::EmptySearchString => ExitCode::from(101),
|
||||
MtgCardExit::NoExactMatchCard => ExitCode::from(102),
|
||||
MtgCardExit::DidYouMean => ExitCode::from(105),
|
||||
MtgCardExit::ExactCardFound => ExitCode::from(200),
|
||||
MtgCardExit::UpdateSuccess => ExitCode::from(201),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum MtgCardExit {
|
||||
Success,
|
||||
UpdateSuccess,
|
||||
ExactCardFound,
|
||||
EmptySearchString,
|
||||
NoExactMatchCard,
|
||||
DidYouMean,
|
||||
@@ -51,7 +55,7 @@ fn exact_search(search_strings: Vec<String>) -> MtgCardExit {
|
||||
}
|
||||
Some(c) => {
|
||||
println!("{}", c);
|
||||
MtgCardExit::Success
|
||||
MtgCardExit::ExactCardFound
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,8 +78,9 @@ fn main() -> MtgCardExit {
|
||||
init_db();
|
||||
let mut path = get_local_cache_folder();
|
||||
path.push(update);
|
||||
// FIXME - if you pass a bad file or something, it just deletes the db
|
||||
update_db_with_file(path);
|
||||
return MtgCardExit::Success;
|
||||
return MtgCardExit::UpdateSuccess;
|
||||
}
|
||||
if args.search_text.is_empty() {
|
||||
dbg!("You need to put some card text to search");
|
||||
@@ -88,6 +93,8 @@ fn main() -> MtgCardExit {
|
||||
}
|
||||
|
||||
let matching_cards = find_matching_cards_scryfall_style(&args.search_text);
|
||||
dbg!(&args.search_text);
|
||||
dbg!(&matching_cards);
|
||||
|
||||
if matching_cards.is_empty() {
|
||||
let mtg_words = get_all_mtg_words();
|
||||
@@ -106,9 +113,11 @@ fn main() -> MtgCardExit {
|
||||
}
|
||||
return MtgCardExit::DidYouMean;
|
||||
} else if matching_cards.len() == 1 {
|
||||
let card = get_card_by_name(&matching_cards[0].name, GetNameType::LowercaseName).unwrap();
|
||||
// FIXME - theres a bug in here - try searching Nalf
|
||||
let card = get_card_by_name(&matching_cards[0].name, GetNameType::Name).unwrap();
|
||||
println!("{}", card);
|
||||
return MtgCardExit::Success;
|
||||
// TODO update this to be more meaningful
|
||||
return MtgCardExit::ExactCardFound;
|
||||
} else {
|
||||
for card in matching_cards {
|
||||
println!(
|
||||
@@ -118,6 +127,7 @@ fn main() -> MtgCardExit {
|
||||
.name
|
||||
);
|
||||
}
|
||||
// TODO update this to be more meaningful
|
||||
return MtgCardExit::Success;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user