Skip to content

Commit caaf3e7

Browse files
committed
add condition to remove colors when running GOOEY
1 parent 3fbb01a commit caaf3e7

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import os
23
import sys
34

45
from gooey import Gooey, GooeyParser
@@ -15,6 +16,17 @@
1516
from diffpy.utils.parsers import load_data
1617

1718

19+
def _running_in_gui():
20+
"""Determine if the application is running in a GUI environment.
21+
22+
This function checks if the standard output (sys.stdout) is
23+
connected to a terminal. If not, it assumes the application is
24+
running in a GUI environment, such as when launched by Gooey. This
25+
is used to prevent ANSI escape sequences from rendering in the GUI.
26+
"""
27+
return not sys.stdout.isatty()
28+
29+
1830
def _add_common_args(parser, use_gui=False):
1931
parser.add_argument(
2032
"-w",
@@ -172,6 +184,13 @@ def apply_absorption_correction(args):
172184

173185
def create_parser(use_gui=False):
174186
Parser = GooeyParser if use_gui else argparse.ArgumentParser
187+
188+
# Force no colors when gui is running to avoid ANSI escape codes
189+
# in Gooey output
190+
if use_gui or _running_in_gui():
191+
os.environ["NO_COLOR"] = "1"
192+
os.environ["CLICOLOR"] = "0"
193+
175194
parser = Parser(
176195
prog="labpdfproc",
177196
description=(

0 commit comments

Comments
 (0)