1
0
Fork 0
mirror of https://git.sr.ht/~nixgoat/vento synced 2025-11-30 00:17:50 +00:00

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.
This commit is contained in:
Lux Aliaga 2023-08-19 20:26:28 -04:00
parent d80ccbea07
commit c1576270b9
4 changed files with 16 additions and 3 deletions

View file

@ -23,11 +23,12 @@ use std::path::Path;
use vento::{ use vento::{
common::get_current_dir, common::get_current_dir,
message::{throw_error, ErrorType}, message::{throw_error, ErrorType},
help, item, help, item, common::override_color
}; };
fn main() -> Result<()> { fn main() -> Result<()> {
// Handles args in Drop // Handles args in Drop
override_color()?;
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() >= 2 { if args.len() >= 2 {
if args[1].contains("--slot=") { if args[1].contains("--slot=") {

View file

@ -21,11 +21,12 @@ use anyhow::Result;
use std::env; use std::env;
use vento::{ use vento::{
message::{throw_error, ErrorType}, message::{throw_error, ErrorType},
help, item, help, item, common::override_color
}; };
fn main() -> Result<()> { fn main() -> Result<()> {
// Handles args in Vento // Handles args in Vento
override_color()?;
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() >= 2 { if args.len() >= 2 {
if args[1].contains("--slot=") { if args[1].contains("--slot=") {

View file

@ -22,11 +22,12 @@ use std::{env, path::PathBuf};
use vento::{ use vento::{
archive, archive,
message::{throw_error, ErrorType}, message::{throw_error, ErrorType},
help, history, inv, help, history, inv, common::override_color
}; };
fn main() -> Result<()> { fn main() -> Result<()> {
// Handles args in Vento // Handles args in Vento
override_color()?;
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() >= 2 { 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 // If the vector for the arguments the command is taking is larger than 2, it most likely means the user has provided an argument

View file

@ -18,6 +18,7 @@
*/ */
use crate::message::{throw_error, ErrorType}; use crate::message::{throw_error, ErrorType};
use colored::control::set_override;
use anyhow::Result; use anyhow::Result;
use config::Config; use config::Config;
use std::env::current_dir; use std::env::current_dir;
@ -162,3 +163,12 @@ pub fn get_current_dir() -> Result<PathBuf> {
Ok(currentdir) Ok(currentdir)
} }
/// Sets color override if display_colors is disabled
pub fn override_color() -> Result<()> {
if !parse_config()?.display_colors {
set_override(false)
}
Ok(())
}