mirror of https://git.sr.ht/~nixgoat/vento
history: Add config to disable displaying dirs
This option is separate from the item actions, since it may be important for some users to still see where the actions are being undone. Therefore, I've added this option to a new hierarchy named "history", which is why I've imported serde into the crate.
This commit is contained in:
parent
2ab970c371
commit
63777e6f61
|
@ -842,6 +842,7 @@ dependencies = [
|
|||
"dirs",
|
||||
"fs_extra",
|
||||
"man",
|
||||
"serde",
|
||||
"size_format",
|
||||
"tar",
|
||||
"xz2",
|
||||
|
|
|
@ -25,6 +25,7 @@ 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"
|
||||
|
|
|
@ -21,6 +21,7 @@ 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,10 +43,17 @@ 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 History {
|
||||
display_dir: bool,
|
||||
}
|
||||
|
||||
pub enum Action {
|
||||
Take,
|
||||
Drop,
|
||||
|
@ -86,6 +94,7 @@ pub fn env_config() -> Result<Settings> {
|
|||
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() {
|
||||
|
@ -109,6 +118,7 @@ pub fn parse_config() -> Result<DeserializedConfig> {
|
|||
};
|
||||
|
||||
display_dir = settings.get_bool("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);
|
||||
}
|
||||
|
@ -117,6 +127,7 @@ pub fn parse_config() -> Result<DeserializedConfig> {
|
|||
Ok(DeserializedConfig {
|
||||
directory,
|
||||
display_dir,
|
||||
history_display_dir,
|
||||
display_emoji,
|
||||
display_colors,
|
||||
})
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
*/
|
||||
|
||||
use crate::{
|
||||
common, inv, item,
|
||||
common::{env_config, parse_config},
|
||||
inv, item,
|
||||
message::{append_emoji, throw_error, EmojiType, ErrorType},
|
||||
};
|
||||
use anyhow::Result;
|
||||
|
@ -28,12 +29,9 @@ 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 = [
|
||||
common::env_config()?.vento_dir,
|
||||
Path::new("last").to_path_buf(),
|
||||
]
|
||||
.iter()
|
||||
.collect();
|
||||
let lastpath: PathBuf = [env_config()?.vento_dir, Path::new("last").to_path_buf()]
|
||||
.iter()
|
||||
.collect();
|
||||
|
||||
let lastfile = fs::read_to_string(lastpath)?;
|
||||
|
||||
|
@ -78,9 +76,12 @@ pub fn undo() -> Result<()> {
|
|||
"{}{}{}{}{}{}{}",
|
||||
" (".green(),
|
||||
contents[1].bold(),
|
||||
", from ".green(),
|
||||
contents[0],
|
||||
" to ".green(),
|
||||
", ".green(),
|
||||
match parse_config()?.history_display_dir {
|
||||
true => format!("{} {} ", "from".green(), contents[0],),
|
||||
_ => String::new(),
|
||||
},
|
||||
"to ".green(),
|
||||
match contents[2] {
|
||||
"active" => contents[2].green(),
|
||||
"inactive" => contents[2].blue(),
|
||||
|
@ -100,8 +101,11 @@ pub fn undo() -> Result<()> {
|
|||
_ => contents[2].red(),
|
||||
}
|
||||
.bold(),
|
||||
" slot to ".green(),
|
||||
contents[0],
|
||||
" slot".green(),
|
||||
match parse_config()?.history_display_dir {
|
||||
true => format!(" {} {}", "to".green(), contents[0],),
|
||||
false => String::new(),
|
||||
},
|
||||
")".green(),
|
||||
),
|
||||
_ => String::from(""),
|
||||
|
|
Loading…
Reference in New Issue