ANSI color support and interactive serial console with command input have been successfully implemented in ESP-Flasher.
Full support for ANSI escape sequences in terminal output, including:
- Text formatting (bold, italic, underline, strikethrough)
- 8 foreground and background colors
- Secret text (redacted)
- Carriage return handling
Serial monitor with command input support:
- Send commands to ESP device
- Automatic timestamping
- ANSI color support
- Thread-safe operation
- Clear console button
- Dynamic input field (appears when viewing logs)
Single console window for all output:
- Shows flashing output (read-only)
- Shows serial logs with input field for commands
- Input field always visible, enabled/disabled based on connection state
-
esp_flasher/console_color.py- Complete ANSI color code parser and renderer
ConsoleStateclass for tracking formatting stateColoredConsoleclass for processing and displaying colored output- Support for all standard ANSI SGR codes (0-49)
- Carriage return handling for progress indicators
- Thread-safe implementation using Qt signals
-
esp_flasher/serial_console.py- Serial port reader for log viewing
SerialReaderclass for thread-safe serial port reading- Emits Qt signals for received lines and errors
- Automatic timestamping of received lines
- Proper cleanup and error handling
-
test_ansi_colors.py- Test script demonstrating all supported ANSI features
- Examples of colors, formatting, and combinations
- Simulated ESP output patterns
-
examples/colored_output_example.py- Practical example showing how to use ANSI colors
ANSIColorshelper class with constants- Simulated flashing process with colored output
- Progress bar implementation
-
examples/serial_console_example.py- Standalone demo of the SerialConsoleWidget
- Shows how to integrate the console in custom applications
- Dark theme setup example
-
ANSI_COLOR_SUPPORT.md- Complete documentation of ANSI color support
- Feature list and usage examples
- Technical implementation details
-
SERIAL_CONSOLE.md- Complete documentation of interactive serial console
- Usage guide and examples
- Troubleshooting section
Major changes:
- Removed old
RedirectTextclass - Integrated
ColoredConsolefor stdout redirection - Added dynamic input field that appears when viewing logs
- Input field includes:
- QLineEdit for command input
- Send button
- Clear button
- Input field is hidden during flashing, visible during log viewing
- Added
SerialReaderintegration for log viewing - Added "Stop Logs" button
- Added state management (
_logs_activeflag) - Added methods:
send_command(),append_log_line(),show_log_error(),clear_console() - Added
stop_logs()method - Added
closeEvent()handler for cleanup - Updated imports to include new modules
Updates:
- Added ANSI color support to features list
- Added interactive serial monitor to features list
- Added new section "ANSI Color Support" in Architecture
- Updated project structure to include new files
- Updated
gui.pymodule description with dynamic input field - Added
serial_console.pymodule description - Updated GUI usage section with input field behavior
Updates:
- Added "Full ANSI color support" to feature list
- Added "Interactive serial monitor with command input support" to feature list
- Bold (
\033[1m) - Italic (
\033[3m) - Underline (
\033[4m) - Strikethrough (
\033[9m)
- 8 foreground colors (black, red, green, yellow, blue, magenta, cyan, white)
- 8 background colors (same as foreground)
- Reset to default (
\033[0m)
- Secret text (hidden from selection, shows as
[redacted]) - Carriage return handling for overwriting lines
- Auto-scroll to bottom
- Thread-safe operation
- ANSI color support for output
- Automatic timestamps (
[HH:MM:SS]) - Thread-safe serial reading
- Auto-scroll to new content
- Command input field
- Enter-to-send functionality
- Send button
- Clear console button
- Command echo in cyan color
- Configurable baud rate (default: 115200)
- Automatic error handling
- Clean shutdown
- Thread-safe operation
-
Regex Pattern:
(?:\x1B|\033)(?:\[(.*?)[@-~]|\].*?(?:\x07|\x1B\\))- Matches ANSI escape sequences
- Supports both
\x1Band\033escape characters
-
State Management:
ConsoleStateclass tracks current formatting- Bold, italic, underline, strikethrough flags
- Foreground and background color
- Secret text flag
-
Qt Integration: Uses
QTextCharFormatfor applying formatting- Font weight for bold
- Font italic for italic
- Font underline/strikethrough
- Foreground/background colors
-
Thread Safety: Qt signals for cross-thread communication
text_writtensignal emitted from any thread_append_textslot runs in GUI thread
Architecture with two main components:
-
SerialReader — Background thread for reading
- Runs in daemon thread
- Emits Qt signals for thread-safe communication
- Handles serial exceptions gracefully
-
GUI Integration — Main window manages serial communication
- Console output area (QTextEdit with ColoredConsole)
- Dynamic input field (QLineEdit) that appears when viewing logs
- Send and Clear buttons
- Manages serial port lifecycle
Run the test script to verify ANSI color support:
python test_ansi_colors.pyOr run the example:
python examples/colored_output_example.pyRun the standalone demo:
python examples/serial_console_example.pyOr use the main GUI and click "View Logs".
- Fully compatible with existing ESP-Flasher functionality
- No breaking changes to existing code
- Works on all supported platforms (Windows, macOS, Linux)
- Requires PyQt5 (already a dependency)
- Support for 256-color palette (
\033[38;5;Nm) - Support for RGB colors (
\033[38;2;R;G;Bm) - Support for bright/intense colors (
\033[90-97m) - Configurable color schemes
- Export console output with colors (HTML/RTF)
- Command history (Up/Down arrows)
- Auto-completion
- Configurable baud rate without reconnecting
- Save logs to file
- Filters for log levels
- Hex view mode
- Configurable line endings (CR, LF, CRLF)
- Local echo option
- ANSI escape codes: https://en.wikipedia.org/wiki/ANSI_escape_code
- Qt text formatting: https://doc.qt.io/qt-5/qtextcharformat.html
- PySerial: https://pyserial.readthedocs.io/