comparison mcabber/mcabber/screen.c @ 2090:16b04d64ec88

Add option to highlight timestamp added by server.
author Hermitifier
date Thu, 03 Apr 2014 16:11:16 +0200
parents e04b6dfbb054
children c4a68361883f
comparison
equal deleted inserted replaced
2089:91a8f3740a1a 2090:16b04d64ec88
438 "rosterselmsg", 438 "rosterselmsg",
439 "rosternewmsg", 439 "rosternewmsg",
440 "info", 440 "info",
441 "msgin", 441 "msgin",
442 "readmark", 442 "readmark",
443 "timestamp",
443 NULL 444 NULL
444 }; 445 };
445 446
446 const char *color; 447 const char *color;
447 const char *background = settings_opt_get("color_background"); 448 const char *background = settings_opt_get("color_background");
523 break; 524 break;
524 case COLOR_READMARK: 525 case COLOR_READMARK:
525 init_pair(i+1, ((color) ? find_color(color) : COLOR_RED), 526 init_pair(i+1, ((color) ? find_color(color) : COLOR_RED),
526 find_color(background)); 527 find_color(background));
527 break; 528 break;
529 case COLOR_TIMESTAMP:
530 init_pair(i+1, ((color) ? find_color(color) : COLOR_WHITE),
531 find_color(background));
532 break;
528 } 533 }
529 } 534 }
530 for (i = COLOR_max; i < (COLOR_max + COLORS); i++) 535 for (i = COLOR_max; i < (COLOR_max + COLORS); i++)
531 init_pair(i, i-COLOR_max, find_color(background)); 536 init_pair(i, i-COLOR_max, find_color(background));
532 537
808 settings_set_guard("color_roster", scr_color_guard); 813 settings_set_guard("color_roster", scr_color_guard);
809 settings_set_guard("color_bgrostersel", scr_color_guard); 814 settings_set_guard("color_bgrostersel", scr_color_guard);
810 settings_set_guard("color_rostersel", scr_color_guard); 815 settings_set_guard("color_rostersel", scr_color_guard);
811 settings_set_guard("color_rosterselmsg", scr_color_guard); 816 settings_set_guard("color_rosterselmsg", scr_color_guard);
812 settings_set_guard("color_rosternewmsg", scr_color_guard); 817 settings_set_guard("color_rosternewmsg", scr_color_guard);
818 settings_set_guard("color_timestamp", scr_color_guard);
813 819
814 getmaxyx(stdscr, maxY, maxX); 820 getmaxyx(stdscr, maxY, maxX);
815 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT; 821 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT;
816 // Note scr_draw_main_window() should be called early after scr_init_curses() 822 // Note scr_draw_main_window() should be called early after scr_init_curses()
817 // to update Log_Win_Height and set max{X,Y} 823 // to update Log_Win_Height and set max{X,Y}
1058 } 1064 }
1059 1065
1060 // scr_line_prefix(line, pref, preflen) 1066 // scr_line_prefix(line, pref, preflen)
1061 // Use data from the hbb_line structure and write the prefix 1067 // Use data from the hbb_line structure and write the prefix
1062 // to pref (not exceeding preflen, trailing null byte included). 1068 // to pref (not exceeding preflen, trailing null byte included).
1063 void scr_line_prefix(hbb_line *line, char *pref, guint preflen) 1069 size_t scr_line_prefix(hbb_line *line, char *pref, guint preflen)
1064 { 1070 {
1065 char date[64]; 1071 char date[64];
1072 size_t timepreflen = 0;
1066 1073
1067 if (line->timestamp && 1074 if (line->timestamp &&
1068 !(line->flags & (HBB_PREFIX_SPECIAL|HBB_PREFIX_CONT))) { 1075 !(line->flags & (HBB_PREFIX_SPECIAL|HBB_PREFIX_CONT))) {
1069 strftime(date, 30, gettprefix(), localtime(&line->timestamp)); 1076 timepreflen = strftime(date, 30, gettprefix(), localtime(&line->timestamp));
1070 } else 1077 } else
1071 strcpy(date, " "); 1078 strcpy(date, " ");
1072 1079
1073 if (!(line->flags & HBB_PREFIX_CONT)) { 1080 if (!(line->flags & HBB_PREFIX_CONT)) {
1074 if (line->flags & HBB_PREFIX_INFO) { 1081 if (line->flags & HBB_PREFIX_INFO) {
1106 receiptflag = 'r'; 1113 receiptflag = 'r';
1107 else 1114 else
1108 receiptflag = '-'; 1115 receiptflag = '-';
1109 g_snprintf(pref, preflen, "%s%c%c> ", date, receiptflag, cryptflag); 1116 g_snprintf(pref, preflen, "%s%c%c> ", date, receiptflag, cryptflag);
1110 } else if (line->flags & HBB_PREFIX_SPECIAL) { 1117 } else if (line->flags & HBB_PREFIX_SPECIAL) {
1111 strftime(date, 30, getspectprefix(), localtime(&line->timestamp)); 1118 timepreflen = strftime(date, 30, getspectprefix(), localtime(&line->timestamp));
1112 g_snprintf(pref, preflen, "%s ", date); 1119 g_snprintf(pref, preflen, "%s ", date);
1113 } else { 1120 } else {
1114 g_snprintf(pref, preflen, "%s ", date); 1121 g_snprintf(pref, preflen, "%s ", date);
1115 } 1122 }
1116 } else { 1123 } else {
1117 g_snprintf(pref, preflen, " "); 1124 g_snprintf(pref, preflen, " ");
1118 } 1125 }
1126 return timepreflen;
1119 } 1127 }
1120 1128
1121 // scr_update_window() 1129 // scr_update_window()
1122 // (Re-)Display the given chat window. 1130 // (Re-)Display the given chat window.
1123 static void scr_update_window(winbuf *win_entry) 1131 static void scr_update_window(winbuf *win_entry)
1186 } 1194 }
1187 } 1195 }
1188 1196
1189 // Display the lines 1197 // Display the lines
1190 for (n = 0 ; n < CHAT_WIN_HEIGHT; n++) { 1198 for (n = 0 ; n < CHAT_WIN_HEIGHT; n++) {
1199 int timelen;
1191 int winy = n + mark_offset; 1200 int winy = n + mark_offset;
1192 wmove(win_entry->win, winy, 0); 1201 wmove(win_entry->win, winy, 0);
1193 line = *(lines+n); 1202 line = *(lines+n);
1194 if (line) { 1203 if (line) {
1195 if (skipline) 1204 if (skipline)
1208 1217
1209 if (color != COLOR_GENERAL) 1218 if (color != COLOR_GENERAL)
1210 wattrset(win_entry->win, get_color(color)); 1219 wattrset(win_entry->win, get_color(color));
1211 1220
1212 // Generate the prefix area and display it 1221 // Generate the prefix area and display it
1213 scr_line_prefix(line, pref, prefixwidth); 1222
1214 wprintw(win_entry->win, pref); 1223 timelen = scr_line_prefix(line, pref, prefixwidth);
1224 if (timelen && line->flags & HBB_PREFIX_DELAYED) {
1225 char tmp;
1226
1227 tmp = pref[timelen];
1228 pref[timelen] = '\0';
1229 wattrset(win_entry->win, get_color(COLOR_TIMESTAMP));
1230 wprintw(win_entry->win, pref);
1231 pref[timelen] = tmp;
1232 wattrset(win_entry->win, get_color(color));
1233 wprintw(win_entry->win, pref+timelen);
1234 } else
1235 wprintw(win_entry->win, pref);
1215 1236
1216 // Make sure we are at the right position 1237 // Make sure we are at the right position
1217 wmove(win_entry->win, winy, prefixwidth-1); 1238 wmove(win_entry->win, winy, prefixwidth-1);
1218 1239
1219 // The MUC nick - overwrite with proper color 1240 // The MUC nick - overwrite with proper color
2206 time_t timestamp, guint prefix_flags, 2227 time_t timestamp, guint prefix_flags,
2207 unsigned mucnicklen, gpointer xep184) 2228 unsigned mucnicklen, gpointer xep184)
2208 { 2229 {
2209 char *xtext; 2230 char *xtext;
2210 2231
2211 if (!timestamp) timestamp = time(NULL); 2232 if (!timestamp)
2233 timestamp = time(NULL);
2234 else
2235 prefix_flags |= HBB_PREFIX_DELAYED;
2212 2236
2213 xtext = ut_expand_tabs(text); // Expand tabs and filter out some chars 2237 xtext = ut_expand_tabs(text); // Expand tabs and filter out some chars
2214 2238
2215 scr_write_in_window(bjid, xtext, timestamp, prefix_flags, FALSE, mucnicklen, 2239 scr_write_in_window(bjid, xtext, timestamp, prefix_flags, FALSE, mucnicklen,
2216 xep184); 2240 xep184);