Compare commits

..

No commits in common. "e9aa1b2ee10c2741a6513b57ea6536d22d56fcec" and "bb02a070f955ec8f42406f5e86235e6d8ca01080" have entirely different histories.

7 changed files with 52 additions and 114 deletions

1
Cargo.lock generated
View File

@ -842,7 +842,6 @@ dependencies = [
"dirs",
"fs_extra",
"man",
"serde",
"size_format",
"tar",
"xz2",

View File

@ -25,7 +25,6 @@ config = "0.13"
xz2 = "0.1"
tar = "0.4"
clap = { version = "4.3.23", features = ["derive"] }
serde = "1.0"
[build-dependencies]
man = "0.3.0"

View File

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

View File

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

View File

@ -21,7 +21,6 @@ use crate::message::{throw_error, ErrorType};
use anyhow::Result;
use colored::control::set_override;
use config::Config;
use serde::Deserialize;
use std::env::current_dir;
use std::fs::File;
use std::io::Write;
@ -42,24 +41,10 @@ pub struct HistoryData {
pub struct DeserializedConfig {
pub directory: String,
pub display_dir: bool,
pub history_display_dir: bool,
pub display_emoji: bool,
pub display_colors: bool,
}
#[derive(Debug, Deserialize)]
#[allow(unused)]
struct Item {
display_dir: bool,
}
#[derive(Debug, Deserialize)]
#[allow(unused)]
struct History {
display_dir: bool,
}
pub enum Action {
Take,
Drop,
@ -99,8 +84,6 @@ 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 history_display_dir = true;
let mut display_emoji = true;
let mut display_colors = true;
let mut config = match dirs::config_dir() {
@ -123,8 +106,6 @@ pub fn parse_config() -> Result<DeserializedConfig> {
Err(_) => String::new(),
};
display_dir = settings.get_bool("item.display_dir").unwrap_or(true);
history_display_dir = settings.get_bool("history.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);
}
@ -132,8 +113,6 @@ pub fn parse_config() -> Result<DeserializedConfig> {
Ok(DeserializedConfig {
directory,
display_dir,
history_display_dir,
display_emoji,
display_colors,
})

View File

@ -18,8 +18,7 @@
*/
use crate::{
common::{env_config, parse_config},
inv, item,
common, inv, item,
message::{append_emoji, throw_error, EmojiType, ErrorType},
};
use anyhow::Result;
@ -29,9 +28,12 @@ use std::path::{Path, PathBuf};
/// Undoes the last action made by Vento using the history file located on the Vento directory
pub fn undo() -> Result<()> {
let lastpath: PathBuf = [env_config()?.vento_dir, Path::new("last").to_path_buf()]
.iter()
.collect();
let lastpath: PathBuf = [
common::env_config()?.vento_dir,
Path::new("last").to_path_buf(),
]
.iter()
.collect();
let lastfile = fs::read_to_string(lastpath)?;
@ -48,17 +50,11 @@ 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,
false,
)?;
item::drop(&String::from(contents[1]), contents[2], destpath, false)?;
}
"drop" => {
let path = vec![contents[0], contents[1]].join("/");
item::take(&path, contents[2], false, false)?;
item::take(&path, contents[2], false)?;
}
"switch" => {
inv::switch(false)?;
@ -82,12 +78,9 @@ pub fn undo() -> Result<()> {
"{}{}{}{}{}{}{}",
" (".green(),
contents[1].bold(),
", ".green(),
match parse_config()?.history_display_dir {
true => format!("{} {} ", "from".green(), contents[0],),
_ => String::new(),
},
"to ".green(),
", from ".green(),
contents[0],
" to ".green(),
match contents[2] {
"active" => contents[2].green(),
"inactive" => contents[2].blue(),
@ -107,11 +100,8 @@ pub fn undo() -> Result<()> {
_ => contents[2].red(),
}
.bold(),
" slot".green(),
match parse_config()?.history_display_dir {
true => format!(" {} {}", "to".green(), contents[0],),
false => String::new(),
},
" slot to ".green(),
contents[0],
")".green(),
),
_ => String::from(""),

View File

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