item: Don't display slot if not stated explicitly

It is implied that if you're working without the slot argument you are
working with the active slot, therefore it's not needed for the message
to output that.
This commit is contained in:
Lux Aliaga 2023-08-26 10:54:53 -04:00
parent 63777e6f61
commit 1506dc811c
4 changed files with 51 additions and 27 deletions

View File

@ -40,11 +40,11 @@ struct Cli {
fn main() -> Result<()> {
// Handles args in Drop
let cli = Cli::parse();
let unwrapped_slot = cli.slot.unwrap_or(String::from("active"));
let unwrapped_slot = cli.slot.clone().unwrap_or(String::from("active"));
let slot = unwrapped_slot.as_str();
let out = cli.output.unwrap_or(get_current_dir()?);
item::drop(&cli.file, slot, out, true)?;
item::drop(&cli.file, slot, out, true, cli.slot.is_some())?;
Ok(())
}

View File

@ -38,8 +38,8 @@ fn main() -> Result<()> {
// Handles args in Vento
override_color()?;
let cli = Cli::parse();
let slot = cli.slot.unwrap_or(String::from("active"));
let slot = cli.slot.clone().unwrap_or(String::from("active"));
item::take(&cli.file, &slot, true)?;
item::take(&cli.file, &slot, true, cli.slot.is_some())?;
Ok(())
}

View File

@ -48,11 +48,17 @@ pub fn undo() -> Result<()> {
match contents[3] {
"take" => {
let destpath = Path::new(contents[0]).to_path_buf();
item::drop(&String::from(contents[1]), contents[2], destpath, false)?;
item::drop(
&String::from(contents[1]),
contents[2],
destpath,
false,
false,
)?;
}
"drop" => {
let path = vec![contents[0], contents[1]].join("/");
item::take(&path, contents[2], false)?;
item::take(&path, contents[2], false, false)?;
}
"switch" => {
inv::switch(false)?;

View File

@ -28,7 +28,7 @@ use std::fs;
use std::path::{Path, PathBuf};
/// Takes a file or directory and stores it in an inventory slot
pub fn take(file: &String, slot: &str, message: bool) -> Result<()> {
pub fn take(file: &String, slot: &str, message: bool, display_slot: bool) -> Result<()> {
let ventodir = &env_config()?.vento_dir;
if !ventodir.is_dir() {
@ -87,25 +87,31 @@ pub fn take(file: &String, slot: &str, message: bool) -> Result<()> {
if message {
println!(
"{}{} {} {}{} {} {}",
"{}{} {}{}{}",
append_emoji(EmojiType::Success)?,
"Took".green(),
&filename.bold(),
match parse_config()?.display_dir {
true => format! {"{} {} ",
"from".green(),
" from".green(),
&sourcelocation.to_str().unwrap(),
},
_ => String::new(),
},
"to".green(),
match slot {
"active" => slot.green(),
"inactive" => slot.blue(),
_ => slot.red(),
}
.bold(),
"slot".green()
match display_slot {
true => format!(
"{} {} {}",
" to".green(),
match slot {
"active" => slot.green(),
"inactive" => slot.blue(),
_ => slot.red(),
}
.bold(),
"slot".green()
),
_ => String::new(),
},
);
}
@ -113,7 +119,13 @@ pub fn take(file: &String, slot: &str, message: bool) -> Result<()> {
}
/// Drops a file or directory and stores it in an inventory slot
pub fn drop(file: &String, slot: &str, dest: PathBuf, message: bool) -> Result<()> {
pub fn drop(
file: &String,
slot: &str,
dest: PathBuf,
message: bool,
display_slot: bool,
) -> Result<()> {
// Drops a file or directory
let ventodir = &env_config()?.vento_dir;
@ -177,18 +189,24 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf, message: bool) -> Result<(
if message {
println!(
"{}{} {} {} {} {}{}",
"{}{} {}{}{}",
append_emoji(EmojiType::Success)?,
"Dropped".green(),
&file.bold(),
"from".green(),
match slot {
"active" => slot.green(),
"inactive" => slot.blue(),
_ => slot.red(),
}
.bold(),
"slot".green(),
match display_slot {
true => format!(
"{} {} {}",
" from".green(),
match slot {
"active" => slot.green(),
"inactive" => slot.blue(),
_ => slot.red(),
}
.bold(),
"slot".green(),
),
false => String::new(),
},
match parse_config()?.display_dir {
true => format! {"{} {} ",
" into".green(),