Skip to content

Commit

Permalink
Add check for special value in TERM env variable to disable not color…
Browse files Browse the repository at this point in the history
… ANSI escape codes
  • Loading branch information
JoeJoeTV committed Aug 31, 2023
1 parent 86c63b9 commit 4991542
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
11 changes: 8 additions & 3 deletions AstroTuxLauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, config
from typing import Optional
from utils.misc import ExcludeIfNone, read_build_version, LAUNCHER_VERSION
from utils.misc import ExcludeIfNone, read_build_version, LAUNCHER_VERSION, CONTROL_CODES_SUPPORTED
from utils.termutils import set_window_title
from enum import Enum
from pansi import ansi
Expand Down Expand Up @@ -504,7 +504,7 @@ def exit(self, graceful=False, reason=None):

sys.exit(1)

if __name__ == "__main__":
if __name__ == "__main__":
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("command", type=LauncherCommand, action=interface.EnumStoreAction, help=HELP_COMMAND)
Expand All @@ -515,8 +515,10 @@ def exit(self, graceful=False, reason=None):

args = parser.parse_args()


# Set terminal window title
set_window_title(f"{NAME} - Unofficial Astroneer Dedicated Server Launcher for Linux")
if CONTROL_CODES_SUPPORTED is None:
set_window_title(f"{NAME} - Unofficial Astroneer Dedicated Server Launcher for Linux")

# Print Banner
print(BANNER_LOGO, end="")
Expand All @@ -534,6 +536,9 @@ def exit(self, graceful=False, reason=None):

signal.signal(signal.SIGINT, launcher.user_exit)

if CONTROL_CODES_SUPPORTED == False:
LOGGER.debug("ANSI escape codes except color codes are disabled")

LOGGER.debug(f"CLI Command: {args.command.value}")

if args.command == LauncherCommand.INSTALL:
Expand Down
4 changes: 2 additions & 2 deletions astro/dedicatedserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
from os import path
import os
from utils.misc import ExcludeIfNone, read_build_version
from utils.misc import ExcludeIfNone, read_build_version, CONTROL_CODES_SUPPORTED
from astro.rcon import PlayerCategory
import re
from typing import Optional, List
Expand Down Expand Up @@ -750,7 +750,7 @@ def start(self):
wait_time = self.launcher.config.PlayfabAPIInterval

# Wait for DS to finish registration
with alive_bar(title="Waiting for Dedicated Server to register with Playfab", spinner=DOTS_SPINNER, bar=None, receipt=True, enrich_print=False, monitor=False, stats=False) as bar:
with alive_bar(title="Waiting for Dedicated Server to register with Playfab", spinner=DOTS_SPINNER, bar=None, receipt=True, enrich_print=False, monitor=False, stats=False, force_tty=CONTROL_CODES_SUPPORTED) as bar:
while not self.registered:
# Print all lines currently in process output queue
while True:
Expand Down
7 changes: 7 additions & 0 deletions utils/misc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from os import path
import os

LAUNCHER_VERSION="1.0.1"

CONTROL_CODES_SUPPORTED = None

# If TERM environment variable contains "coloronly", disable stuff that uses ANSI escape codes other than color
if ("TERM" in os.environ) and ("coloronly" in os.environ["TERM"]):
CONTROL_CODES_SUPPORTED = False

def ExcludeIfNone(value):
"""Do not include field for None values"""
return value is None
Expand Down
5 changes: 3 additions & 2 deletions utils/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
from utils.interface import run_proc_with_logging, safeformat, DOTS_SPINNER
from alive_progress import alive_bar
from utils.misc import CONTROL_CODES_SUPPORTED

DEPOTDL_LATEST_ZIP_URL="https://github.com/SteamRE/DepotDownloader/releases/latest/download/DepotDownloader-linux-x64.zip"

Expand Down Expand Up @@ -81,7 +82,7 @@ def dl_depotdownloader(dest_dir, execname="depotdownloader"):

start_time = time.time()

with alive_bar(title="Downloading DepotDownloader", spinner=DOTS_SPINNER, bar="smooth", manual=True, receipt=True, enrich_print=False) as bar:
with alive_bar(title="Downloading DepotDownloader", spinner=DOTS_SPINNER, bar="smooth", manual=True, receipt=True, enrich_print=False, force_tty=CONTROL_CODES_SUPPORTED) as bar:
zip_path, _ = dl.download(bar)

# Extract zip file into tmp dir
Expand Down Expand Up @@ -130,7 +131,7 @@ def update_app(exec_path, app, os, directory):
start_time = time.time()

# Run update command, log output and wait until it is finished
with alive_bar(title=f"Updating app {app}", spinner=DOTS_SPINNER, bar=None, receipt=True, enrich_print=False, monitor=False, stats=False) as bar:
with alive_bar(title=f"Updating app {app}", spinner=DOTS_SPINNER, bar=None, receipt=True, enrich_print=False, monitor=False, stats=False, force_tty=CONTROL_CODES_SUPPORTED) as bar:
proc_res = run_proc_with_logging(cmd_args, "DepotDL", level=logging.DEBUG, alive_bar=bar)

end_time = time.time()
Expand Down

0 comments on commit 4991542

Please sign in to comment.