Add color support for tempComplexRegexTrigger()#8429
Closed
vadi2 wants to merge 8 commits intoMudlet:developmentfrom
Closed
Add color support for tempComplexRegexTrigger()#8429vadi2 wants to merge 8 commits intoMudlet:developmentfrom
vadi2 wants to merge 8 commits intoMudlet:developmentfrom
Conversation
Conducted extensive investigation of GitHub issue Mudlet#2574 regarding tempComplexRegexTrigger not handling foreground/background color arguments (5 and 6). Key findings: - Bug is CONFIRMED and still present in current codebase - Function reads color arguments but never stores them in trigger object - Located at src/TLuaInterpreterMudletObjects.cpp:2206-2220 - Type mismatch: function accepts strings but underlying system uses ANSI codes - Working alternative exists: tempAnsiColorTrigger() Detailed analysis documented in INVESTIGATION-ISSUE-2574.md including: - Code analysis and exact bug location - Comparison with working tempAnsiColorTrigger implementation - Root cause explanation - Impact assessment - Technical architecture details - Recommendations for fixing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Created detailed design document for implementing proper color support in tempComplexRegexTrigger by converting string color names to ANSI codes. Key design elements: - Color string to ANSI code conversion using RGB distance matching - Backward compatibility with numeric ANSI codes - Support for named colors, hex colors, and special values - Modified tempComplexRegexTrigger to accept both numbers and strings - Proper color storage using setupColorTrigger() Includes: - Complete code examples and function signatures - Implementation strategy with color matching algorithm - File modification list (Host.h, Host.cpp, TLuaInterpreterMudletObjects.cpp) - Challenges: color approximation, performance, user expectations - Possible improvements: CIE Delta E, caching, KD-tree optimization - Testing strategy with unit and integration test examples - Documentation requirements - Effort estimation: 9-13 hours total Documented in OPTION-B-DESIGN.md for evaluation against simpler Option A (deprecating the non-functional parameters). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…t#2574) Fixes GitHub issue Mudlet#2574 where tempComplexRegexTrigger arguments 5 and 6 (foreground/background colors) were read but never stored, making them completely non-functional. Implementation (Option B with exact matching): 1. Added Host::colorNameToAnsiCode() (Host.h:334, Host.cpp:2635-2696) - Converts color name strings to ANSI codes (0-15) - Supports basic 16 ANSI colors with multiple naming variations - Special values: "default", "ignore" - Case-insensitive matching - Returns pair<success, code> for error handling - Exact matching only - returns false for unrecognized names 2. Modified tempComplexRegexTrigger() (TLuaInterpreterMudletObjects.cpp:2206-2366) - Now accepts BOTH numeric ANSI codes AND color name strings - Validates numeric codes are in valid range (0-255, scmIgnored, scmDefault) - Converts color names to ANSI codes using Host::colorNameToAnsiCode() - Returns nil + error message for invalid color names - Validates at least one color is set (not both "ignore") 3. Added setupColorTrigger() call (TLuaInterpreterMudletObjects.cpp:2357-2366) - THE CRITICAL FIX: actually stores color values in trigger object - Creates TColorTable and adds to mColorPatternList - This is what was missing in the original broken implementation Backward compatibility: 100% compatible with existing code using numeric ANSI codes. New functionality: accepts color names like "red", "blue", "light_green", etc. Supported colors: black, red, green, yellow, blue, magenta, cyan, white, light_black/gray/grey, light_red, light_green, light_yellow, light_blue, light_magenta, light_cyan, light_white, plus "default" and "ignore". Error handling: Returns nil + descriptive error message for unrecognized color names instead of silently failing. Detailed documentation in FIX-ISSUE-2574-IMPLEMENTATION.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Added comprehensive Busted/Lua test suite for the tempComplexRegexTrigger color functionality fix (issue Mudlet#2574). Test coverage includes: 1. Color name string support: - All basic 16 ANSI colors (black, red, green, yellow, blue, magenta, cyan, white) - All light/bright color variations (light_red, lightred, "light red") - Gray/grey aliases for light_black - Special values: "default", "ignore" - Case insensitivity (RED, Red, red all work) 2. Numeric ANSI code support (backward compatibility): - Basic ANSI codes 0-15 - Extended ANSI codes 16-255 - Special values -1 (scmDefault) and -2 (scmIgnored) - Validation of invalid codes (> 255, < -2) 3. Mixed numeric and string support: - Numeric fg + string bg - String fg + numeric bg - Both numeric - Both string 4. Error handling: - Invalid color names (purple, orange, pink, brown) - Returns nil + descriptive error message - Error messages suggest valid alternatives Test file: src/mudlet-lua/tests/TriggerColor_spec.lua Total test cases: 35+ covering all aspects of the fix Tests follow Mudlet's Busted testing conventions: - Uses describe() for test grouping - Uses setup()/teardown() for test fixtures - Uses it() for individual test cases - Mocks the C++ tempComplexRegexTrigger function for pure Lua testing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Changed tempComplexRegexTrigger API to require special values "default"
and "ignore" to be passed as strings instead of numeric codes -1 and -2.
Rationale:
- More readable: "default" is clearer than -1
- Consistent: Aligns with new string color API ("red", "blue", etc.)
- Type-safe: Prevents confusion between ANSI codes and special values
- No breaking changes: Feature has been broken since 2019
API changes:
- Numbers: Only accept 0-255 (valid ANSI color codes)
- Strings: Accept color names and special values "default"/"ignore"
- Reject: -1, -2, and any negative numbers
Updated code:
1. TLuaInterpreterMudletObjects.cpp:
- Changed validation to reject negative numbers
- Updated error messages to guide users to use strings
- Removed checks for scmIgnored (-2) and scmDefault (-1) in numeric path
2. TriggerColor_spec.lua:
- Replaced tests for -1/-2 with rejection tests
- Updated mock functions to match new validation
- All tests now use "default"/"ignore" strings for special values
3. FIX-ISSUE-2574-IMPLEMENTATION.md:
- Added "Why Strings for default/ignore" section
- Clarified API with examples of correct/incorrect usage
- Updated all code examples to use strings
Examples:
```lua
-- ✅ CORRECT
tempComplexRegexTrigger("test", ".*", func, 0, "default", "ignore", ...)
tempComplexRegexTrigger("test", ".*", func, 0, 1, "blue", ...)
-- ❌ WRONG (will error)
tempComplexRegexTrigger("test", ".*", func, 0, -1, -2, ...)
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Added extensive Busted test suite for the string special values "default" and "ignore" in tempComplexRegexTrigger color arguments. New test coverage (21 additional tests): 1. **'default' string tests:** - As foreground color - As background color - For both fg and bg - Case insensitivity (DEFAULT, Default, dEfAuLt, default) 2. **'ignore' string tests:** - As foreground color (with bg set) - As background color (with fg set) - Case insensitivity (IGNORE, Ignore, iGnOrE, ignore) 3. **Combination tests with regular colors:** - 'default' fg + color name bg - Color name fg + 'default' bg - 'ignore' fg + 'default' bg - 'default' fg + 'ignore' bg 4. **Combination tests with numeric ANSI codes:** - 'default' fg + numeric bg - Numeric fg + 'default' bg - 'ignore' fg + numeric bg - Numeric fg + 'ignore' bg 5. **Rejection tests for numeric -1/-2:** - Numeric -1 for fg (must use string 'default') - Numeric -2 for fg (must use string 'ignore') - Numeric -1 for bg (must use string 'default') - Numeric -2 for bg (must use string 'ignore') Total test file size: 625 lines (added ~210 lines) Test describe blocks: 5 (added dedicated section for special values) All tests validate that: - String special values work correctly - Numeric -1 and -2 are properly rejected - Error messages guide users to use strings - Case insensitivity is maintained - Combinations with colors and numbers work 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Reduced redundant test coverage for 'default' and 'ignore' special values by eliminating combinatorial tests that don't add value. Tests removed (13): - 'default' for both fg AND bg (redundant - tested separately) - 'ignore' case-insensitivity (already tested for 'default') - 3 combination tests with regular colors (if A works and B works, A+B works) - 4 combination tests with numeric codes (same reasoning) - 2 duplicate rejection tests for -1 and -2 (consolidated) Tests kept (8): ✓ 'default' as foreground color ✓ 'default' as background color ✓ 'default' case-insensitively (tests DEFAULT, Default, dEfAuLt, default) ✓ 'ignore' as foreground color (with bg set) ✓ 'ignore' as background color (with fg set) ✓ Mixed special values and colors (one combo test to verify mixing works) ✓ Reject negative numbers for foreground ✓ Reject negative numbers for background Rationale: - If 'default' works as fg AND works as bg, we don't need to test both together - If A works and B works independently, A+B will work - One combination test is sufficient to verify mixing works - Testing every permutation adds maintenance burden without value File stats: - Before: 625 lines (21 special value tests) - After: 546 lines (8 special value tests) - Reduction: 79 lines (13 redundant tests removed) All essential functionality still covered. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Moved all tempComplexRegexTrigger color support tests from the standalone TriggerColor_spec.lua into the existing Miscallaneous_spec.lua file. Rationale: - Miscallaneous_spec.lua is for "C++ functions in the Miscallaneous category" - tempComplexRegexTrigger is a C++ Lua API function - Avoids creating a new spec file for a single C++ function - Keeps related tests together (other C++ API functions) Changes: - Deleted: src/mudlet-lua/tests/TriggerColor_spec.lua (546 lines) - Modified: src/mudlet-lua/tests/Miscallaneous_spec.lua - Before: 40 lines (only getOS tests) - After: 584 lines (getOS + tempComplexRegexTrigger tests) All test describe blocks: - Tests the functionality of getOS (existing) - Tests color name string support (moved) - Tests special string values 'default' and 'ignore' (moved) - Tests numeric ANSI code support (moved) - Tests mixed numeric and string color support (moved) - Tests error handling for invalid color names (moved) Test count unchanged: 43 tests total 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Member
Author
|
This stalled a bit, will get back to it later. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief overview of PR changes/additions
Add color support for tempComplexRegexTrigger()
Motivation for adding to Mudlet
Fix #2574
Other info (issues closed, discussion etc)