Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 75:ff119bb11563
[/trunk] Changeset 89 by mikael
* Fix wrapping (prefix) issue.
author | mikael |
---|---|
date | Sat, 16 Apr 2005 17:14:55 +0000 |
parents | b392112ab995 |
children | a8f8492abd44 |
comparison
equal
deleted
inserted
replaced
74:b392112ab995 | 75:ff119bb11563 |
---|---|
244 // Display these lines | 244 // Display these lines |
245 width = scr_WindowWidth(win_entry->win); | 245 width = scr_WindowWidth(win_entry->win); |
246 wmove(win_entry->win, 0, 0); | 246 wmove(win_entry->win, 0, 0); |
247 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { | 247 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { |
248 int r = width; | 248 int r = width; |
249 if (*(lines+n)) { | 249 if (*(lines+2*n)) { |
250 wprintw(win_entry->win, "%s", *(lines+n)); | 250 if (**(lines+2*n)) |
251 r -= strlen(*(lines+n)); | 251 wprintw(win_entry->win, "%s", *(lines+2*n)); // prefix |
252 }// else | 252 else { |
253 // wmove(win_entry->win, n, 0); | 253 wprintw(win_entry->win, " "); |
254 r -= 12; | |
255 } | |
256 wprintw(win_entry->win, "%s", *(lines+2*n+1)); // line | |
257 // Calculate the number of blank characters to empty the line | |
258 r -= strlen(*(lines+2*n)) + strlen(*(lines+2*n+1)); | |
259 } | |
254 for ( ; r>0 ; r--) { | 260 for ( ; r>0 ; r--) { |
255 wprintw(win_entry->win, " "); | 261 wprintw(win_entry->win, " "); |
256 } | 262 } |
257 //// wclrtoeol(win_entry->win); does not work :( | 263 //// wclrtoeol(win_entry->win); does not work :( |
258 } | 264 } |
289 scr_ShowWindow(tmp->jid); | 295 scr_ShowWindow(tmp->jid); |
290 top_panel(inputPanel); | 296 top_panel(inputPanel); |
291 } | 297 } |
292 | 298 |
293 | 299 |
294 void scr_WriteInWindow(const char *winId, char *text, int TimeStamp, | 300 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp, |
295 int force_show) | 301 const char *prefix, int force_show) |
296 { | 302 { |
297 char *line; | 303 char *fullprefix = NULL; |
298 window_entry_t *win_entry; | 304 window_entry_t *win_entry; |
299 int dont_show = FALSE; | 305 int dont_show = FALSE; |
300 | 306 |
301 line = calloc(1, strlen(text)+16); | 307 // Prepare the prefix |
302 | 308 if (prefix || TimeStamp) { |
303 // Prepare line (timestamp + text) | 309 if (!prefix) prefix = ""; |
304 // FIXME: actually timestamp and text should not be merged, there is a prefix | 310 fullprefix = calloc(1, strlen(prefix)+16); |
305 // field in the hbuf_block structure just for that. | 311 if (TimeStamp) { |
306 if (TimeStamp) { | 312 time_t now = time(NULL); |
307 time_t now = time(NULL); | 313 strftime(fullprefix, 12, "[%H:%M] ", localtime(&now)); |
308 strftime(line, 12, "[%H:%M] ", localtime(&now)); | 314 } else { |
309 } else { | 315 strcpy(fullprefix, " "); |
310 strcpy(line, " "); | 316 } |
311 } | 317 strcat(fullprefix, prefix); |
312 strcat(line, text); | 318 } |
313 | 319 |
314 // Look for the window entry. | 320 // Look for the window entry. |
315 win_entry = scr_SearchWindow(winId); | 321 win_entry = scr_SearchWindow(winId); |
316 | 322 |
317 // Do we have to really show the window? | 323 // Do we have to really show the window? |
324 if (win_entry == NULL) { | 330 if (win_entry == NULL) { |
325 win_entry = scr_CreatePanel(winId, ROSTER_WIDTH, 0, CHAT_WIN_HEIGHT, | 331 win_entry = scr_CreatePanel(winId, ROSTER_WIDTH, 0, CHAT_WIN_HEIGHT, |
326 maxX - ROSTER_WIDTH, dont_show); | 332 maxX - ROSTER_WIDTH, dont_show); |
327 } | 333 } |
328 | 334 |
329 hbuf_add_line(&win_entry->hbuf, line, | 335 hbuf_add_line(&win_entry->hbuf, text, fullprefix, |
330 maxX - scr_WindowWidth(rosterWnd) - 14); | 336 maxX - scr_WindowWidth(rosterWnd) - 14); |
331 free(line); | 337 free(fullprefix); |
332 | 338 |
333 if (!dont_show) { | 339 if (!dont_show) { |
334 // Show and refresh the window | 340 // Show and refresh the window |
335 top_panel(win_entry->panel); | 341 top_panel(win_entry->panel); |
336 scr_UpdateWindow(win_entry); | 342 scr_UpdateWindow(win_entry); |
405 refresh(); | 411 refresh(); |
406 endwin(); | 412 endwin(); |
407 return; | 413 return; |
408 } | 414 } |
409 | 415 |
410 // XXX This function is almost useless now. Once we handle properly | |
411 // the prefix in scr_WriteInWindow(), we can remove it... | |
412 void scr_WriteMessage(const char *jid, const char *text, char *prefix) | 416 void scr_WriteMessage(const char *jid, const char *text, char *prefix) |
413 { | 417 { |
414 char *buffer = (char *) malloc(strlen(prefix) + strlen(text) + 1); | 418 scr_WriteInWindow(jid, text, TRUE, prefix, FALSE); |
415 | |
416 if (prefix) | |
417 strcpy(buffer, prefix); | |
418 else | |
419 *buffer = 0; | |
420 | |
421 strcat(buffer, text); | |
422 | |
423 scr_WriteInWindow(jid, buffer, TRUE, FALSE); | |
424 | |
425 free(buffer); | |
426 } | 419 } |
427 | 420 |
428 void scr_WriteIncomingMessage(const char *jidfrom, const char *text) | 421 void scr_WriteIncomingMessage(const char *jidfrom, const char *text) |
429 { | 422 { |
430 char *buffer = utf8_decode(text); | 423 char *buffer = utf8_decode(text); |
431 // FIXME expand tabs... | 424 // FIXME expand tabs / filter out special chars... |
432 scr_WriteMessage(jidfrom, buffer, "<== "); | 425 scr_WriteMessage(jidfrom, buffer, "<== "); |
433 free(buffer); | 426 free(buffer); |
434 top_panel(inputPanel); | 427 top_panel(inputPanel); |
435 update_panels(); | 428 update_panels(); |
436 doupdate(); | 429 doupdate(); |
439 void scr_WriteOutgoingMessage(const char *jidto, const char *text) | 432 void scr_WriteOutgoingMessage(const char *jidto, const char *text) |
440 { | 433 { |
441 scr_WriteMessage(jidto, text, "--> "); | 434 scr_WriteMessage(jidto, text, "--> "); |
442 scr_ShowWindow(jidto); | 435 scr_ShowWindow(jidto); |
443 top_panel(inputPanel); | 436 top_panel(inputPanel); |
444 //refresh(); // XXX ? | |
445 } | 437 } |
446 | 438 |
447 int scr_Getch(void) | 439 int scr_Getch(void) |
448 { | 440 { |
449 int ch; | 441 int ch; |