summaryrefslogtreecommitdiffstats
path: root/mbbsd/visio.c
blob: b12b037bf7192a10a6b4d700080c1d90d0119af2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* $Id$ */
#include "bbs.h"

/*
 * visio.c
 * High-level virtual screen input output control
 *
 * This is not the original visio.c from maple3.
 * m3 visio = (ptt) visio+screen.
 * This visio contains only high level UI element/widgets.
 * In fact the only APIs from m3 are vmsg/vget...
 *
 * To add API here, please...
 * (1) name the API in prefix of 'v'.
 * (2) use only screen.c APIs.
 * (3) take care of wide screen.
 * (4) utilize the colos in visio.h, and name asa VCLR_* (visio color)
 */

// ---- DEFINITION ---------------------------------------------------
#define MAX_COL     (t_columns-1)
#define SAFE_MAX_COL    (MAX_COL-1)

// ---- UTILITIES ----------------------------------------------------
inline void
outnc(int n, unsigned char c)
{
    while (n-- > 0)
    outc(c);
}

inline void
nblank(int n)
{
    outnc(n, ' ');
}

// ---- HIGH LEVEL API -----------------------------------------------
void
vfprints()
{
}

/**
 * 在最底部印出 caption msg 的形式
 * msg 中若有 () 則會變色, \t 後的文字會靠右。
 * 最後面會自動留一個空白 (以避免自動偵測中文字的問題)。
 */
void 
vfooter(const char *caption, const char *msg)
{
    int i = 0;
    move(b_lines, 0); clrtoeol();

    if (caption)
    {
    outs(VCLR_FOOTER_CAPTION);
    outs(caption); i+= strlen(caption);
    }

    if (!msg) msg = "";
    outs(VCLR_FOOTER);

    while (*msg && i < SAFE_MAX_COL)
    {
    if (*msg == '(')
        outs(VCLR_FOOTER_QUOTE);
    else if (*msg == '\t')
    {
        // if we don't have enough space, ignore whole.
        int l = strlen(++msg);
        if (i + l > SAFE_MAX_COL) break;
        l = SAFE_MAX_COL - l - i;
        nblank(l); 
        i += l;
        continue;
    }
    outc(*msg); i++;
    if (*msg == ')')
        outs(VCLR_FOOTER);
    msg ++;
    }
    nblank(SAFE_MAX_COL-i);
    outc(' ');
    outs(ANSI_RESET);
}