summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ansi.h2
-rw-r--r--mbbsd/calendar.c32
-rw-r--r--mbbsd/edit.c2
-rw-r--r--mbbsd/talk.c2
-rw-r--r--mbbsd/term.c10
-rw-r--r--mbbsd/var.c12
6 files changed, 33 insertions, 27 deletions
diff --git a/include/ansi.h b/include/ansi.h
index 1b0d9073..cb7e86cd 100644
--- a/include/ansi.h
+++ b/include/ansi.h
@@ -16,7 +16,7 @@
// Common ANSI commands.
#define ANSI_RESET ESC_STR "[m"
#define ANSI_COLOR(x) ESC_STR "[" #x "m"
-#define ANSI_MOVETO(x,y) ESC_STR "[" #x ";" #y "H"
+#define ANSI_MOVETO(y,x) ESC_STR "[" #y ";" #x "H"
#define ANSI_CLRTOEND ESC_STR "[K"
#endif /* INCLUDE_ANSI_H */
diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c
index f3cafca2..5a398b3d 100644
--- a/mbbsd/calendar.c
+++ b/mbbsd/calendar.c
@@ -181,19 +181,19 @@ FreeCalBuffer(char **buf)
free(buf);
}
-#define CALENDAR_COLOR "\33[0;30;47m"
-#define HEADER_COLOR "\33[1;44m"
-#define HEADER_SUNDAY_COLOR "\33[31m"
-#define HEADER_DAY_COLOR "\33[33m"
+#define CALENDAR_COLOR ANSI_COLOR(0;30;47)
+#define HEADER_COLOR ANSI_COLOR(1;44)
+#define HEADER_SUNDAY_COLOR ANSI_COLOR(31)
+#define HEADER_DAY_COLOR ANSI_COLOR(33)
static int
GenerateCalendar(char **buf, int y, int m, int today, event_t * e)
{
char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"};
char *month_color[12] = {
- "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m",
- "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m",
- "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m"
+ ANSI_COLOR(1;32), ANSI_COLOR(1;33), ANSI_COLOR(1;35), ANSI_COLOR(1;36),
+ ANSI_COLOR(1;32), ANSI_COLOR(1;33), ANSI_COLOR(1;35), ANSI_COLOR(1;36),
+ ANSI_COLOR(1;32), ANSI_COLOR(1;33), ANSI_COLOR(1;35), ANSI_COLOR(1;36)
};
char *month_str[12] = {
"一月 ", "二月 ", "三月 ", "四月 ", "五月 ", "六月 ",
@@ -210,7 +210,7 @@ GenerateCalendar(char **buf, int y, int m, int today, event_t * e)
week_str[0], HEADER_DAY_COLOR);
for (i = 1; i < 7; i++)
p += sprintf(p, " %s", week_str[i]);
- p += sprintf(p, "\33[m");
+ p += sprintf(p, ANSI_RESET);
/* indent for first line */
p = buf[++line];
@@ -226,18 +226,18 @@ GenerateCalendar(char **buf, int y, int m, int today, event_t * e)
attr1[0] = 0;
attr2 = "";
while (e && e->days == first_day + i - 1) {
- sprintf(attr1, "\33[1;%dm", e->color);
+ sprintf(attr1, ANSI_COLOR(1;%d), e->color);
attr2 = CALENDAR_COLOR;
e = e->next;
}
if (today == first_day + i - 1) {
- strlcpy(attr1, "\33[1;37;42m", sizeof(attr1));
+ strlcpy(attr1, ANSI_COLOR(1;37;42), sizeof(attr1));
attr2 = CALENDAR_COLOR;
}
p += sprintf(p, "%s%2d%s", attr1, i, attr2);
if (w == 6) {
- p += sprintf(p, "\33[m");
+ p += sprintf(p, ANSI_RESET);
p = buf[++line];
/* show month */
if (line >= 2 && line <= 4)
@@ -254,7 +254,7 @@ GenerateCalendar(char **buf, int y, int m, int today, event_t * e)
if (w) {
for (w = 7 - w; w; w--)
p += sprintf(p, w == 1 ? " " : " ");
- p += sprintf(p, "\33[m");
+ p += sprintf(p, ANSI_RESET);
}
return line + 1;
}
@@ -293,13 +293,17 @@ calendar(void)
for (i = 0; i < 22; i++) {
outs(buf[i]);
if (i == 0) {
- prints("\t\33[1;37m現在是 %d.%02d.%02d %2d:%02d:%02d%cm\33[m",
+ prints("\t" ANSI_COLOR(1;37)
+ "現在是 %d.%02d.%02d %2d:%02d:%02d%cm" ANSI_RESET,
snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday,
(snow.tm_hour == 0 || snow.tm_hour == 12) ?
12 : snow.tm_hour % 12, snow.tm_min, snow.tm_sec,
snow.tm_hour >= 12 ? 'p' : 'a');
} else if (i >= 2 && e) {
- prints("\t\33[1;37m(\33[%dm%3d\33[37m)\33[m %02d/%02d %s",
+ prints("\t" ANSI_COLOR(1;37)
+ "(" ANSI_COLOR(%d) "%3d"
+ ANSI_COLOR(37) ")"
+ ANSI_RESET " %02d/%02d %s",
e->color, e->days - today,
e->month, e->day, e->content);
e = e->next;
diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index 53e6dea3..539985c4 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -1895,7 +1895,7 @@ display_textline_internal(textline_t *p, int i, int min, int max)
newpnt = fix_cursor(p->data, newpnt, FC_LEFT);
if(newpnt == curr_buf->edit_margin-1)
{
- (*output)("\033[1m\033[m");
+ (*output)(ANSI_COLOR(1) "<" ANSI_RESET);
pdata++;
}
(*output)(pdata);
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index a57827fe..40585253 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -2003,7 +2003,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way,
memcpy(mind, uentp->mind, 4);
mind[4] = 0;
prints("%5d %c%c%s%-13s%-17.16s" ANSI_RESET "%-17.16s%-13.13s"
- "\33[33m%-4.4s\33[m%s\n",
+ ANSI_COLOR(33) "%-4.4s" ANSI_RESET "%s\n",
/* list number or uid */
#ifdef SHOWUID
diff --git a/mbbsd/term.c b/mbbsd/term.c
index 782d07b8..2ef13ed0 100644
--- a/mbbsd/term.c
+++ b/mbbsd/term.c
@@ -80,7 +80,7 @@ do_move(int destcol, int destline)
{
char buf[16], *p;
- snprintf(buf, sizeof(buf), "\33[%d;%dH", destline + 1, destcol + 1);
+ snprintf(buf, sizeof(buf), ANSI_MOVETO(%d,%d), destline + 1, destcol + 1);
for (p = buf; *p; p++)
ochar(*p);
}
@@ -88,14 +88,14 @@ do_move(int destcol, int destline)
void
save_cursor(void)
{
- ochar('\33');
+ ochar(ESC_CHR);
ochar('7');
}
void
restore_cursor(void)
{
- ochar('\33');
+ ochar(ESC_CHR);
ochar('8');
}
@@ -104,7 +104,7 @@ change_scroll_range(int top, int bottom)
{
char buf[16], *p;
- snprintf(buf, sizeof(buf), "\33[%d;%dr", top + 1, bottom + 1);
+ snprintf(buf, sizeof(buf), ESC_STR "[%d;%dr", top + 1, bottom + 1);
for (p = buf; *p; p++)
ochar(*p);
}
@@ -112,6 +112,6 @@ change_scroll_range(int top, int bottom)
void
scroll_forward(void)
{
- ochar('\33');
+ ochar(ESC_CHR);
ochar('D');
}
diff --git a/mbbsd/var.c b/mbbsd/var.c
index baee68d0..c9e439ca 100644
--- a/mbbsd/var.c
+++ b/mbbsd/var.c
@@ -312,15 +312,17 @@ int b_lines = 23; // bottom line of screen
int t_lines = 24; // term lines
int p_lines = 20;
int t_columns = 80;
-char * const strtstandout = "\33[7m";
+
+/* refer to ansi.h for *len */
+char * const strtstandout = ANSI_COLOR(7);
const int strtstandoutlen = 4;
-char * const endstandout = "\33[m";
+char * const endstandout = ANSI_RESET;
const int endstandoutlen = 3;
-char * const clearbuf = "\33[H\33[J";
+char * const clearbuf = ESC_STR "[H" ESC_STR "[J";
const int clearbuflen = 6;
-char * const cleolbuf = "\33[K";
+char * const cleolbuf = ESC_STR "[K";
const int cleolbuflen = 3;
-char * const scrollrev = "\33M";
+char * const scrollrev = ESC_STR "M";
const int scrollrevlen = 2;
int automargins = 1;