item: Add display_dir config

This option allows the user to prevent showing the path where the file
was taken/dropped from. Next up would be implementing this in history
changes.
This commit is contained in:
Lux Aliaga 2023-08-23 08:48:26 -04:00
parent bb02a070f9
commit 2ab970c371
2 changed files with 32 additions and 17 deletions

View File

@ -41,6 +41,7 @@ pub struct HistoryData {
pub struct DeserializedConfig {
pub directory: String,
pub display_dir: bool,
pub display_emoji: bool,
pub display_colors: bool,
}
@ -84,6 +85,7 @@ pub fn env_config() -> Result<Settings> {
/// Handles reading the config file or variables for Vento.
pub fn parse_config() -> Result<DeserializedConfig> {
let mut directory = String::new();
let mut display_dir = true;
let mut display_emoji = true;
let mut display_colors = true;
let mut config = match dirs::config_dir() {
@ -106,6 +108,7 @@ pub fn parse_config() -> Result<DeserializedConfig> {
Err(_) => String::new(),
};
display_dir = settings.get_bool("display_dir").unwrap_or(true);
display_emoji = settings.get_bool("display_emoji").unwrap_or(true);
display_colors = settings.get_bool("display_colors").unwrap_or(true);
}
@ -113,6 +116,7 @@ pub fn parse_config() -> Result<DeserializedConfig> {
Ok(DeserializedConfig {
directory,
display_dir,
display_emoji,
display_colors,
})

View File

@ -18,7 +18,7 @@
*/
use super::{
common,
common::{env_config, history, parse_config, Action, HistoryData},
message::{append_emoji, throw_error, EmojiType, ErrorType},
};
use anyhow::{bail, Result};
@ -29,15 +29,15 @@ 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<()> {
let ventodir = &common::env_config()?.vento_dir;
let ventodir = &env_config()?.vento_dir;
if !ventodir.is_dir() {
// Detects if Vento hasn't been initialized and bails if so
throw_error(ErrorType::NotInitialized)?;
};
let slotdir: PathBuf = match slot {
"active" | "a" => common::env_config()?.active_dir,
"inactive" | "i" => common::env_config()?.inactive_dir,
"active" | "a" => env_config()?.active_dir,
"inactive" | "i" => env_config()?.inactive_dir,
_ => PathBuf::new(),
};
@ -78,21 +78,26 @@ pub fn take(file: &String, slot: &str, message: bool) -> Result<()> {
throw_error(ErrorType::NoFileOrDir)?;
}
common::history(common::HistoryData {
history(HistoryData {
path: sourcelocation.clone(),
file: String::from(filename),
slot: String::from(slot),
action: common::Action::Take,
action: Action::Take,
})?;
if message {
println!(
"{}{} {} {} {} {} {} {}",
"{}{} {} {}{} {} {}",
append_emoji(EmojiType::Success)?,
"Took".green(),
&filename.bold(),
"from".green(),
&sourcelocation.to_str().unwrap(),
match parse_config()?.display_dir {
true => format! {"{} {} ",
"from".green(),
&sourcelocation.to_str().unwrap(),
},
_ => String::new(),
},
"to".green(),
match slot {
"active" => slot.green(),
@ -110,7 +115,7 @@ 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<()> {
// Drops a file or directory
let ventodir = &common::env_config()?.vento_dir;
let ventodir = &env_config()?.vento_dir;
if !ventodir.is_dir() {
// Detects if Vento hasn't been initialized and bails if so
@ -118,8 +123,8 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf, message: bool) -> Result<(
};
let slotdir: PathBuf = match slot {
"active" | "a" => common::env_config()?.active_dir,
"inactive" | "i" => common::env_config()?.inactive_dir,
"active" | "a" => env_config()?.active_dir,
"inactive" | "i" => env_config()?.inactive_dir,
_ => PathBuf::new(),
};
@ -163,16 +168,16 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf, message: bool) -> Result<(
destpath.pop();
common::history(common::HistoryData {
history(HistoryData {
path: destpath.clone(),
file: String::from(file),
slot: String::from(slot),
action: common::Action::Drop,
action: Action::Drop,
})?;
if message {
println!(
"{}{} {} {} {} {} {}",
"{}{} {} {} {} {}{}",
append_emoji(EmojiType::Success)?,
"Dropped".green(),
&file.bold(),
@ -183,8 +188,14 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf, message: bool) -> Result<(
_ => slot.red(),
}
.bold(),
"slot into".green(),
&destpath.to_str().unwrap()
"slot".green(),
match parse_config()?.display_dir {
true => format! {"{} {} ",
" into".green(),
&destpath.to_str().unwrap(),
},
_ => String::new(),
},
);
};