From 01cae7cc0030e26ce53c5743fc0dccc4aa7bf683 Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 6 Aug 2005 05:03:41 +0000 Subject: Large Terminal Rules New api: *lr family calls are used to pad and fir terminal width. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2996 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/announce.c | 2 +- mbbsd/bbs.c | 18 ++++--- mbbsd/board.c | 17 +++--- mbbsd/cache.c | 2 +- mbbsd/edit.c | 8 +-- mbbsd/mail.c | 6 +-- mbbsd/menu.c | 161 +++++++++++++++++++++++++++++++++++++------------------ mbbsd/merge.c | 2 +- mbbsd/read.c | 10 ++-- mbbsd/screen.c | 40 +++++++++++++- mbbsd/talk.c | 21 +++++--- mbbsd/var.c | 1 - 12 files changed, 201 insertions(+), 87 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/announce.c b/mbbsd/announce.c index b9197343..b8c300bf 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -226,7 +226,7 @@ a_showmenu(const menu_t * pm) { // something in queue prints( ANSI_COLOR(37;44) "¡i¤w¼Ð°O(½Æ»s) %d ­Ó¶µ¥Ø¡j" - ANSI_COLOR(31) "(c)" ANSI_COLOR(30) "¼Ð°O/½Æ»s " + ANSI_COLOR(31;47) "(c)" ANSI_COLOR(30) "¼Ð°O/½Æ»s " ANSI_COLOR(31) "(p)" ANSI_COLOR(30) "¶K¤W/¨ú®ø/­«³]¼Ð°O " ANSI_COLOR(31) "(a)" ANSI_COLOR(30) "ªþ¥[¦Ü¤å³¹«á " // ANSI_COLOR(31;47) " (h)" ANSI_COLOR(30) "»¡©ú " diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 37e8eb8f..0d9269c4 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -159,14 +159,14 @@ set_board(void) /* calculate with other title information */ int l = 0; - snprintf(currBM, sizeof(currBM), "ªO¥D¡G%s", bp->BM); - /* title have +7 leading symbols */ + snprintf(currBM, sizeof(currBM), "ªO¥D:%s", bp->BM); + /* title has +7 leading symbols */ l += strlen(bp->title); if(l >= 7) l -= 7; else l = 0; - l += 12; /* fixed stuff */ + l += 8 + strlen(currboard); /* trailing stuff */ l += strlen(bp->brdname); l = t_columns - l -strlen(currBM); @@ -259,12 +259,18 @@ readtitle(void) listmode_desc[currlistmode]); #ifdef USE_COOLDOWN - if (bp->brdattr & BRD_COOLDOWN && !((currmode & MODE_BOARD) || HasUserPerm(PERM_SYSOP))) - prints(" " ANSI_RESET); + if ( bp->brdattr & BRD_COOLDOWN && + !((currmode & MODE_BOARD) || HasUserPerm(PERM_SYSOP))) + outslr("", 44, ANSI_RESET, 0); else #endif - prints(" ¤H®ð:%-5d " ANSI_RESET, + { + char buf[32]; + sprintf(buf, "¤H®ð:%d ", SHM->bcache[currbid - 1].nuser); + outslr("", 44, buf, -1); + outs(ANSI_RESET); + } } static void diff --git a/mbbsd/board.c b/mbbsd/board.c index d7be9eb6..c5f34290 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -57,7 +57,7 @@ inline int getbid(const boardheader_t *fh) inline boardheader_t *getparent(const boardheader_t *fh) { if(fh->parent>0) - return &bcache[fh->parent-1]; + return getbcache(fh->parent); else return NULL; } @@ -164,7 +164,7 @@ load_uidofgid(const int gid, const int type) currbptr = parent = &bcache[gid - 1]; for (n = 0; n < numboards; ++n) { bid = SHM->bsorted[type][n]+1; - if( bid<=0 || !(bptr = &bcache[bid-1]) + if( bid<=0 || !(bptr = getbcache(bid)) || bptr->brdname[0] == '\0' ) continue; if (bptr->gid == gid) { @@ -491,12 +491,13 @@ show_brdlist(int head, int clsflag, int newflag) "¡X¡X" ANSI_RESET " ¢« ¡X¡Ï" ANSI_RESET); } else if (clsflag) { showtitle("¬ÝªO¦Cªí", BBSName); - prints("[¡ö]¥D¿ï³æ [¡÷]¾\\Ū [¡ô¡õ]¿ï¾Ü [S]±Æ§Ç [/]·j´M " - "[m]¥[¤J©Î²¾¥X§Úªº³Ì·R [h]¨D§U\n" - ANSI_COLOR(7) "%-20s Ãþ§O Âà«H%-30s" - "¤H®ð ªO ¥D " ANSI_RESET, - newflag ? "Á`¼Æ ¥¼Åª ¬Ý ªO" : " ½s¸¹ ¬Ý ªO", - " ¤¤ ¤å ±Ô ­z"); + outs("[¡ö]¥D¿ï³æ [¡÷]¾\\Ū [¡ô¡õ]¿ï¾Ü [S]±Æ§Ç [/]·j´M [m]¥[¤J©Î²¾¥X§Úªº³Ì·R [h]¨D§U\n"); + outs(ANSI_COLOR(7)); + outs( newflag ? + "Á`¼Æ ¥¼Åª ¬Ý ªO " : + " ½s¸¹ ¬Ý ªO "); + outs( " Ãþ§O Âà«H ¤¤ ¤å ±Ô ­z ¤H®ð ªO ¥D"); + outslr("", 72, ANSI_RESET, 0); move(b_lines, 0); brdlist_foot(); } diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 36b9346a..79197183 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -788,7 +788,7 @@ void buildBMcache(int bid) /* bid starts from 1 */ char s[IDLEN * 3 + 3], *ptr; int i, uid; - strlcpy(s, bcache[bid-1].BM, sizeof(s)); + strlcpy(s, getbcache(bid)->BM, sizeof(s)); for( i = 0 ; s[i] != 0 ; ++i ) if( !isalpha((int)s[i]) && !isdigit((int)s[i]) ) s[i] = ' '; diff --git a/mbbsd/edit.c b/mbbsd/edit.c index 05159707..42b104a6 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -405,17 +405,19 @@ edit_msg(void) move(b_lines, 0); clrtoeol(); - prints( ANSI_COLOR(37;44) " ½s¿è¤å³¹ " + outs( ANSI_COLOR(37;44) " ½s¿è¤å³¹ " ANSI_COLOR(31;47) " (^Z/F1)" ANSI_COLOR(30) "»¡©ú " ANSI_COLOR(31;47) "(^P/^G)" ANSI_COLOR(30) "´¡¤J²Å¸¹/¹Ï¤ù " - ANSI_COLOR(31) "(^X/^Q)" ANSI_COLOR(30) "Â÷¶}" - "ùø%s¢x%c%c%c%cùø %3d:%3d " ANSI_RESET, + ANSI_COLOR(31) "(^X/^Q)" ANSI_COLOR(30) "Â÷¶}"); + + prints( "ùø%s¢x%c%c%c%cùø %3d:%3d ", curr_buf->insert_mode ? "´¡¤J" : "¨ú¥N", curr_buf->ansimode ? 'A' : 'a', curr_buf->indent_mode ? 'I' : 'i', curr_buf->phone_mode ? 'P' : 'p', curr_buf->raw_mode ? 'R' : 'r', curr_buf->currln + 1, n + 1); + outslr("", 78, ANSI_RESET, 0); } /** diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 5e0bf175..f51023eb 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -815,7 +815,7 @@ read_new_mail(void * voidfptr, void *optarg) return more_result; } - outmsg(msg_mailer); + outmsglr(MSG_MAILER, MSG_MAILER_LEN, "", 0); switch (igetch()) { case 'r': @@ -1032,7 +1032,7 @@ mail_read(int ent, fileheader_t * fhdr, const char *direct) default: return more_result; } - outmsg(msg_mailer); + outmsglr(MSG_MAILER, MSG_MAILER_LEN, "", 0); switch (igetch()) { case 'r': @@ -1138,7 +1138,7 @@ mail_nooutmail(int ent, fileheader_t * fhdr, const char *direct) { cuser.uflag2 ^= REJ_OUTTAMAIL; passwd_update(usernum, &cuser); - return TITLE_REDRAW; + return FULLUPDATE; } diff --git a/mbbsd/menu.c b/mbbsd/menu.c index 136fe37d..3e26c79e 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -9,67 +9,118 @@ extern char *boardprefix; extern struct utmpfile_t *utmpshm; extern char board_hidden_status; + +static const char *title_tail_msgs[] = { + "¬ÝªO", + "¤åºK", + "¨t¦C", +}; +static const char *title_tail_attrs[] = { + ANSI_COLOR(37), + ANSI_COLOR(32), + ANSI_COLOR(36), +}; +enum { + TITLE_TAIL_BOARD = 0, + TITLE_TAIL_SELECT, + TITLE_TAIL_DIGEST, +}; + void showtitle(const char *title, const char *mid) { - char buf[40], numreg[50]; -#ifndef DEBUG - int nreg; -#endif - int spc = 0, pad, bid; + /* we have to... + * - display title in left, cannot truncate. + * - display mid message, cannot truncate + * - display tail (board info), if possible. + */ + int llen = -1, rlen = -1, mlen = -1, mpos = 0; + int pos = 0; + int tail_type = TITLE_TAIL_BOARD; + const char *mid_attr = ANSI_COLOR(33); + static char lastboard[16] = {0}; + char buf[64]; + + if (currmode & MODE_SELECT) + tail_type = TITLE_TAIL_SELECT; + else if (currmode & MODE_DIGEST) + tail_type = TITLE_TAIL_DIGEST; + + /* check if board was changed. */ + if (strcmp(currboard, lastboard) != 0 && currboard[0]) { + int bid = getbnum(currboard); + if(bid > 0) + { + board_hidden_status = ((getbcache(bid)->brdattr & BRD_HIDE) && + (getbcache(bid)->brdattr & BRD_POSTMASK)); + strncpy(lastboard, currboard, sizeof(lastboard)); + } + } - spc = strlen(mid); - if (title[0] == 0) - title++; + /* next, determine if title was overrided. */ #ifdef DEBUG - else { - snprintf(numreg, sizeof(numreg), - ANSI_COLOR(41;5) " current pid: %6d " TITLE_COLOR, - getpid()); - mid = numreg; - spc = 23; + { + sprintf(buf, " current pid: %6d ", getpid()); + mid = buf; + mid_attr = ANSI_COLOR(41;5); + mlen = strlen(mid); } #else - else if (currutmp->mailalert) { - mid = ANSI_COLOR(41;5) " ¶l®t¨Ó«ö¹aÅo " TITLE_COLOR; - spc = 18; - } else if ( HasUserPerm(PERM_ACCTREG) && - (nreg = dashs((char *)fn_register) / 163) > 100 ) { - snprintf(numreg, sizeof(numreg), - ANSI_COLOR(41;5) " ¦³ %03d ¥¼¼f®Ö " TITLE_COLOR, - nreg); - mid = numreg; - spc = 19; + if (currutmp->mailalert) { + mid = " ¶l®t¨Ó«ö¹aÅo "; + mid_attr = ANSI_COLOR(41;5); + mlen = strlen(mid); + } else if ( HasUserPerm(PERM_ACCTREG) ) { + int nreg = dashs((char *)fn_register) / 163; + if(nreg > 100) + { + sprintf(buf, " ¦³ %03d ¥¼¼f®Ö ", nreg); + mid_attr = ANSI_COLOR(41;5); + mid = buf; + mlen = strlen(mid); + } } #endif - spc = 66 - strlen(title) - spc - strlen(currboard); - if (spc < 0) - spc = 0; - pad = 1 - (spc & 1); - memset(buf, ' ', spc >>= 1); - buf[spc] = '\0'; + /* now, calculate real positioning info */ + if(llen < 0) llen = strlen(title); + if(mlen < 0) mlen = strlen(mid); + mpos = (t_columns - mlen)/2; + /* first, print left. */ clear(); - prints(TITLE_COLOR "¡i%s¡j%s" ANSI_COLOR(33) "%s%s%s%s¡m", - title, buf, mid, buf, " " + pad, - currmode & MODE_SELECT ? ANSI_COLOR(36) "¨t¦C" : - currmode & MODE_DIGEST ? ANSI_COLOR(32) "¤åºK" : ANSI_COLOR(37) "¬ÝªO"); - - if (strcmp(currboard, lastboard)) { /* change board */ - if (currboard[0] != 0 && - (bid = getbnum(currboard)) > 0) { - // XXX: bid starts from 1 - board_hidden_status = ((bcache[bid - 1].brdattr & BRD_HIDE) && - (bcache[bid - 1].brdattr & BRD_POSTMASK)); - strncpy(lastboard, currboard, sizeof(lastboard)); - } + outs(TITLE_COLOR "¡i"); + outs(title); + outs("¡j"); + pos = llen + 4; + /* prepare for mid */ + while(pos < mpos) + outc(' '), pos++; + outs(mid_attr); + outs(mid), pos+=mlen; + outs(TITLE_COLOR); + /* try to locate right */ + rlen = strlen(currboard) + 4 + 4; + if(currboard[0] && pos+rlen <= t_columns) + { + // print right stuff + while(++pos < t_columns-rlen) + outc(' '); + outs(title_tail_attrs[tail_type]); + outs(title_tail_msgs[tail_type]); + outs("¡m"); + if (board_hidden_status) + outs(ANSI_COLOR(32)); + outs(currboard); + outs(title_tail_attrs[tail_type]); + outs("¡n" ANSI_RESET "\n"); + } else { + // just pad it. + while(++pos < t_columns) + outc(' '); + outs(ANSI_RESET "\n"); } - if (board_hidden_status) - outs(ANSI_COLOR(32)); - outs(currboard); - prints(ANSI_COLOR(3%d) "¡n" ANSI_COLOR(0) "\n", currmode & MODE_SELECT ? 6 : - currmode & MODE_DIGEST ? 2 : 7); + } /* °Êµe³B²z */ @@ -88,14 +139,20 @@ show_status(void) i = ptime->tm_wday << 1; snprintf(mystatus, sizeof(mystatus), - ANSI_COLOR(34;46) "[%d/%d ¬P´Á%c%c %d:%02d]" ANSI_COLOR(1;33;45) "%-14s" - ANSI_COLOR(30;47) " ¥Ø«e§{¸Ì¦³" ANSI_COLOR(31) "%d" ANSI_COLOR(30) "¤H, §Ú¬O" ANSI_COLOR(31) "%-12s" - ANSI_COLOR(30) "[¦©¾÷]" ANSI_COLOR(31) "%s" ANSI_COLOR(0) "", + ANSI_COLOR(34;46) "[%d/%d ¬P´Á%c%c %d:%02d]" + ANSI_COLOR(1;33;45) "%-14s" + ANSI_COLOR(30;47) " ¥Ø«e§{¸Ì¦³" ANSI_COLOR(31) + "%d" ANSI_COLOR(30) "¤H, §Ú¬O" ANSI_COLOR(31) "%-12s" + ANSI_COLOR(30) , ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], ptime->tm_hour, ptime->tm_min, currutmp->birth ? "¥Í¤é­n½Ð«È­ò" : SHM->today_is, - SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); + SHM->UTMPnumber, cuser.userid); outmsg(mystatus); + i = strlen(mystatus) - (3*7+25); + sprintf(mystatus, "[¦©¾÷]" ANSI_COLOR(31) "%s " ANSI_RESET, + msgs[currutmp->pager]); + outslr("", i, mystatus, strlen(msgs[currutmp->pager]) + 7); } void diff --git a/mbbsd/merge.c b/mbbsd/merge.c index f8769274..b3b61b84 100644 --- a/mbbsd/merge.c +++ b/mbbsd/merge.c @@ -233,5 +233,5 @@ m_sob_brd(char *bname, char *fromdir) sprintf(buf, "man/boards/%c/%s/.DIR", bname[0], bname); append_record(buf, &fh, sizeof(fh)); sprintf(fromdir, "sob/boards/%s/.DIR", fbname); - vmsg("§Y±N¶×¤J %s ªO¸ê®Æ..«öÁä«á»Ý­n¤@ÂI®É¶¡",fbname); + vmsgf("§Y±N¶×¤J %s ªO¸ê®Æ..«öÁä«á»Ý­n¤@ÂI®É¶¡",fbname); } diff --git a/mbbsd/read.c b/mbbsd/read.c index 79b09708..a9964e65 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -1014,9 +1014,13 @@ i_read(int cmdmode, const char *direct, void (*dotitle) (), for( i = 0; i < entries ; i++ ) (*doentry) (locmem->top_ln + i, &headers[i]); case READ_REDRAW: - outmsg(curredit & EDIT_ITEM ? - ANSI_COLOR(44) " ¨p¤H¦¬Âà " ANSI_COLOR(30;47) " Ä~Äò? " ANSI_RESET : - curredit & EDIT_MAIL ? msg_mailer : MSG_POSTER); + if(curredit & EDIT_ITEM) + outmsglr(ANSI_COLOR(44) " ¨p¤H¦¬Âà " ANSI_COLOR(30;47), 10, + " Ä~Äò? ", 7); + else if (curredit & EDIT_MAIL) + outmsglr(MSG_MAILER, MSG_MAILER_LEN, "", 0); + else + outmsglr(MSG_POSTER, MSG_POSTER_LEN, "", 0); break; case TITLE_REDRAW: (*dotitle) (); diff --git a/mbbsd/screen.c b/mbbsd/screen.c index 6613085a..b9b57b90 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -372,6 +372,35 @@ outs_n(const char *str, int n) outc(*str++); } } +// +void +outslr(const char *left, int leftlen, const char *right, int rightlen) +{ + if (left == NULL) + left = ""; + if (right == NULL) + right = ""; + if(*left && leftlen < 0) + leftlen = strlen(left); + if(*right && rightlen < 0) + rightlen = strlen(right); + // now calculate padding + rightlen = t_columns - leftlen - rightlen; + outs(left); + + // ignore right msg if we need to. + if(rightlen >= 0) + { + while(--rightlen > 0) + outc(' '); + outs(right); + } else { + rightlen = t_columns - leftlen; + while(--rightlen > 0) + outc(' '); + } +} + /* Jaky */ void @@ -393,6 +422,15 @@ outmsg(const char *msg) outs(msg); } +void +outmsglr(const char *msg, int llen, const char *rmsg, int rlen) +{ + move(b_lines - msg_occupied, 0); + clrtoeol(); + outslr(msg, llen, rmsg, rlen); + outs(ANSI_RESET ANSI_CLRTOEND); +} + void prints(const char *fmt,...) { @@ -518,5 +556,5 @@ void screen_restore(int len, screenline_t *bp, const void *buf) } } -/* vim:tw=4 +/* vim:sw=4 */ diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 9bcac216..4b6712c6 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -1902,7 +1902,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, ( /* §tªO¤Í, ¦n¤Í°Ï³Ì¦h¥u·|¦³ (friendtotal + ªO¤Í) ­Ó*/ (currutmp->brc_id && which < (friendtotal + 1 + - bcache[currutmp->brc_id-1].nuser)) || + getbcache(currutmp->brc_id)->nuser)) || /* ¤£§tªO¤Í, ³Ì¦h¥u·|¦³ friendtotal­Ó */ (!currutmp->brc_id && which < friendtotal + 1) @@ -1914,7 +1914,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, if (pickup_way == 0 && currutmp->brc_id != 0 #ifdef USE_COOLDOWN - && !(bcache[currutmp->brc_id-1].brdattr & BRD_COOLDOWN) + && !(getbcache(currutmp->brc_id)->brdattr & BRD_COOLDOWN) #endif ){ /* TODO ¥u»Ý­n which+nPickups-*nfriend ­ÓªO¤Í, ¤£¤@©w­n¾ã­Ó±½¤@¹M */ @@ -1997,10 +1997,17 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, show_pid ? " PID" : "¤ß±¡ µo§b" ); move(b_lines, 0); - outs(ANSI_COLOR(31;47) "(TAB/f)" ANSI_COLOR(30) "±Æ§Ç/¦n¤Í " ANSI_COLOR(31) "(t)" ANSI_COLOR(30) "²á¤Ñ " - ANSI_COLOR(31) "(a/d/o)" ANSI_COLOR(30) "¥æ¤Í " ANSI_COLOR(31) "(q)" ANSI_COLOR(30) "¬d¸ß " - ANSI_COLOR(31) "(w)" ANSI_COLOR(30) "¤ô²y " ANSI_COLOR(31) "(m)" ANSI_COLOR(30) "±H«H " ANSI_COLOR(31) "(h)" - ANSI_COLOR(30) "½u¤W»²§U " ANSI_RESET); + outslr( + ANSI_COLOR(34;46) " ¥ð¶¢²á¤Ñ " + ANSI_COLOR(31;47) " (TAB/f)" ANSI_COLOR(30) "±Æ§Ç/¦n¤Í " + ANSI_COLOR(31) "(t)" ANSI_COLOR(30) "²á¤Ñ " + ANSI_COLOR(31) "(a/d/o)" ANSI_COLOR(30) "¥æ¤Í " + ANSI_COLOR(31) "(q)" ANSI_COLOR(30) "¬d¸ß " + ANSI_COLOR(31) "(w)" ANSI_COLOR(30) "¤ô²y " + ANSI_COLOR(31) "(m)" ANSI_COLOR(30) "±H«H ", + 80-8, + ANSI_COLOR(31) "(h)" ANSI_COLOR(30) "»¡©ú " ANSI_RESET, + 8); } move(1, 0); prints(" ±Æ§Ç¡G[%s] ¤W¯¸¤H¼Æ¡G%-4d" ANSI_COLOR(1;32) "§ÚªºªB¤Í¡G%-3d" @@ -2080,7 +2087,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, /* board or mode */ #if defined(SHOWBOARD) && defined(DEBUG) show_board ? (uentp->brc_id == 0 ? "" : - bcache[uentp->brc_id - 1].brdname) : + getbcache(uentp->brc_id)->brdname) : #endif /* %-13.13s */ modestring(uentp, 0), diff --git a/mbbsd/var.c b/mbbsd/var.c index 9c917204..2cf0ff0f 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -146,7 +146,6 @@ char * const loginview_file[NUMVIEWFILE][2] = { /* message */ char * const msg_seperator = MSG_SEPERATOR; -char * const msg_mailer = MSG_MAILER; char * const msg_shortulist = MSG_SHORTULIST; char * const msg_cancel = MSG_CANCEL; -- cgit v1.2.3