Browse Source

[F] Fix windows paths

wuliaozhiji 2 years ago
parent
commit
59fa4e5ecc
2 changed files with 10 additions and 3 deletions
  1. 6 1
      hyfetch/main.py
  2. 4 2
      hyfetch/neofetch_util.py

+ 6 - 1
hyfetch/main.py

@@ -6,6 +6,7 @@ import json
 import random
 import random
 import re
 import re
 from itertools import permutations
 from itertools import permutations
+import traceback
 from typing import Iterable
 from typing import Iterable
 from math import ceil
 from math import ceil
 
 
@@ -389,7 +390,11 @@ def run():
         preset = preset.set_light_dl(config.lightness)
         preset = preset.set_light_dl(config.lightness)
 
 
     # Run
     # Run
-    run_neofetch(preset, config.color_align)
+    try:
+        run_neofetch(preset, config.color_align)
+    except Exception as e:
+        print(f'Error: {e}')
+        traceback.print_exc()
 
 
     if args.ask_exit:
     if args.ask_exit:
         input('Press any key to exit...')
         input('Press any key to exit...')

+ 4 - 2
hyfetch/neofetch_util.py

@@ -6,6 +6,7 @@ import platform
 import re
 import re
 import shlex
 import shlex
 import subprocess
 import subprocess
+import sys
 import zipfile
 import zipfile
 from dataclasses import dataclass
 from dataclasses import dataclass
 from pathlib import Path
 from pathlib import Path
@@ -145,7 +146,7 @@ def get_command_path() -> str:
 
 
     # Windows doesn't support symbolic links, but also I can't detect symbolic links... hard-code it here for now.
     # Windows doesn't support symbolic links, but also I can't detect symbolic links... hard-code it here for now.
     if platform.system() == 'Windows':
     if platform.system() == 'Windows':
-        return str(Path(cmd_path).parent.parent / 'neofetch')
+        return str(Path(cmd_path).parent.parent.parent / 'neofetch')
 
 
     return cmd_path
     return cmd_path
 
 
@@ -192,11 +193,12 @@ def check_windows_cmd():
     """
     """
     if platform.system() == 'Windows':
     if platform.system() == 'Windows':
         import psutil
         import psutil
+        # TODO: This line does not correctly identify cmd prompts...
         if psutil.Process(os.getppid()).name().lower().strip() == 'cmd.exe':
         if psutil.Process(os.getppid()).name().lower().strip() == 'cmd.exe':
             print("cmd.exe doesn't support RGB colors, restarting in MinTTY...")
             print("cmd.exe doesn't support RGB colors, restarting in MinTTY...")
             cmd = f'"{ensure_git_bash().parent.parent / "usr/bin/mintty.exe"}" -s 110,40 -e python -m hyfetch --ask-exit'
             cmd = f'"{ensure_git_bash().parent.parent / "usr/bin/mintty.exe"}" -s 110,40 -e python -m hyfetch --ask-exit'
             os.system(cmd)
             os.system(cmd)
-            exit()
+            sys.exit(0)
 
 
 
 
 def run_command(args: str, pipe: bool = False) -> str | None:
 def run_command(args: str, pipe: bool = False) -> str | None: