feat(tools): Add auto color to monitor and disable colors from chip logs

ANSI color codes are handled on the host side instead of the chip side. This
will result in shorter log messages transmitted over serial.
This commit is contained in:
Peter Dragun 2024-09-18 15:22:20 +02:00
parent 1143b7639f
commit 2c458f3af1
6 changed files with 18 additions and 7 deletions

View File

@ -2,7 +2,7 @@ menu "Format"
config BOOTLOADER_LOG_COLORS
bool "Color"
default y
default n
help
Use ANSI terminal colors in log output
Enable ANSI terminal color codes.

View File

@ -2,7 +2,7 @@ menu "Format"
config LOG_COLORS
bool "Color"
default y
default n
help
Enable ANSI terminal color codes.
In order to view these, your terminal program must support ANSI color codes.

View File

@ -8,6 +8,7 @@ Log
- `esp_log_buffer_hex` is deprecated, use `ESP_LOG_BUFFER_HEX` instead.
- `esp_log_buffer_char` is deprecated, use `ESP_LOG_BUFFER_CHAR` instead.
- The default value for ``CONFIG_LOG_COLORS`` is now set to false. Colors are added on the host side by default in IDF Monitor. If you want to enable colors in the log output for other console monitors, set ``CONFIG_LOG_COLORS`` to true in your project configuration. To disable automatic coloring in IDF Monitor, run the following command: ``idf.py monitor --disable-auto-color``.
ESP ROM
---------

View File

@ -97,7 +97,7 @@ There are two outputs produced by example:
```
W (274) example: Switch to semihosted stdout
W (274) example: Switched back to UART stdout
I (274) example: Wrote 2798 bytes
I (274) example: Wrote 2776 bytes
====================== HOST DATA START =========================
The following are the graphical (non-control) characters defined by
ISO 8859-1 (1987). Descriptions in words aren't all that helpful,
@ -115,4 +115,3 @@ There are two outputs produced by example:
====================== HOST DATA END =========================
I (694) example: Read 6121 bytes
```

View File

@ -1,6 +1,5 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import os
import shutil
import tempfile
@ -42,7 +41,10 @@ def prepare() -> t.Generator[None, None, None]:
def test_semihost_vfs(dut: IdfDut) -> None:
dut.expect_exact('example: Switch to semihosted stdout')
dut.expect_exact('example: Switched back to UART stdout')
dut.expect_exact('example: Wrote 2798 bytes')
if dut.app.sdkconfig.get('LOG_COLORS') is True:
dut.expect_exact('example: Wrote 2798 bytes')
else:
dut.expect_exact('example: Wrote 2776 bytes')
dut.expect_exact('====================== HOST DATA START =========================')
with open(HOST_FILE_PATH) as f:

View File

@ -105,6 +105,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
timestamps: bool,
timestamp_format: str,
force_color: bool,
disable_auto_color: bool,
) -> None:
"""
Run esp_idf_monitor to watch build output
@ -187,6 +188,9 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
if force_color or os.name == 'nt':
monitor_args += ['--force-color']
if disable_auto_color:
monitor_args += ['--disable-auto-color']
idf_py = [PYTHON] + _get_commandline_options(ctx) # commands to re-run idf.py
monitor_args += ['-m', ' '.join("'%s'" % a for a in idf_py)]
hints = not args.no_hints
@ -1011,6 +1015,11 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
'is_flag': True,
'help': 'Always print ANSI for colors',
},
{
'names': ['--disable-auto-color'],
'is_flag': True,
'help': 'Disable auto coloring logs',
},
],
'order_dependencies': [
'flash',