1
0
Эх сурвалжийг харах

Merge pull request #454 from gleitz/feature/colorama

Use `colorama` to support colorization in Powershell
Benjamin Gleitzman 2 жил өмнө
parent
commit
2f84131fd3
3 өөрчлөгдсөн 15 нэмэгдсэн , 4 устгасан
  1. 12 3
      howdoi/howdoi.py
  2. 1 0
      requirements/common.txt
  3. 2 1
      setup.py

+ 12 - 3
howdoi/howdoi.py

@@ -41,6 +41,9 @@ from pyquery import PyQuery as pq
 from requests.exceptions import ConnectionError as RequestsConnectionError
 from requests.exceptions import SSLError
 
+from colorama import init
+init()
+
 from howdoi import __version__
 from howdoi.errors import GoogleValidationError, BingValidationError, DDGValidationError
 
@@ -813,9 +816,15 @@ def command_line_runner():  # pylint: disable=too-many-return-statements,too-man
     if os.getenv('HOWDOI_COLORIZE'):
         args['color'] = True
 
-    utf8_result = howdoi(args).encode('utf-8', 'ignore')
-    # Write UTF-8 to stdout: https://stackoverflow.com/a/3603160
-    sys.stdout.buffer.write(utf8_result)
+    howdoi_result = howdoi(args)
+
+    if os.name == 'nt':
+        # Windows
+        print(howdoi_result)
+    else:
+        utf8_result = howdoi_result.encode('utf-8', 'ignore')
+        # Write UTF-8 to stdout: https://stackoverflow.com/a/3603160
+        sys.stdout.buffer.write(utf8_result)
 
     # close the session to release connection
     howdoi_session.close()

+ 1 - 0
requirements/common.txt

@@ -9,3 +9,4 @@ cachelib==0.1.1
 appdirs==1.4.4
 keep==2.9
 rich==10.13.0
+colorama==0.4.4

+ 2 - 1
setup.py

@@ -105,7 +105,8 @@ setup(
         'cachelib',
         'appdirs',
         'keep',
-        'rich'
+        'rich',
+        'colorama'
     ],
     cmdclass={
         'lint': Lint