From c1576270b96e67bd9710fe5c06f76ae1136a5511 Mon Sep 17 00:00:00 2001 From: Lux Aliaga Date: Sat, 19 Aug 2023 20:26:28 -0400 Subject: [PATCH] common: Implement display_colors config This works using the override_color() function within common.rs, which, using colored's set_override function and if set to false in the config file, will disable all coloring within the program, in case your terminal isn't that fancy. --- src/bin/drop.rs | 3 ++- src/bin/take.rs | 3 ++- src/bin/vento.rs | 3 ++- src/common.rs | 10 ++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bin/drop.rs b/src/bin/drop.rs index 3f6d1f1..5b8f7f7 100644 --- a/src/bin/drop.rs +++ b/src/bin/drop.rs @@ -23,11 +23,12 @@ use std::path::Path; use vento::{ common::get_current_dir, message::{throw_error, ErrorType}, - help, item, + help, item, common::override_color }; fn main() -> Result<()> { // Handles args in Drop + override_color()?; let args: Vec = env::args().collect(); if args.len() >= 2 { if args[1].contains("--slot=") { diff --git a/src/bin/take.rs b/src/bin/take.rs index e581427..14c1c4b 100644 --- a/src/bin/take.rs +++ b/src/bin/take.rs @@ -21,11 +21,12 @@ use anyhow::Result; use std::env; use vento::{ message::{throw_error, ErrorType}, - help, item, + help, item, common::override_color }; fn main() -> Result<()> { // Handles args in Vento + override_color()?; let args: Vec = env::args().collect(); if args.len() >= 2 { if args[1].contains("--slot=") { diff --git a/src/bin/vento.rs b/src/bin/vento.rs index 0576abb..76210a2 100644 --- a/src/bin/vento.rs +++ b/src/bin/vento.rs @@ -22,11 +22,12 @@ use std::{env, path::PathBuf}; use vento::{ archive, message::{throw_error, ErrorType}, - help, history, inv, + help, history, inv, common::override_color }; fn main() -> Result<()> { // Handles args in Vento + override_color()?; let args: Vec = env::args().collect(); if args.len() >= 2 { // If the vector for the arguments the command is taking is larger than 2, it most likely means the user has provided an argument diff --git a/src/common.rs b/src/common.rs index 09534a4..419a0d1 100644 --- a/src/common.rs +++ b/src/common.rs @@ -18,6 +18,7 @@ */ use crate::message::{throw_error, ErrorType}; +use colored::control::set_override; use anyhow::Result; use config::Config; use std::env::current_dir; @@ -162,3 +163,12 @@ pub fn get_current_dir() -> Result { Ok(currentdir) } + +/// Sets color override if display_colors is disabled +pub fn override_color() -> Result<()> { + if !parse_config()?.display_colors { + set_override(false) + } + + Ok(()) +}