diff options
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/bbs.c | 21 | ||||
-rw-r--r-- | mbbsd/board.c | 6 | ||||
-rw-r--r-- | mbbsd/mail.c | 36 | ||||
-rw-r--r-- | mbbsd/menu.c | 28 | ||||
-rw-r--r-- | mbbsd/stuff.c | 2 | ||||
-rw-r--r-- | mbbsd/talk.c | 23 | ||||
-rw-r--r-- | mbbsd/visio.c | 51 |
7 files changed, 94 insertions, 73 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index f7e3d49f..5baf189e 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -402,9 +402,11 @@ readtitle(void) { boardheader_t *bp; char *brd_title; + char buf[32]; assert(0<=currbid-1 && currbid-1<MAX_BOARD); bp = getbcache(currbid); + if(bp->bvote != 2 && bp->bvote) brd_title = "本看板進行投票中"; else @@ -412,23 +414,18 @@ readtitle(void) showtitle(currBM, brd_title); outs("[←]離開 [→]閱\讀 [^P]發表文章 [d]刪除 [z]精華區 [i]看板資訊/設定 [h]說明\n"); - prints(ANSI_COLOR(7) " 編號 %s 作 者 文 章 標 題", - IS_LISTING_MONEY ? listmode_desc[LISTMODE_MONEY] : listmode_desc[currlistmode]); + buf[0] = 0; #ifdef USE_COOLDOWN - if ( bp->brdattr & BRD_COOLDOWN && - !((currmode & MODE_BOARD) || HasUserPerm(PERM_SYSOP))) - outslr("", 44, ANSI_RESET, 0); - else + if (!(bp->brdattr & BRD_COOLDOWN)) #endif { - char buf[32]; - assert(0<=currbid-1 && currbid-1<MAX_BOARD); - sprintf(buf, "人氣:%d ", - SHM->bcache[currbid - 1].nuser); - outslr("", 44, buf, -1); - outs(ANSI_RESET); + snprintf(buf, sizeof(buf), "人氣:%d ", SHM->bcache[currbid - 1].nuser); } + + vbarf(ANSI_COLOR(7) " 編號 %s 作 者 文 章 標 題\t%s ", + IS_LISTING_MONEY ? listmode_desc[LISTMODE_MONEY] : listmode_desc[currlistmode], + buf); } static void diff --git a/mbbsd/board.c b/mbbsd/board.c index 1f6c34de..d6816ff0 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -1108,7 +1108,6 @@ show_brdlist(int head, int clsflag, int newflag) showtitle("看板列表", BBSName); // [m]加入或移出我的最愛 outs("[←][q]主選單 [→][r]閱\讀 [↑↓]選擇 [PgUp][PgDn]翻頁 [S]排序 [/]搜尋 [h]求助\n"); - outs(ANSI_COLOR(7)); // boards in Ptt series are very, very large. // let's create more space for board numbers, @@ -1116,9 +1115,8 @@ show_brdlist(int head, int clsflag, int newflag) // // newflag is not so different now because we use all 5 digits. - outs( newflag ? " 總數" : " 編號"); - outs(" 看 板 類別 轉信 中 文 敘 述 人氣 板 主"); - outslr("", 74, ANSI_RESET, 0); + vbarf(ANSI_COLOR(7) " %s 看 板 類別 轉信 中 文 敘 述 人氣 板 主", + newflag ? "總數" : "編號"); move(b_lines, 0); brdlist_foot(); } diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 2f3ff920..1b05e801 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -984,33 +984,23 @@ static void mailtitle(void) { char buf[STRLEN]; - int msglen = 0; - - showtitle("郵件選單", BBSName); - prints("[←]離開[↑↓]選擇[→]閱\讀信件 [X]轉錄看板[F]轉寄站外 " - " [O]站外信:%s [h]求助\n" - ANSI_COLOR(7) " 編號 %s 作 者 信 件 標 題" - "", - REJECT_OUTTAMAIL ? ANSI_COLOR(31) "關" ANSI_RESET : "開", - (showmail_mode == SHOWMAIL_SUM) ? "大 小":"日 期"); - - /* 43 columns in length, used later. */ - buf[0] = 0; if (mailsumlimit) { - /* warning: snprintf returns length "if not limited". - * however if this case, they should be the same. */ - - msglen = snprintf(buf, sizeof(buf), - ANSI_COLOR(32) - " (容量:%d/%dk %d/%d篇) ", - mailsum, mailsumlimit, - mailkeep, mailmaxkeep); - msglen -= strlen(ANSI_COLOR(32)); + snprintf(buf, sizeof(buf), ANSI_COLOR(32) "(容量:%d/%dk %d/%d篇)", + mailsum, mailsumlimit, + mailkeep, mailmaxkeep); + } else { + snprintf(buf, sizeof(buf), ANSI_COLOR(32) "(大小:%dk %d篇)", + mailsum, mailkeep); } - outslr("", 44, buf, msglen); - outs(ANSI_RESET); + + showtitle("郵件選單", BBSName); + outs("[←]離開[↑↓]選擇[→]閱\讀信件 [X]轉錄看板[F]轉寄站外 "); + prints(" [O]站外信:%s [h]求助\n" , REJECT_OUTTAMAIL ? ANSI_COLOR(31) "關" ANSI_RESET : "開"); + vbarf(ANSI_COLOR(7) " 編號 %s 作 者 信 件 標 題\t%s ", + (showmail_mode == SHOWMAIL_SUM) ? "大 小":"日 期", + buf); } static void diff --git a/mbbsd/menu.c b/mbbsd/menu.c index 0b335353..0434d6f9 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -136,27 +136,21 @@ show_status(void) { int i; struct tm *ptime = localtime4(&now); - char mystatus[160]; char *myweek = "天一二三四五六"; const char *msgs[] = {"關閉", "打開", "拔掉", "防水", "好友"}; i = ptime->tm_wday << 1; - snprintf(mystatus, sizeof(mystatus), - ANSI_COLOR(34;46) "[%d/%d 星期%c%c %d:%02d]" - ANSI_COLOR(1;33;45) "%-14s" - ANSI_COLOR(30;47) " 線上" ANSI_COLOR(31) - "%d" ANSI_COLOR(30) "人, 我是" ANSI_COLOR(31) "%s" - ANSI_COLOR(30) , - ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], - ptime->tm_hour, ptime->tm_min, currutmp->birth ? - "生日要請客唷" : SHM->today_is, - SHM->UTMPnumber, cuser.userid); - outmsg(mystatus); - i = strlen(mystatus) - (3*7+25); // 3 = ANSI_COLOR, 25 = stuff inside - sprintf(mystatus, "[扣機]" ANSI_COLOR(31) "%s ", - msgs[currutmp->pager]); - outslr("", i, mystatus, strlen(msgs[currutmp->pager]) + 7); - outs(ANSI_RESET); + move(b_lines, 0); + vbarf(ANSI_COLOR(34;46) "[%d/%d 星期%c%c %d:%02d]" + ANSI_COLOR(1;33;45) "%-14s" + ANSI_COLOR(30;47) " 線上" ANSI_COLOR(31) + "%d" ANSI_COLOR(30) "人, 我是" ANSI_COLOR(31) "%s" + ANSI_COLOR(30) "\t[扣機]" ANSI_COLOR(31) "%s ", + ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], + ptime->tm_hour, ptime->tm_min, currutmp->birth ? + "生日要請客唷" : SHM->today_is, + SHM->UTMPnumber, cuser.userid, + msgs[currutmp->pager]); } /* diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 3b79de9a..c9109601 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -290,7 +290,7 @@ vmsg(const char *msg) int vmsgf(const char *fmt,...) { - char msg[256]; + char msg[512]; va_list ap; va_start(ap, fmt); vsnprintf(msg, sizeof(msg), fmt, ap); diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 72cc581e..3cf50c71 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -2293,22 +2293,17 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, { // modes should match ANGELPAUSE* static const char *modestr[ANGELPAUSE_MODES] = { - ANSI_COLOR(1;30;47) "[神諭呼叫器]" ANSI_COLOR(0;30;47) - " 開放 " ANSI_RESET, - ANSI_COLOR(1;30;47) "[神諭呼叫器]" ANSI_COLOR(0;32;47) - " 停收 " ANSI_RESET, - ANSI_COLOR(1;30;47) "[神諭呼叫器]" ANSI_COLOR(0;31;47) - " 關閉 " ANSI_RESET, + ANSI_COLOR(0;30;47) "開放", + ANSI_COLOR(0;32;47) "停收", + ANSI_COLOR(0;31;47) "關閉", }; // reduced version - outslr( - ANSI_COLOR(34;46) " 休閒聊天 " - ANSI_COLOR(31;47) " (TAB/f)" ANSI_COLOR(30) "排序/好友 " - ANSI_COLOR(31) "(p)" ANSI_COLOR(30) "一般呼叫器 " - ANSI_COLOR(31) "(^P)" ANSI_COLOR(30) "神諭呼叫器 ", - 57, - modestr[currutmp->angelpause % ANGELPAUSE_MODES], - 18); + vbarf( ANSI_COLOR(34;46) " 休閒聊天 " + ANSI_COLOR(31;47) " (TAB/f)" ANSI_COLOR(30) "排序/好友 " + ANSI_COLOR(31) "(p)" ANSI_COLOR(30) "一般呼叫器 " + ANSI_COLOR(31) "(^P)" ANSI_COLOR(30) "神諭呼叫器\t" + ANSI_COLOR(1;30;47) "[神諭呼叫器] %s ", + modestr[currutmp->angelpause % ANGELPAUSE_MODES]); } else #endif vfooter(" 休閒聊天 ", diff --git a/mbbsd/visio.c b/mbbsd/visio.c index b12b037b..789b6e60 100644 --- a/mbbsd/visio.c +++ b/mbbsd/visio.c @@ -36,13 +36,60 @@ nblank(int n) } // ---- HIGH LEVEL API ----------------------------------------------- + +/** + * vbarf(s, ...): 格式化輸出左右對齊的字串 (MAX_COL) + * + * s 裡 \t 後的內容會對齊右端。 + */ void -vfprints() +vbarf(const char *s, ...) { + char msg[512], *s2; + va_list ap; + va_start(ap, s); + vsnprintf(msg, sizeof(msg), s, ap); + va_end(ap); + + s2 = strchr(msg, '\t'); + if (s2) *s2++ = 0; + else s2 = ""; + + return vbar(msg, s2); } /** - * 在最底部印出 caption msg 的形式 + * vbar(l, r): 左右對齊畫滿螢幕 (MAX_COL) + * + * 注意 r 的後面不會補空白。 + * l r 都可以含 ANSI 控制碼。 + * 注意: 目前的實作自動認定游標已在行開頭。 + */ +void +vbar(const char *l, const char *r) +{ + // TODO strlen_noansi 跑兩次... 其實 l 可以邊 output 邊算。 + int szl = strlen_noansi(l), + szr = strlen_noansi(r); + // assume we are already in (y, 0) + clrtoeol(); + outs(l); + szl = MAX_COL - szl; + if (szl > szr) + { + nblank(szl - szr); + szl = szr; + } + if (szl == szr) + outs(r); + else if (szl > 0) + nblank(szl); + outs(ANSI_RESET); +} + +/** + * vfooter(caption, msg): 在螢幕底部印出格式化的 caption msg + * * msg 中若有 () 則會變色, \t 後的文字會靠右。 * 最後面會自動留一個空白 (以避免自動偵測中文字的問題)。 */ |