Fix pen color ignored in logCustom when key is set
Thanks a lot for contributing!
When logCustom is called with a TalkerLog that has both a custom pen and a key (e.g., TalkerKey.debug), the custom pen color is ignored and replaced with the key's default color.
talker.logCustom(
TalkerLog(
'WITH A KEY',
pen: AnsiPen()..xterm(46), // Custom green - ignored!
key: TalkerLogType.debug.key,
),
);
Root cause: _handleLogData unconditionally overwrites data.pen via settings.getPenByKey(key, fallbackPen: data.pen). Since debug exists in the default colors map, the fallback is never used.
Fix: Only apply the key's default color when no custom pen was provided:
if (pen == null) {
pen = settings.getPenByKey(key);
data.pen = pen;
}
Added test cases verifying:
- Custom pen is preserved when key is also set
- Default key color still applies when no custom pen provided
Original prompt
This section details on the original issue you should resolve
<issue_title>Talker ignores pen color in logCustom, when the key is set.</issue_title> <issue_description>Describe the bug
Reopening issue: https://github.com/Frezyx/talker/issues/313
As of a version 4.8.3 this is still not working. I am adding full testable code + output screenshot.
final talker = TalkerFlutter.init(); talker.logCustom( TalkerLog( 'WITH A KEY', pen: AnsiPen()..xterm(46), key: TalkerLogType.debug.key, ), ); talker.logCustom( TalkerLog( 'WITHOUT A KEY', pen: AnsiPen()..xterm(46), ), );
I did not go any deeper into the code. Just quickly checked the merged PR(https://github.com/Frezyx/talker/commit/fbe77e0dcfa37a7c44bd8dc68a429256f7e8198a) that should have fix the issue. This one seems maybe a bit of:
This implies to me, at first glance, that the
settings.getPenByLogKey(logTypeKeygets still the pen color by logType key in priority of the setted pen color.Expected behavior The color should be changed appropriately.
Desktop (please complete the following information):
- OS: Linux Mint
Smartphone (please complete the following information):
- Device: Samsung S22 Ultra
- OS: Android 14
</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes Frezyx/talker#381
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.