Mercurial > hg
comparison mcabber/src/screen.c @ 1286:02ad6200df26
Add selectable time prefixes (vorner)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 25 Aug 2007 23:07:22 +0200 |
parents | 2c96720c4f5b |
children | e42f48103609 |
comparison
equal
deleted
inserted
replaced
1285:1046bbcb6d14 | 1286:02ad6200df26 |
---|---|
626 inline void scr_Beep(void) | 626 inline void scr_Beep(void) |
627 { | 627 { |
628 beep(); | 628 beep(); |
629 } | 629 } |
630 | 630 |
631 // This and following belongs to dynamic setting of time prefix | |
632 static const char *timeprefixes[] = { | |
633 "%m-%d %H:%M ", | |
634 "%H:%M ", | |
635 " " | |
636 }; | |
637 | |
638 static const char *spectimeprefixes[] = { | |
639 "%m-%d %H:%M:%S ", | |
640 "%H:%M:%S ", | |
641 " " | |
642 }; | |
643 | |
644 static int timepreflengths[] = { | |
645 17, | |
646 11, | |
647 6 | |
648 }; | |
649 | |
650 static const char *gettprefix() | |
651 { | |
652 return timeprefixes[settings_opt_get_int("time_prefix")]; | |
653 } | |
654 | |
655 static const char *getspectprefix() | |
656 { | |
657 return spectimeprefixes[settings_opt_get_int("time_prefix")]; | |
658 } | |
659 | |
660 static unsigned getprefixwidth() | |
661 { | |
662 return timepreflengths[settings_opt_get_int("time_prefix")]; | |
663 } | |
664 | |
631 // scr_LogPrint(...) | 665 // scr_LogPrint(...) |
632 // Display a message in the log window. | 666 // Display a message in the log window. |
633 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. | 667 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. |
634 void scr_LogPrint(unsigned int flag, const char *fmt, ...) | 668 void scr_LogPrint(unsigned int flag, const char *fmt, ...) |
635 { | 669 { |
755 tmp->bd=wb->bd; | 789 tmp->bd=wb->bd; |
756 g_free(id); | 790 g_free(id); |
757 } else { // Load buddy history from file (if enabled) | 791 } else { // Load buddy history from file (if enabled) |
758 tmp->bd = g_new0(buffdata, 1); | 792 tmp->bd = g_new0(buffdata, 1); |
759 hlog_read_history(title, &tmp->bd->hbuf, | 793 hlog_read_history(title, &tmp->bd->hbuf, |
760 maxX - Roster_Width - PREFIX_WIDTH); | 794 maxX - Roster_Width - getprefixwidth()); |
761 } | 795 } |
762 | 796 |
763 id = g_strdup(title); | 797 id = g_strdup(title); |
764 mc_strtolower(id); | 798 mc_strtolower(id); |
765 g_hash_table_insert(winbufhash, id, tmp); | 799 g_hash_table_insert(winbufhash, id, tmp); |
814 | 848 |
815 // Display these lines | 849 // Display these lines |
816 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { | 850 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { |
817 wmove(win_entry->win, n, 0); | 851 wmove(win_entry->win, n, 0); |
818 line = *(lines+n); | 852 line = *(lines+n); |
819 // NOTE: update PREFIX_WIDTH if you change the date format!! | |
820 // You need to set it to the whole prefix length + 1 | |
821 if (line) { | 853 if (line) { |
822 if (line->flags & HBB_PREFIX_HLIGHT_OUT) | 854 if (line->flags & HBB_PREFIX_HLIGHT_OUT) |
823 wattrset(win_entry->win, get_color(COLOR_MSGOUT)); | 855 wattrset(win_entry->win, get_color(COLOR_MSGOUT)); |
824 else if (line->flags & HBB_PREFIX_HLIGHT) | 856 else if (line->flags & HBB_PREFIX_HLIGHT) |
825 wattrset(win_entry->win, get_color(COLOR_MSGHL)); | 857 wattrset(win_entry->win, get_color(COLOR_MSGHL)); |
828 else if (line->flags & HBB_PREFIX_IN) | 860 else if (line->flags & HBB_PREFIX_IN) |
829 wattrset(win_entry->win, get_color(COLOR_MSGIN)); | 861 wattrset(win_entry->win, get_color(COLOR_MSGIN)); |
830 | 862 |
831 if (line->timestamp && | 863 if (line->timestamp && |
832 !(line->flags & (HBB_PREFIX_SPECIAL|HBB_PREFIX_CONT))) { | 864 !(line->flags & (HBB_PREFIX_SPECIAL|HBB_PREFIX_CONT))) { |
833 strftime(date, 30, "%m-%d %H:%M", localtime(&line->timestamp)); | 865 strftime(date, 30, gettprefix(), localtime(&line->timestamp)); |
834 } else | 866 } else |
835 strcpy(date, " "); | 867 strcpy(date, " "); |
836 if (!(line->flags & HBB_PREFIX_CONT)) { | 868 if (!(line->flags & HBB_PREFIX_CONT)) { |
837 if (line->flags & HBB_PREFIX_INFO) { | 869 if (line->flags & HBB_PREFIX_INFO) { |
838 char dir = '*'; | 870 char dir = '*'; |
839 if (line->flags & HBB_PREFIX_IN) | 871 if (line->flags & HBB_PREFIX_IN) |
840 dir = '<'; | 872 dir = '<'; |
841 else if (line->flags & HBB_PREFIX_OUT) | 873 else if (line->flags & HBB_PREFIX_OUT) |
842 dir = '>'; | 874 dir = '>'; |
843 wprintw(win_entry->win, "%.11s *%c* ", date, dir); | 875 wprintw(win_entry->win, "%s*%c* ", date, dir); |
844 } else if (line->flags & HBB_PREFIX_ERR) { | 876 } else if (line->flags & HBB_PREFIX_ERR) { |
845 char dir = '#'; | 877 char dir = '#'; |
846 if (line->flags & HBB_PREFIX_IN) | 878 if (line->flags & HBB_PREFIX_IN) |
847 dir = '<'; | 879 dir = '<'; |
848 else if (line->flags & HBB_PREFIX_OUT) | 880 else if (line->flags & HBB_PREFIX_OUT) |
849 dir = '>'; | 881 dir = '>'; |
850 wprintw(win_entry->win, "%.11s #%c# ", date, dir); | 882 wprintw(win_entry->win, "%s#%c# ", date, dir); |
851 } else if (line->flags & HBB_PREFIX_IN) { | 883 } else if (line->flags & HBB_PREFIX_IN) { |
852 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '='; | 884 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '='; |
853 wprintw(win_entry->win, "%.11s <%c= ", date, cryptflag); | 885 wprintw(win_entry->win, "%s<%c= ", date, cryptflag); |
854 } else if (line->flags & HBB_PREFIX_OUT) { | 886 } else if (line->flags & HBB_PREFIX_OUT) { |
855 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-'; | 887 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-'; |
856 wprintw(win_entry->win, "%.11s -%c> ", date, cryptflag); | 888 wprintw(win_entry->win, "%s-%c> ", date, cryptflag); |
857 } else if (line->flags & HBB_PREFIX_SPECIAL) { | 889 } else if (line->flags & HBB_PREFIX_SPECIAL) { |
858 strftime(date, 30, "%m-%d %H:%M:%S", localtime(&line->timestamp)); | 890 strftime(date, 30, getspectprefix(), localtime(&line->timestamp)); |
859 wprintw(win_entry->win, "%.14s ", date); | 891 wprintw(win_entry->win, "%s ", date); |
860 } else { | 892 } else { |
861 wprintw(win_entry->win, "%.11s ", date); | 893 wprintw(win_entry->win, "%s ", date); |
862 } | 894 } |
863 } else { | 895 } else { |
864 wprintw(win_entry->win, " " ); | 896 wprintw(win_entry->win, " " ); |
865 } | 897 } |
866 | 898 |
899 // Make sure we are at the right position | |
900 wmove(win_entry->win, n, getprefixwidth()-1); | |
867 wprintw(win_entry->win, "%s", line->text); // Display text line | 901 wprintw(win_entry->win, "%s", line->text); // Display text line |
868 | 902 |
869 // Return the color back | 903 // Return the color back |
870 if (line->flags & (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT | 904 if (line->flags & (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT |
871 | HBB_PREFIX_INFO | HBB_PREFIX_IN)) | 905 | HBB_PREFIX_INFO | HBB_PREFIX_IN)) |
1007 else | 1041 else |
1008 num_history_blocks = get_max_history_blocks(); | 1042 num_history_blocks = get_max_history_blocks(); |
1009 | 1043 |
1010 text_locale = from_utf8(text); | 1044 text_locale = from_utf8(text); |
1011 hbuf_add_line(&win_entry->bd->hbuf, text_locale, timestamp, prefix_flags, | 1045 hbuf_add_line(&win_entry->bd->hbuf, text_locale, timestamp, prefix_flags, |
1012 maxX - Roster_Width - PREFIX_WIDTH, num_history_blocks); | 1046 maxX - Roster_Width - getprefixwidth(), num_history_blocks); |
1013 g_free(text_locale); | 1047 g_free(text_locale); |
1014 | 1048 |
1015 if (win_entry->bd->cleared) { | 1049 if (win_entry->bd->cleared) { |
1016 win_entry->bd->cleared = FALSE; | 1050 win_entry->bd->cleared = FALSE; |
1017 if (g_list_next(win_entry->bd->top)) | 1051 if (g_list_next(win_entry->bd->top)) |
1208 // is added | 1242 // is added |
1209 buddylist_build(); | 1243 buddylist_build(); |
1210 | 1244 |
1211 // Init prev_chatwidth; this variable will be used to prevent us | 1245 // Init prev_chatwidth; this variable will be used to prevent us |
1212 // from rewrapping buffers when the width doesn't change. | 1246 // from rewrapping buffers when the width doesn't change. |
1213 prev_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; | 1247 prev_chatwidth = maxX - Roster_Width - getprefixwidth(); |
1214 // Wrap existing status buffer lines | 1248 // Wrap existing status buffer lines |
1215 hbuf_rebuild(&statushbuf, prev_chatwidth); | 1249 hbuf_rebuild(&statushbuf, prev_chatwidth); |
1216 | 1250 |
1217 #ifndef UNICODE | 1251 #ifndef UNICODE |
1218 if (utf8_mode) | 1252 if (utf8_mode) |
1262 if (wbp->panel) | 1296 if (wbp->panel) |
1263 replace_panel(wbp->panel, wbp->win); | 1297 replace_panel(wbp->panel, wbp->win); |
1264 // Redo line wrapping | 1298 // Redo line wrapping |
1265 wbp->bd->top = hbuf_previous_persistent(wbp->bd->top); | 1299 wbp->bd->top = hbuf_previous_persistent(wbp->bd->top); |
1266 | 1300 |
1267 new_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; | 1301 new_chatwidth = maxX - Roster_Width - getprefixwidth(); |
1268 if (new_chatwidth != prev_chatwidth) | 1302 if (new_chatwidth != prev_chatwidth) |
1269 hbuf_rebuild(&wbp->bd->hbuf, new_chatwidth); | 1303 hbuf_rebuild(&wbp->bd->hbuf, new_chatwidth); |
1270 } | 1304 } |
1271 | 1305 |
1272 // scr_Resize() | 1306 // scr_Resize() |
1299 // Resize/move special status buffer | 1333 // Resize/move special status buffer |
1300 if (statusWindow) | 1334 if (statusWindow) |
1301 resize_win_buffer(NULL, statusWindow, &dim); | 1335 resize_win_buffer(NULL, statusWindow, &dim); |
1302 | 1336 |
1303 // Update prev_chatwidth, now that all buffers have been resized | 1337 // Update prev_chatwidth, now that all buffers have been resized |
1304 prev_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; | 1338 prev_chatwidth = maxX - Roster_Width - getprefixwidth(); |
1305 | 1339 |
1306 // Refresh current buddy window | 1340 // Refresh current buddy window |
1307 if (chatmode) | 1341 if (chatmode) |
1308 scr_ShowBuddyWindow(); | 1342 scr_ShowBuddyWindow(); |
1309 } | 1343 } |