diff options
-rw-r--r-- | pttbbs/include/vtuikit.h | 12 | ||||
-rw-r--r-- | pttbbs/mbbsd/vtuikit.c | 83 |
2 files changed, 95 insertions, 0 deletions
diff --git a/pttbbs/include/vtuikit.h b/pttbbs/include/vtuikit.h index 2c6c8b22..7fd83822 100644 --- a/pttbbs/include/vtuikit.h +++ b/pttbbs/include/vtuikit.h @@ -29,6 +29,11 @@ #define VCLR_MSG ANSI_COLOR(1;36;44) #define VCLR_PAUSE_PAD ANSI_COLOR(1;34;44) #define VCLR_PAUSE ANSI_COLOR(1;37;44) +#define VCLR_QPREF_TITLE ANSI_COLOR(0;30;47) +#define VCLR_QPREF_PROMPT ANSI_COLOR(0) +#define VCLR_QPREF_ENTRY_KEY ANSI_COLOR(0;1;31) +#define VCLR_QPREF_ENTRY_TEXT ANSI_COLOR(0) +#define VCLR_QPREF_ENTRY_ACTIVE ANSI_COLOR(0;1;36) #define VCLR_INPUT_FIELD ANSI_COLOR(0;7) @@ -39,6 +44,10 @@ #define VMSG_HDR_PREFIX "【 " #define VMSG_HDR_POSTFIX " 】" +#define VMSG_QPREF_TITLE "請設定下列選項" +#define VMSG_QPREF_ENTRY "可使用選項: " +#define VMSG_QPREF_PROMPT "請按數字或方向鍵調整,或其它任意鍵結束" + // CONSTANT DEFINITION ------------------------------------------------- #define VCOL_MAXW (INT16_MAX) #define VCOL_MAXPRI (INT16_MAX) @@ -154,6 +163,9 @@ void vs_hdr2bar (const char *left, const char *right); void vs_hdr2barf(const char *fmt, ...); void vs_footer (const char *caption, const char *prompt); +int vs_quick_pref(int default_value, const char *title, const char *entry, + const char *options, const char *prompt); + void vs_rectangle_simple(int l, int t, int r, int b); // draw a single line rectangle, not filling inside interior void vs_multi_T_table_simple( const char ***t_tables, int n_t_tables, diff --git a/pttbbs/mbbsd/vtuikit.c b/pttbbs/mbbsd/vtuikit.c index 2820ee47..2ee250db 100644 --- a/pttbbs/mbbsd/vtuikit.c +++ b/pttbbs/mbbsd/vtuikit.c @@ -930,6 +930,89 @@ vs_multi_T_table_simple( while (incomplete); } +// pmore_QuickRawModePref style pref setter, renders +// - title - +// - entry: options (separated by TAB) - +// - prompt - +int +vs_quick_pref(int default_value, const char *title, const char *entry, + const char *options, const char *prompt) { + int ystart = b_lines -2; + int cOptions = 0; + int index = default_value, k; + const char *opt; + +#ifdef HAVE_GRAYOUT + grayout(0, ystart-1, GRAYOUT_DARK); +#endif // HAVE_GRAYOUT + + // adjust params + if (!title) + title = VMSG_QPREF_TITLE; + if (!entry) + entry = VMSG_QPREF_ENTRY; + if (!prompt) + prompt = VMSG_QPREF_PROMPT; + assert(options && *options); + + while (1) + { + move(ystart, 0); + clrtobot(); + outs(VCLR_QPREF_TITLE); + vbarf("%s", title); // in case title has TAB for LR display. + move(ystart + 1, 0); + outs(VCLR_QPREF_PROMPT); + outs(entry); + cOptions = 0; + + // list options + opt = options; + while (*opt) { + const char *ptab = strchr(opt, '\t'); + int slen = ptab ? (ptab - opt) : strlen(opt); + outs(VCLR_QPREF_ENTRY_KEY); + prints("%d", cOptions + 1); + if (cOptions == index) { + outs(VCLR_QPREF_ENTRY_ACTIVE); + outc('*'); + } else { + outs(VCLR_QPREF_ENTRY_TEXT); + outc(' '); + } + outns(opt, slen); + outs(ANSI_RESET); + outc(' '); + opt += slen; + cOptions++; + if (*opt) + opt++; + } + + k = vmsg(prompt); + if (isascii(k) && isdigit(k)) { + k = k - '1'; + if (k >= 0 && k < cOptions) { + index = k; + break; + } + } else if (k == KEY_LEFT) { + if (index > 0) { + index--; + continue; + } + } else if (k == KEY_RIGHT) { + if (index + 1 < cOptions) { + index++; + continue; + } + } else { + break; + } + } + return index; +} + //////////////////////////////////////////////////////////////////////// // DBCS Aware Helpers //////////////////////////////////////////////////////////////////////// |