mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
bug(idf_monitor): fix color on windows with hints
Closes https://github.com/espressif/esp-idf/issues/9610
This commit is contained in:
parent
96f2d215a2
commit
bebd2cec4a
@ -1046,7 +1046,7 @@ int linenoiseProbe(void) {
|
|||||||
flushWrite();
|
flushWrite();
|
||||||
|
|
||||||
/* Try to read response */
|
/* Try to read response */
|
||||||
int timeout_ms = 300;
|
int timeout_ms = 500;
|
||||||
const int retry_ms = 10;
|
const int retry_ms = 10;
|
||||||
size_t read_bytes = 0;
|
size_t read_bytes = 0;
|
||||||
while (timeout_ms > 0 && read_bytes < 4) { // response is ESC[0n or ESC[3n
|
while (timeout_ms > 0 && read_bytes < 4) { // response is ESC[0n or ESC[3n
|
||||||
|
@ -146,7 +146,7 @@ or partition table as applicable.
|
|||||||
Hints on how to resolve errors
|
Hints on how to resolve errors
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
``idf.py`` will try to suggest hints on how to resolve errors. It works with a database of hints stored in :idf_file:`tools/idf_py_actions/hints.yml` and the hints will be printed if a match is found for the given error. The monitor and menuconfig targets are not supported at the moment by automatic hints on resolving errors.
|
``idf.py`` will try to suggest hints on how to resolve errors. It works with a database of hints stored in :idf_file:`tools/idf_py_actions/hints.yml` and the hints will be printed if a match is found for the given error. The menuconfig target is not supported at the moment by automatic hints on resolving errors.
|
||||||
|
|
||||||
The ``--no-hints`` argument of ``idf.py`` can be used to turn the hints off in case they are not desired.
|
The ``--no-hints`` argument of ``idf.py`` can be used to turn the hints off in case they are not desired.
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@ -155,14 +155,14 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|||||||
|
|
||||||
idf_py = [PYTHON] + _get_commandline_options(ctx) # commands to re-run idf.py
|
idf_py = [PYTHON] + _get_commandline_options(ctx) # commands to re-run idf.py
|
||||||
monitor_args += ['-m', ' '.join("'%s'" % a for a in idf_py)]
|
monitor_args += ['-m', ' '.join("'%s'" % a for a in idf_py)]
|
||||||
hints = False # Temporarily disabled because of https://github.com/espressif/esp-idf/issues/9610
|
hints = not args.no_hints
|
||||||
|
|
||||||
# Temporally ignore SIGINT, which is used in idf_monitor to spawn gdb.
|
# Temporally ignore SIGINT, which is used in idf_monitor to spawn gdb.
|
||||||
old_handler = signal.getsignal(signal.SIGINT)
|
old_handler = signal.getsignal(signal.SIGINT)
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
RunTool('idf_monitor', monitor_args, args.project_dir, build_dir=args.build_dir, hints=hints, interactive=True)()
|
RunTool('idf_monitor', monitor_args, args.project_dir, build_dir=args.build_dir, hints=hints, interactive=True, convert_output=True)()
|
||||||
finally:
|
finally:
|
||||||
signal.signal(signal.SIGINT, old_handler)
|
signal.signal(signal.SIGINT, old_handler)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ from typing import Any, Dict, Generator, List, Match, Optional, TextIO, Tuple, U
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
import yaml
|
import yaml
|
||||||
|
from esp_idf_monitor import get_ansi_converter
|
||||||
from idf_py_actions.errors import NoSerialPortFoundError
|
from idf_py_actions.errors import NoSerialPortFoundError
|
||||||
|
|
||||||
from .constants import GENERATORS
|
from .constants import GENERATORS
|
||||||
@ -193,7 +194,7 @@ def fit_text_in_terminal(out: str) -> str:
|
|||||||
|
|
||||||
class RunTool:
|
class RunTool:
|
||||||
def __init__(self, tool_name: str, args: List, cwd: str, env: Dict=None, custom_error_handler: FunctionType=None, build_dir: str=None,
|
def __init__(self, tool_name: str, args: List, cwd: str, env: Dict=None, custom_error_handler: FunctionType=None, build_dir: str=None,
|
||||||
hints: bool=True, force_progression: bool=False, interactive: bool=False) -> None:
|
hints: bool=True, force_progression: bool=False, interactive: bool=False, convert_output: bool=False) -> None:
|
||||||
self.tool_name = tool_name
|
self.tool_name = tool_name
|
||||||
self.args = args
|
self.args = args
|
||||||
self.cwd = cwd
|
self.cwd = cwd
|
||||||
@ -204,6 +205,7 @@ class RunTool:
|
|||||||
self.hints = hints
|
self.hints = hints
|
||||||
self.force_progression = force_progression
|
self.force_progression = force_progression
|
||||||
self.interactive = interactive
|
self.interactive = interactive
|
||||||
|
self.convert_output = convert_output
|
||||||
|
|
||||||
def __call__(self) -> None:
|
def __call__(self) -> None:
|
||||||
def quote_arg(arg: str) -> str:
|
def quote_arg(arg: str) -> str:
|
||||||
@ -303,6 +305,9 @@ class RunTool:
|
|||||||
# and still can not decode it we can just ignore some bytes
|
# and still can not decode it we can just ignore some bytes
|
||||||
return buffer.decode(errors='ignore')
|
return buffer.decode(errors='ignore')
|
||||||
|
|
||||||
|
# use ANSI color converter for Monitor on Windows
|
||||||
|
output_converter = get_ansi_converter(output_stream) if self.convert_output else output_stream
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(output_filename, 'w', encoding='utf8') as output_file:
|
with open(output_filename, 'w', encoding='utf8') as output_file:
|
||||||
while True:
|
while True:
|
||||||
@ -325,8 +330,8 @@ class RunTool:
|
|||||||
# print output in progression way but only the progression related (that started with '[') and if verbose flag is not set
|
# print output in progression way but only the progression related (that started with '[') and if verbose flag is not set
|
||||||
print_progression(output)
|
print_progression(output)
|
||||||
else:
|
else:
|
||||||
output_stream.write(output)
|
output_converter.write(output)
|
||||||
output_stream.flush()
|
output_converter.flush()
|
||||||
except (RuntimeError, EnvironmentError) as e:
|
except (RuntimeError, EnvironmentError) as e:
|
||||||
yellow_print('WARNING: The exception {} was raised and we can\'t capture all your {} and '
|
yellow_print('WARNING: The exception {} was raised and we can\'t capture all your {} and '
|
||||||
'hints on how to resolve errors can be not accurate.'.format(e, output_stream.name.strip('<>')))
|
'hints on how to resolve errors can be not accurate.'.format(e, output_stream.name.strip('<>')))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user