File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import argparse
2+ import os
23import sys
34
45from gooey import Gooey , GooeyParser
1516from 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+
1830def _add_common_args (parser , use_gui = False ):
1931 parser .add_argument (
2032 "-w" ,
@@ -172,6 +184,13 @@ def apply_absorption_correction(args):
172184
173185def 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 = (
You can’t perform that action at this time.
0 commit comments