From 93ef6da6298f3a98127ed572659b6c24a3f5295e Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 6 Jun 2024 06:08:41 +0800 Subject: refactor: global IS_STDOUT_TERMINAL (#571) --- src/config/mod.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs index 0240a80..fbee667 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -15,12 +15,11 @@ use crate::rag::{Rag, TEMP_RAG_NAME}; use crate::render::{MarkdownRender, RenderOptions}; use crate::utils::{ format_option_value, fuzzy_match, get_env_name, light_theme_from_colorfgbg, now, render_prompt, - set_text, AbortSignal, + set_text, AbortSignal, IS_STDOUT_TERMINAL, }; use anyhow::{anyhow, bail, Context, Result}; use inquire::{Confirm, Select}; -use is_terminal::IsTerminal; use parking_lot::RwLock; use serde::Deserialize; use serde_json::json; @@ -28,7 +27,7 @@ use std::collections::{HashMap, HashSet}; use std::{ env, fs::{create_dir_all, read_dir, read_to_string, remove_file, File, OpenOptions}, - io::{stdout, Write}, + io::Write, path::{Path, PathBuf}, process::exit, sync::Arc, @@ -156,7 +155,7 @@ impl Config { let config_path = Self::config_file()?; let platform = env::var(get_env_name("platform")).ok(); - if working_mode != WorkingMode::Command && platform.is_none() && !config_path.exists() { + if *IS_STDOUT_TERMINAL && platform.is_none() && !config_path.exists() { create_config_file(&config_path)?; } let mut config = if platform.is_some() { @@ -915,7 +914,7 @@ impl Config { } else { None }; - let wrap = if stdout().is_terminal() { + let wrap = if *IS_STDOUT_TERMINAL { self.wrap.clone() } else { None -- cgit v1.2.3