Skip to content

Commit

Permalink
Improve color and terminal width overrides (#7674)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilevkivskyi committed Oct 9, 2019
1 parent 33e3558 commit 40f4d66
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
5 changes: 3 additions & 2 deletions mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ def request(status_file: str, command: str, *, timeout: Optional[int] = None,
args['command'] = command
# Tell the server whether this request was initiated from a human-facing terminal,
# so that it can format the type checking output accordingly.
args['is_tty'] = sys.stdout.isatty()
args['terminal_width'] = get_terminal_width()
args['is_tty'] = sys.stdout.isatty() or int(os.getenv('MYPY_FORCE_COLOR', '0')) > 0
args['terminal_width'] = (int(os.getenv('MYPY_FORCE_TERMINAL_WIDTH', '0')) or
get_terminal_width())
bdata = json.dumps(args).encode('utf8')
_, name = get_status(status_file)
try:
Expand Down
2 changes: 0 additions & 2 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ def run_command(self, command: str, data: Dict[str, object]) -> Dict[str, object
# Only the above commands use some error formatting.
del data['is_tty']
del data['terminal_width']
elif int(os.getenv('MYPY_FORCE_COLOR', '0')):
data['is_tty'] = True
return method(self, **data)

# Command functions (run in the server via RPC).
Expand Down
3 changes: 2 additions & 1 deletion mypy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ def style(self, text: str, color: Literal['red', 'green', 'blue', 'yellow', 'non
def fit_in_terminal(self, messages: List[str],
fixed_terminal_width: Optional[int] = None) -> List[str]:
"""Improve readability by wrapping error messages and trimming source code."""
width = fixed_terminal_width or get_terminal_width()
width = (fixed_terminal_width or int(os.getenv('MYPY_FORCE_TERMINAL_WIDTH', '0')) or
get_terminal_width())
new_messages = messages.copy()
for i, error in enumerate(messages):
if ': error:' in error:
Expand Down

0 comments on commit 40f4d66

Please sign in to comment.