From c78d877d45496115e90c3584b063fd2bc72303b9 Mon Sep 17 00:00:00 2001 From: piaip Date: Mon, 28 Sep 2009 17:59:20 +0000 Subject: * refine kbd stack and move to common/bbs * rename visio to vtuikit git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4888 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/bbs.h | 2 +- include/common.h | 1 - include/visio.h | 153 ----------------------------------------------------- include/vtkbd.h | 8 ++- include/vtuikit.h | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 156 deletions(-) delete mode 100644 include/visio.h create mode 100644 include/vtuikit.h (limited to 'include') diff --git a/include/bbs.h b/include/bbs.h index d16d5b02..7892f646 100644 --- a/include/bbs.h +++ b/include/bbs.h @@ -44,7 +44,7 @@ extern "C" { #include "ansi.h" #include "vtkbd.h" -#include "visio.h" +#include "vtuikit.h" #include "statistic.h" #include "uflags.h" #include "pttstruct.h" diff --git a/include/common.h b/include/common.h index a2829047..e584cd54 100644 --- a/include/common.h +++ b/include/common.h @@ -155,7 +155,6 @@ #define ST_REJECT (IRH | HRM) #define QCAST int (*)(const void *, const void *) -#define Ctrl(c) (c & 037) #define chartoupper(c) ((c >= 'a' && c <= 'z') ? c+'A'-'a' : c) #define LEN_AUTHOR1 5 diff --git a/include/visio.h b/include/visio.h deleted file mode 100644 index f2879ce6..00000000 --- a/include/visio.h +++ /dev/null @@ -1,153 +0,0 @@ -// $Id$ -#ifndef _VISIO_H -#define _VISIO_H - -/* - * visio.h - * piaip's new implementation of visio - * - * see visio.c for license, usage, and introduction. - */ - -#include "bbs.h" -#include "ansi.h" // we need it. -#include - -// THEME DEFINITION ---------------------------------------------------- -#define VCLR_HEADER ANSI_COLOR(1;37;46) // was: TITLE_COLOR -#define VCLR_HEADER_MID ANSI_COLOR(1;33;46) -#define VCLR_HEADER_RIGHT ANSI_COLOR(1;37;46) -#define VCLR_HDR ANSI_COLOR(1;37;46) -#define VCLR_FOOTER_CAPTION ANSI_COLOR(0;34;46) -#define VCLR_FOOTER ANSI_COLOR(0;30;47) -#define VCLR_FOOTER_QUOTE ANSI_COLOR(0;31;47) -#define VCLR_ZA_CAPTION ANSI_COLOR(1;37;42) -#define VCLR_MSG_FLOAT ANSI_COLOR(1;33;46) -#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_INPUT_FIELD ANSI_COLOR(0;7) - -#define VMSG_PAUSE " 請按任意鍵繼續 " -#define VMSG_PAUSE_PAD "▄" -#define VMSG_MSG_FLOAT " [按任意鍵繼續]" -#define VMSG_MSG_PREFIX " ◆ " -#define VMSG_HDR_PREFIX "【 " -#define VMSG_HDR_POSTFIX " 】" - -// CONSTANT DEFINITION ------------------------------------------------- -#define VCOL_MAXW (INT16_MAX) -#define VCOL_MAXPRI (INT16_MAX) - -#define VFILL_DEFAULT (0x00) -// #define VFILL_NO_ANSI VFILL_DEFAULT -#define VFILL_HAS_ANSI (0x01) -// #define VVILL_LEFT_ALIGN VFILL_DEFAULT -#define VFILL_RIGHT_ALIGN (0x02) -// #define VFILL_HAS_BORDER VFILL_DEFAULT -#define VFILL_NO_BORDER (0x08) - -#define VGET_DEFAULT (0x00) -// #define VGET_DOECHO (VGET_DEFAULT) -#define VGET_NOECHO (0x01) -#define VGET_LOWERCASE (0x02) -#define VGET_DIGITS (0x04) -#define VGET_TRANSPARENT (0x08) -#define VGET_ASCII_ONLY (0x10) -#define VGET_PASSWORD (VGET_NOECHO | VGET_ASCII_ONLY) - -// DATATYPE DEFINITION ------------------------------------------------- -typedef void * VREFSCR; -typedef long VREFCUR; - -typedef short VCOLW; -typedef short VCOLPRI; - -typedef struct VCOL { - char *attr; // default attribute - VCOLW minw; // minimal width - VCOLW maxw; // max width - VCOLPRI pri; // priority (higher expands first) - - struct { - char has_ansi; // field data have ANSI escapes - char right_align; // align output to right side - char usewhole; // draw entire column and prevent borders - } flags; - -} VCOL; - -#define VGETCB_NONE (0) // do nothing -#define VGETCB_NEXT (1) // skip to next event loop -#define VGETCB_END (2) // finish input -#define VGETCB_ABORT (3) // clear buffer and finish - -typedef struct { - char *buf; - const int len; // callbacks should not change this. - int icurr; // cursor position - int iend; // buffer tail (= strlen(buf)) -} VGET_RUNTIME; - -typedef int (*VGET_FCALLBACK)(int key, VGET_RUNTIME *prt, void *instance); -typedef struct { - VGET_FCALLBACK peek; // called immediately after key hit - VGET_FCALLBACK data; // called before inserting character data - VGET_FCALLBACK post; // called after every data inserted into buffer. -} VGET_CALLBACKS; - -// API DEFINITION ---------------------------------------------------- - -// curses flavor -void prints(const char *fmt, ...) GCC_CHECK_FORMAT(1,2); -void mvprints(int y, int x, const char *fmt, ...) GCC_CHECK_FORMAT(3,4); -void mvouts(int y, int x, const char *str); - -// input history -int InputHistoryAdd (const char *s); -int InputHistoryExists (const char *s); -void InputHistoryPrev (char *s, int sz); -void InputHistoryNext (char *s, int sz); - -// v*: primitive rendering -void vpad (int n, const char *pattern); /// pad n fields by pattern - int vgety (void); /// return cursor position (y) -void vfill (int n, int flags, const char *s); /// fill n-width space with s -void vfillf (int n, int flags, const char *s, ...) GCC_CHECK_FORMAT(3,4); /// formatted version of vfill -void vbarlr (const char *l, const char *r); /// draw a left-right expanded bar with (l,r) -void vbarf (const char *s, ...) GCC_CHECK_FORMAT(1,2); /// vbarlr with formatted input (\t splits (l,r) -void vshowmsg(const char *msg); /// draw standard pause/message - -// v*: input widgets -// int vans(char *prompt); // prompt at bottom and return y/n in lower case. - int vmsg (const char *msg); /// draw standard pause/message and return input - int vmsgf (const char *fmt,...) GCC_CHECK_FORMAT(1,2); /// formatted input of vmsg - int vans (const char *msg); /// prompt and return (lowercase) single byte input - int vansf (const char *fmt,...) GCC_CHECK_FORMAT(1,2); /// formatted input of vans - -// vget: (y, x, ...) -int vgets (char *buf, int len, int flags); /// input with edit box control -int vgetstr (char *buf, int len, int flags, const char *str);/// input with default value -int vget (int y, int x, const char *prompt, char *buf, int len, int mode); -int vgetstring(char *_buf, int len, int flags, const char *defstr, const VGET_CALLBACKS *pcbs, void *instance); - -// vs_*: formatted and themed virtual screen layout -// you cannot use ANSI escapes in these APIs. -void vs_header (const char *title, const char *mid, const char *right); // vs_head, showtitle -void vs_hdr (const char *title); // vs_bar, stand_title -void vs_footer (const char *caption, const char *prompt); - -void vs_rectangle_simple(int l, int t, int r, int b); // draw a single line rectangle, not filling inside interior - -// columned output -void vs_cols_layout (const VCOL* cols, VCOLW *ws, int n); /// calculate VCOL to fit current screen in ws -void vs_cols (const VCOL* cols, const VCOLW *ws, int n, ...); - -// VREF: save and storing temporary objects (restore will also free object). -VREFSCR vscr_save (void); -void vscr_restore(VREFSCR); -VREFCUR vcur_save (void); -void vcur_restore(VREFCUR); - -#endif // _VISIO_H diff --git a/include/vtkbd.h b/include/vtkbd.h index f1e998c8..609787d4 100644 --- a/include/vtkbd.h +++ b/include/vtkbd.h @@ -25,6 +25,8 @@ #ifndef _VTKBD_H #define _VTKBD_H +#include + /* context definition */ typedef struct { int state; @@ -32,7 +34,11 @@ typedef struct { } VtkbdCtx; /* vtkbd API */ -int vtkbd_process(int c, VtkbdCtx *ctx); +int vtkbd_process(int c, VtkbdCtx *ctx); +ssize_t vtkbd_ignore_dbcs_evil_repeats(const unsigned char *buf, ssize_t len); + +/* key code macro */ +#define Ctrl(c) (c & 0x1F) /* common ASCII compatible keys definition */ #define KEY_TAB 9 diff --git a/include/vtuikit.h b/include/vtuikit.h new file mode 100644 index 00000000..09257345 --- /dev/null +++ b/include/vtuikit.h @@ -0,0 +1,154 @@ +// $Id$ +#ifndef _VISIO_H +#define _VISIO_H + +/* + * vtuikit.h + * piaip's new implementation of vtuikit + * + * see vtuikit.c for license, usage, and introduction. + */ + +#include "bbs.h" +#include "ansi.h" // we need it. +#include "vtkbd.h" // we usually use it +#include + +// THEME DEFINITION ---------------------------------------------------- +#define VCLR_HEADER ANSI_COLOR(1;37;46) // was: TITLE_COLOR +#define VCLR_HEADER_MID ANSI_COLOR(1;33;46) +#define VCLR_HEADER_RIGHT ANSI_COLOR(1;37;46) +#define VCLR_HDR ANSI_COLOR(1;37;46) +#define VCLR_FOOTER_CAPTION ANSI_COLOR(0;34;46) +#define VCLR_FOOTER ANSI_COLOR(0;30;47) +#define VCLR_FOOTER_QUOTE ANSI_COLOR(0;31;47) +#define VCLR_ZA_CAPTION ANSI_COLOR(1;37;42) +#define VCLR_MSG_FLOAT ANSI_COLOR(1;33;46) +#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_INPUT_FIELD ANSI_COLOR(0;7) + +#define VMSG_PAUSE " 請按任意鍵繼續 " +#define VMSG_PAUSE_PAD "▄" +#define VMSG_MSG_FLOAT " [按任意鍵繼續]" +#define VMSG_MSG_PREFIX " ◆ " +#define VMSG_HDR_PREFIX "【 " +#define VMSG_HDR_POSTFIX " 】" + +// CONSTANT DEFINITION ------------------------------------------------- +#define VCOL_MAXW (INT16_MAX) +#define VCOL_MAXPRI (INT16_MAX) + +#define VFILL_DEFAULT (0x00) +// #define VFILL_NO_ANSI VFILL_DEFAULT +#define VFILL_HAS_ANSI (0x01) +// #define VVILL_LEFT_ALIGN VFILL_DEFAULT +#define VFILL_RIGHT_ALIGN (0x02) +// #define VFILL_HAS_BORDER VFILL_DEFAULT +#define VFILL_NO_BORDER (0x08) + +#define VGET_DEFAULT (0x00) +// #define VGET_DOECHO (VGET_DEFAULT) +#define VGET_NOECHO (0x01) +#define VGET_LOWERCASE (0x02) +#define VGET_DIGITS (0x04) +#define VGET_TRANSPARENT (0x08) +#define VGET_ASCII_ONLY (0x10) +#define VGET_PASSWORD (VGET_NOECHO | VGET_ASCII_ONLY) + +// DATATYPE DEFINITION ------------------------------------------------- +typedef void * VREFSCR; +typedef long VREFCUR; + +typedef short VCOLW; +typedef short VCOLPRI; + +typedef struct VCOL { + char *attr; // default attribute + VCOLW minw; // minimal width + VCOLW maxw; // max width + VCOLPRI pri; // priority (higher expands first) + + struct { + char has_ansi; // field data have ANSI escapes + char right_align; // align output to right side + char usewhole; // draw entire column and prevent borders + } flags; + +} VCOL; + +#define VGETCB_NONE (0) // do nothing +#define VGETCB_NEXT (1) // skip to next event loop +#define VGETCB_END (2) // finish input +#define VGETCB_ABORT (3) // clear buffer and finish + +typedef struct { + char *buf; + const int len; // callbacks should not change this. + int icurr; // cursor position + int iend; // buffer tail (= strlen(buf)) +} VGET_RUNTIME; + +typedef int (*VGET_FCALLBACK)(int key, VGET_RUNTIME *prt, void *instance); +typedef struct { + VGET_FCALLBACK peek; // called immediately after key hit + VGET_FCALLBACK data; // called before inserting character data + VGET_FCALLBACK post; // called after every data inserted into buffer. +} VGET_CALLBACKS; + +// API DEFINITION ---------------------------------------------------- + +// curses flavor +void prints(const char *fmt, ...) GCC_CHECK_FORMAT(1,2); +void mvprints(int y, int x, const char *fmt, ...) GCC_CHECK_FORMAT(3,4); +void mvouts(int y, int x, const char *str); + +// input history +int InputHistoryAdd (const char *s); +int InputHistoryExists (const char *s); +void InputHistoryPrev (char *s, int sz); +void InputHistoryNext (char *s, int sz); + +// v*: primitive rendering +void vpad (int n, const char *pattern); /// pad n fields by pattern + int vgety (void); /// return cursor position (y) +void vfill (int n, int flags, const char *s); /// fill n-width space with s +void vfillf (int n, int flags, const char *s, ...) GCC_CHECK_FORMAT(3,4); /// formatted version of vfill +void vbarlr (const char *l, const char *r); /// draw a left-right expanded bar with (l,r) +void vbarf (const char *s, ...) GCC_CHECK_FORMAT(1,2); /// vbarlr with formatted input (\t splits (l,r) +void vshowmsg(const char *msg); /// draw standard pause/message + +// v*: input widgets +// int vans(char *prompt); // prompt at bottom and return y/n in lower case. + int vmsg (const char *msg); /// draw standard pause/message and return input + int vmsgf (const char *fmt,...) GCC_CHECK_FORMAT(1,2); /// formatted input of vmsg + int vans (const char *msg); /// prompt and return (lowercase) single byte input + int vansf (const char *fmt,...) GCC_CHECK_FORMAT(1,2); /// formatted input of vans + +// vget: (y, x, ...) +int vgets (char *buf, int len, int flags); /// input with edit box control +int vgetstr (char *buf, int len, int flags, const char *str);/// input with default value +int vget (int y, int x, const char *prompt, char *buf, int len, int mode); +int vgetstring(char *_buf, int len, int flags, const char *defstr, const VGET_CALLBACKS *pcbs, void *instance); + +// vs_*: formatted and themed virtual screen layout +// you cannot use ANSI escapes in these APIs. +void vs_header (const char *title, const char *mid, const char *right); // vs_head, showtitle +void vs_hdr (const char *title); // vs_bar, stand_title +void vs_footer (const char *caption, const char *prompt); + +void vs_rectangle_simple(int l, int t, int r, int b); // draw a single line rectangle, not filling inside interior + +// columned output +void vs_cols_layout (const VCOL* cols, VCOLW *ws, int n); /// calculate VCOL to fit current screen in ws +void vs_cols (const VCOL* cols, const VCOLW *ws, int n, ...); + +// VREF: save and storing temporary objects (restore will also free object). +VREFSCR vscr_save (void); +void vscr_restore(VREFSCR); +VREFCUR vcur_save (void); +void vcur_restore(VREFCUR); + +#endif // _VISIO_H -- cgit v1.2.3