Skip to content

feat: add group chat colors (green) in sidebar with wattrset fix#513

Open
arcesannemannmartin wants to merge 2 commits intod99kris:masterfrom
arcesannemannmartin:master
Open

feat: add group chat colors (green) in sidebar with wattrset fix#513
arcesannemannmartin wants to merge 2 commits intod99kris:masterfrom
arcesannemannmartin:master

Conversation

@arcesannemannmartin
Copy link
Copy Markdown

Summary

Adds green color for group chats in the sidebar, and orange for unread group chats. Also fixes a ncurses color stacking bug.

Root Cause Fix

wattron() ADDS attribute bits using OR — when using multiple COLOR_PAIR values, bits combine unpredictably causing all items to turn green.

Fix: Use wattrset() which REPLACES all attributes at once, combined with highlight attrs.

// Before (broken):
wattron(win, COLOR_PAIR(basePair));
wattron(win, COLOR_PAIR(groupPair)); // bits OR together → undefined

// After (fixed):
wattrset(win, activeAttrs | colorPair); // single replacement

Changes

  • src/uicolorconfig.cpp: add list_color_group_fg and list_color_group_unread_fg keys
  • src/uimodel.h/cpp: add GetChatInfoIsGroupLocked() to check if chat is a group
  • src/uilistview.cpp: apply colors with wattrset; green for groups, orange for unread groups
  • ~/.config/nchat/color.conf: add group color definitions

Testing

LD_LIBRARY_PATH=/home/martinarces/nchat/build/lib timeout 5 ./build/bin/nchat
# exit 124 = timeout without crash

Related

  • 859c19d5 fix: make Config::Get return empty string instead of crashing on missing keys

Martín Arces added 2 commits April 15, 2026 18:45
…ing keys

This fixes a crash (std::out_of_range) that occurred when combining color
config changes in 4 files (uicolorconfig.cpp, uimodel.h, uimodel.cpp,
uilistview.cpp). The crash happened in libncutil.so during color
initialization because:

1. UiColorConfig::m_Config is a static global initialized with the
   default Config constructor (empty map)
2. Static variables with complex init (like lambdas calling
   UiColorConfig::GetColorPair) could run before UiColorConfig::Init()
3. These calls would hit Config::Get() which used m_Map.at(key)
4. Since the map was empty (default ctor), std::out_of_range was thrown

The fix makes Config::Get() return empty string for missing keys with a
warning, instead of crashing. This makes the code more defensive without
breaking existing functionality.
- uicolorconfig: add list_color_group_fg and list_color_group_unread_fg keys
- uimodel: add GetChatInfoIsGroupLocked() to check if chat is a group
- uilistview: use wattrset (not wattron) to apply colors correctly; green for groups, orange for unread groups
- ncurses color fix: wattrset replaces all attrs; wattron adds bits which caused color stacking
@d99kris
Copy link
Copy Markdown
Owner

d99kris commented Apr 19, 2026

Hi @arcesannemannmartin - thanks for contributing. I will try find some time to review and feedback soon.

The Config::Get() crash was actually intentional (so that one never misses to add default config, even if empty), but yep one can argue to do a more developer-friendly assert instead, perhaps using nc_assert. Anyway, let me review properly, perhaps we can use your suggested LOG_WARNING.

@d99kris d99kris self-assigned this Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants