summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-19 23:39:37 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-19 23:39:37 +0800
commit60c7059c312f02d1dd5738d7e9c2872a1a123657 (patch)
treea1e4ec9e7c788fcbfaf22882e7629823faeb4067 /mbbsd
parentacf58ca18005d3ed917cbc80a33baeec9d44335f (diff)
downloadpttbbs-60c7059c312f02d1dd5738d7e9c2872a1a123657.tar
pttbbs-60c7059c312f02d1dd5738d7e9c2872a1a123657.tar.gz
pttbbs-60c7059c312f02d1dd5738d7e9c2872a1a123657.tar.bz2
pttbbs-60c7059c312f02d1dd5738d7e9c2872a1a123657.tar.lz
pttbbs-60c7059c312f02d1dd5738d7e9c2872a1a123657.tar.xz
pttbbs-60c7059c312f02d1dd5738d7e9c2872a1a123657.tar.zst
pttbbs-60c7059c312f02d1dd5738d7e9c2872a1a123657.zip
- isolate low level termial i/o api calls, prepare for pfterm
(piaip's flat terminal system) git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3710 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/kaede.c93
-rw-r--r--mbbsd/screen.c141
-rw-r--r--mbbsd/term.c16
3 files changed, 121 insertions, 129 deletions
diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c
index 8e328e5d..92b26885 100644
--- a/mbbsd/kaede.c
+++ b/mbbsd/kaede.c
@@ -1,6 +1,9 @@
/* $Id$ */
#include "bbs.h"
+// TODO move stuff to libbbs(or util)/string.c, ...
+// this file can be removed (or not?)
+
char *
Ptt_prints(char *str, size_t size, int mode)
{
@@ -71,3 +74,93 @@ Ptt_prints(char *str, size_t size, int mode)
return str;
}
+// utility from screen.c
+void
+outs_n(const char *str, int n)
+{
+ while (*str && n--) {
+ outc(*str++);
+ }
+}
+
+// XXX left-right (for large term)
+// TODO someday please add ANSI detection version
+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
+out_lines(const char *str, int line)
+{
+ while (*str && line) {
+ outc(*str);
+ if (*str == '\n')
+ line--;
+ str++;
+ }
+}
+
+void
+outmsg(const char *msg)
+{
+ move(b_lines - msg_occupied, 0);
+ clrtoeol();
+ 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,...)
+{
+ va_list args;
+ char buff[1024];
+
+ va_start(args, fmt);
+ vsnprintf(buff, sizeof(buff), fmt, args);
+ va_end(args);
+ outs(buff);
+}
+
+void
+mouts(int y, int x, const char *str)
+{
+ move(y, x);
+ clrtoeol();
+ outs(str);
+}
+
+// vim:ts=4
diff --git a/mbbsd/screen.c b/mbbsd/screen.c
index 941ad015..7bc61e54 100644
--- a/mbbsd/screen.c
+++ b/mbbsd/screen.c
@@ -24,6 +24,30 @@ initscr(void)
}
}
+int
+resizescr(int w, int h)
+{
+ screenline_t *new_picture;
+
+ /* make sure reasonable size */
+ h = MAX(24, MIN(100, h));
+ w = MAX(80, MIN(200, w));
+
+ if (h > t_lines && big_picture) {
+ new_picture = (screenline_t *)
+ calloc(h, sizeof(screenline_t));
+ if (new_picture == NULL) {
+ syslog(LOG_ERR, "calloc(): %m");
+ return 0;
+ }
+ memcpy(new_picture, big_picture, t_lines * sizeof(screenline_t));
+ free(big_picture);
+ big_picture = new_picture;
+ return 1;
+ }
+ return 0;
+}
+
void
move(int y, int x)
{
@@ -170,34 +194,6 @@ redoscr(void)
oflush();
}
-// deprecated?
-#if 0
-void
-redoln(void)
-{
- screenline_t *slp = GetCurrentLine();
- int len, mode;
-
- len = slp->len;
- rel_move(tc_col, tc_line, 0, cur_ln);
- if (len)
- {
- if ((mode = slp->mode) & STANDOUT)
- standoutput((char*)slp->data, 0, len, slp->sso, slp->eso);
- else
- output((char*)slp->data, len);
-
- slp->mode = mode & ~(MODIFIED);
-
- slp->oldlen = tc_col = len;
- }
- else
- clrtoeol();
- rel_move(tc_col, tc_line, cur_col, cur_ln);
- oflush();
-}
-#endif
-
void
refresh(void)
{
@@ -449,94 +445,6 @@ outs(const char *str)
}
void
-outs_n(const char *str, int n)
-{
- while (*str && n--) {
- outc(*str++);
- }
-}
-
-// XXX left-right (for large term)
-// TODO someday please add ANSI detection version
-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
-out_lines(const char *str, int line)
-{
- while (*str && line) {
- outc(*str);
- if (*str == '\n')
- line--;
- str++;
- }
-}
-
-void
-outmsg(const char *msg)
-{
- move(b_lines - msg_occupied, 0);
- clrtoeol();
- 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,...)
-{
- va_list args;
- char buff[1024];
-
- va_start(args, fmt);
- vsnprintf(buff, sizeof(buff), fmt, args);
- va_end(args);
- outs(buff);
-}
-
-void
-mouts(int y, int x, const char *str)
-{
- move(y, x);
- clrtoeol();
- outs(str);
-}
-
-void
scroll(void)
{
scrollcnt++;
@@ -622,6 +530,7 @@ grayout_lines(int y, int end, int level)
if (y < 0) y = 0;
if (end > b_lines) end = b_lines;
+ // TODO change to y <= end someday
// loop lines
for (; y < end; y ++)
{
diff --git a/mbbsd/term.c b/mbbsd/term.c
index 2ef13ed0..202ea582 100644
--- a/mbbsd/term.c
+++ b/mbbsd/term.c
@@ -40,25 +40,15 @@ sig_term_resize(int sig)
void term_resize(int w, int h)
{
- screenline_t *new_picture;
-
Signal(SIGWINCH, SIG_IGN); /* Don't bother me! */
/* make sure reasonable size */
h = MAX(24, MIN(100, h));
w = MAX(80, MIN(200, w));
- if (h > t_lines && big_picture) {
- new_picture = (screenline_t *)
- calloc(h, sizeof(screenline_t));
- if (new_picture == NULL) {
- syslog(LOG_ERR, "calloc(): %m");
- return;
- }
- memcpy(new_picture, big_picture, t_lines * sizeof(screenline_t));
- free(big_picture);
- big_picture = new_picture;
- }
+ // invoke terminal system resize
+ resizescr(h, w);
+
t_lines = h;
t_columns = w;
scr_lns = t_lines; /* XXX: scr_lns 跟 t_lines 有什麼不同, 為何分成兩個 */