Skip to content

Commit

Permalink
Merge pull request #3051 from pypa/update-crayons-patch
Browse files Browse the repository at this point in the history
Enabled colors on native powershell
  • Loading branch information
techalchemy authored Oct 17, 2018
2 parents 5e9433e + cb3b837 commit 8212a21
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions news/3020.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated ``crayons`` patch to enable colors on native powershell but swap native blue for magenta.
11 changes: 8 additions & 3 deletions pipenv/patched/crayons.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@
except shellingham.ShellDetectionFailure:
is_powershell = False

if is_ipython or (is_powershell and is_native_powershell):
DISABLE_COLOR = False
REPLACE_BLUE = False
if is_ipython:
"""when ipython is fired lot of variables like _oh, etc are used.
There are so many ways to find current python interpreter is ipython.
get_ipython is easiest is most appealing for readers to understand.
"""
DISABLE_COLOR = True
else:
DISABLE_COLOR = False
elif is_powershell and is_native_powershell:
REPLACE_BLUE = True


class ColoredString(object):
Expand All @@ -69,6 +71,9 @@ def __init__(self, color, s, always_color=False, bold=False):
self.s = s.encode("utf-8")
else:
self.s = s

if color == "BLUE" and REPLACE_BLUE:
color = "MAGENTA"
self.color = color
self.always_color = always_color
self.bold = bold
Expand Down
27 changes: 19 additions & 8 deletions tasks/vendoring/patches/patched/crayons.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/pipenv/patched/crayons.py b/pipenv/patched/crayons.py
index 455d3e90..bb4b3d97 100644
index 455d3e90..de735daf 100644
--- a/pipenv/patched/crayons.py
+++ b/pipenv/patched/crayons.py
@@ -12,21 +12,45 @@ import os
@@ -12,41 +12,72 @@ import os
import re
import sys

Expand Down Expand Up @@ -41,6 +41,7 @@ index 455d3e90..bb4b3d97 100644
+ os.environ.get("CMDER_ROOT")
+ or os.environ.get("VSCODE_PID")
+ or os.environ.get("TERM_PROGRAM") == "Hyper"
+ or "VSCODE_CWD" in os.environ
+):
+ is_native_powershell = False
+else:
Expand All @@ -51,12 +52,19 @@ index 455d3e90..bb4b3d97 100644
+except shellingham.ShellDetectionFailure:
+ is_powershell = False
+
+if is_ipython or (is_powershell and is_native_powershell):
+DISABLE_COLOR = False
+REPLACE_BLUE = False
+if is_ipython:
+ """when ipython is fired lot of variables like _oh, etc are used.
There are so many ways to find current python interpreter is ipython.
get_ipython is easiest is most appealing for readers to understand.
"""
@@ -37,16 +61,17 @@ else:
DISABLE_COLOR = True
-else:
- DISABLE_COLOR = False
+elif is_powershell and is_native_powershell:
+ REPLACE_BLUE = True


class ColoredString(object):
"""Enhanced string for __len__ operations on Colored output."""
Expand All @@ -68,6 +76,9 @@ index 455d3e90..bb4b3d97 100644
+ self.s = s.encode("utf-8")
else:
self.s = s
+
+ if color == "BLUE" and REPLACE_BLUE:
+ color = "MAGENTA"
self.color = color
self.always_color = always_color
self.bold = bold
Expand All @@ -76,7 +87,7 @@ index 455d3e90..bb4b3d97 100644
self.always_color = True

def __getattr__(self, att):
@@ -62,12 +87,19 @@ class ColoredString(object):
@@ -62,12 +93,19 @@ class ColoredString(object):
return [self._new(x) for x in result]
else:
return result
Expand All @@ -98,15 +109,15 @@ index 455d3e90..bb4b3d97 100644

if self.always_color:
return c
@@ -76,7 +108,6 @@ class ColoredString(object):
@@ -76,7 +114,6 @@ class ColoredString(object):
else:
return self.s

-
def __len__(self):
return len(self.s)

@@ -86,12 +117,13 @@ class ColoredString(object):
@@ -86,12 +123,13 @@ class ColoredString(object):
def __unicode__(self):
value = self.color_str
if isinstance(value, bytes):
Expand All @@ -121,7 +132,7 @@ index 455d3e90..bb4b3d97 100644
def __str__(self):
return self.color_str

@@ -105,45 +137,60 @@ class ColoredString(object):
@@ -105,45 +143,60 @@ class ColoredString(object):
return str(other) + str(self.color_str)

def __mul__(self, other):
Expand Down

0 comments on commit 8212a21

Please sign in to comment.