about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAurelien Aptel <aaptel@suse.com>2019-12-03 20:59:18 +0100
committerAurelien Aptel <aaptel@suse.com>2019-12-03 21:10:39 +0100
commit7a0a578a8a56cb6689ac9fce680aa44f5af8926d (patch)
tree1ecea7617f3cf57a8ea5dfc056ec261b6883130a /src
parent4a672bda2202f66c616a7b326c5a497b67ade8fd (diff)
downloadprofani-tty-7a0a578a8a56cb6689ac9fce680aa44f5af8926d.tar.gz
XEP-0392: theme, ui: conditionally colorize user nicks
* add theme_hash_attrs()
* when printing a user message check PREF_COLOR_NICK to decide whether
  to colorize it or not

ideally we should hash the jid instead of the nick but this is already
a first step.
Diffstat (limited to 'src')
-rw-r--r--src/config/theme.c6
-rw-r--r--src/config/theme.h1
-rw-r--r--src/ui/window.c4
3 files changed, 11 insertions, 0 deletions
diff --git a/src/config/theme.c b/src/config/theme.c
index 04074f15..c76de248 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -671,6 +671,12 @@ theme_free_string(char *str)
 }
 
 int
+theme_hash_attrs(const char *str)
+{
+    return COLOR_PAIR(color_pair_cache_hash_str(str));
+}
+
+int
 theme_attrs(theme_item_t attrs)
 {
     int result = 0;
diff --git a/src/config/theme.h b/src/config/theme.h
index edf6e6af..bdca6cf6 100644
--- a/src/config/theme.h
+++ b/src/config/theme.h
@@ -147,6 +147,7 @@ gboolean theme_load(const char *const theme_name);
 gboolean theme_exists(const char *const theme_name);
 GSList* theme_list(void);
 void theme_close(void);
+int theme_hash_attrs(const char *str);
 int theme_attrs(theme_item_t attrs);
 char* theme_get_string(char *str);
 void theme_free_string(char *str);
diff --git a/src/ui/window.c b/src/ui/window.c
index 12bf40f5..47230150 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1453,6 +1453,10 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim
             colour = theme_attrs(THEME_THEM);
         }
 
+        if (prefs_get_boolean(PREF_COLOR_NICK)) {
+            colour = theme_hash_attrs(from);
+        }
+
         if (flags & NO_COLOUR_FROM) {
             colour = 0;
         }