Skip to content

Latest commit

 

History

History
245 lines (194 loc) · 7.11 KB

File metadata and controls

245 lines (194 loc) · 7.11 KB

Feature Implementation Changelog

Summary

ANSI color support and interactive serial console with command input have been successfully implemented in ESP-Flasher.

New Features

1. ANSI Color Support

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

2. Interactive Serial Console

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)

3. Unified Console Interface

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

New Files

Core Implementation

  1. esp_flasher/console_color.py

    • Complete ANSI color code parser and renderer
    • ConsoleState class for tracking formatting state
    • ColoredConsole class 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
  2. esp_flasher/serial_console.py

    • Serial port reader for log viewing
    • SerialReader class for thread-safe serial port reading
    • Emits Qt signals for received lines and errors
    • Automatic timestamping of received lines
    • Proper cleanup and error handling

Examples

  1. test_ansi_colors.py

    • Test script demonstrating all supported ANSI features
    • Examples of colors, formatting, and combinations
    • Simulated ESP output patterns
  2. examples/colored_output_example.py

    • Practical example showing how to use ANSI colors
    • ANSIColors helper class with constants
    • Simulated flashing process with colored output
    • Progress bar implementation
  3. examples/serial_console_example.py

    • Standalone demo of the SerialConsoleWidget
    • Shows how to integrate the console in custom applications
    • Dark theme setup example

Documentation

  1. ANSI_COLOR_SUPPORT.md

    • Complete documentation of ANSI color support
    • Feature list and usage examples
    • Technical implementation details
  2. SERIAL_CONSOLE.md

    • Complete documentation of interactive serial console
    • Usage guide and examples
    • Troubleshooting section

Modified Files

1. esp_flasher/gui.py

Major changes:

  • Removed old RedirectText class
  • Integrated ColoredConsole for 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 SerialReader integration for log viewing
  • Added "Stop Logs" button
  • Added state management (_logs_active flag)
  • 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

2. DOCUMENTATION.md

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.py module description with dynamic input field
  • Added serial_console.py module description
  • Updated GUI usage section with input field behavior

3. README.md

Updates:

  • Added "Full ANSI color support" to feature list
  • Added "Interactive serial monitor with command input support" to feature list

Features Implemented

ANSI Color Support

Text Formatting

  • Bold (\033[1m)
  • Italic (\033[3m)
  • Underline (\033[4m)
  • Strikethrough (\033[9m)

Colors

  • 8 foreground colors (black, red, green, yellow, blue, magenta, cyan, white)
  • 8 background colors (same as foreground)
  • Reset to default (\033[0m)

Special Features

  • Secret text (hidden from selection, shows as [redacted])
  • Carriage return handling for overwriting lines
  • Auto-scroll to bottom
  • Thread-safe operation

Interactive Serial Console

Console Features

  • ANSI color support for output
  • Automatic timestamps ([HH:MM:SS])
  • Thread-safe serial reading
  • Auto-scroll to new content

Input Features

  • Command input field
  • Enter-to-send functionality
  • Send button
  • Clear console button
  • Command echo in cyan color

Serial Communication

  • Configurable baud rate (default: 115200)
  • Automatic error handling
  • Clean shutdown
  • Thread-safe operation

Implementation Details

ANSI Color Support

  1. Regex Pattern: (?:\x1B|\033)(?:\[(.*?)[@-~]|\].*?(?:\x07|\x1B\\))

    • Matches ANSI escape sequences
    • Supports both \x1B and \033 escape characters
  2. State Management: ConsoleState class tracks current formatting

    • Bold, italic, underline, strikethrough flags
    • Foreground and background color
    • Secret text flag
  3. Qt Integration: Uses QTextCharFormat for applying formatting

    • Font weight for bold
    • Font italic for italic
    • Font underline/strikethrough
    • Foreground/background colors
  4. Thread Safety: Qt signals for cross-thread communication

    • text_written signal emitted from any thread
    • _append_text slot runs in GUI thread

Interactive Serial Console

Architecture with two main components:

  1. SerialReader — Background thread for reading

    • Runs in daemon thread
    • Emits Qt signals for thread-safe communication
    • Handles serial exceptions gracefully
  2. 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

Testing

ANSI Colors

Run the test script to verify ANSI color support:

python test_ansi_colors.py

Or run the example:

python examples/colored_output_example.py

Serial Console

Run the standalone demo:

python examples/serial_console_example.py

Or use the main GUI and click "View Logs".

Compatibility

  • 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)

Future Enhancements

ANSI Colors

  1. Support for 256-color palette (\033[38;5;Nm)
  2. Support for RGB colors (\033[38;2;R;G;Bm)
  3. Support for bright/intense colors (\033[90-97m)
  4. Configurable color schemes
  5. Export console output with colors (HTML/RTF)

Serial Console

  1. Command history (Up/Down arrows)
  2. Auto-completion
  3. Configurable baud rate without reconnecting
  4. Save logs to file
  5. Filters for log levels
  6. Hex view mode
  7. Configurable line endings (CR, LF, CRLF)
  8. Local echo option

References