2001-08-17 05:46:24 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
2002-01-07 19:16:03 +00:00
|
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
|
* Purpose ...............: Terminal output routines.
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************
|
2004-02-21 14:24:03 +00:00
|
|
|
|
* Copyright (C) 1997-2004
|
2001-08-17 05:46:24 +00:00
|
|
|
|
*
|
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
|
* Beekmansbos 10
|
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
|
* the Netherlands
|
|
|
|
|
*
|
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
|
*
|
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
|
* later version.
|
|
|
|
|
*
|
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
|
#include "../config.h"
|
2004-02-21 14:24:03 +00:00
|
|
|
|
#include "mbselib.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
|
#include "users.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int termmode; /* 0 = tty, 1 = ANSI */
|
2004-02-21 17:22:00 +00:00
|
|
|
|
int termx = 80;
|
|
|
|
|
int termy = 24;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
2004-02-21 17:22:00 +00:00
|
|
|
|
void TermInit(int mode, int x, int y)
|
2001-08-17 05:46:24 +00:00
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
termmode = mode;
|
2004-02-21 17:22:00 +00:00
|
|
|
|
termx = x;
|
|
|
|
|
termy = y;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function will print about of enters specified
|
|
|
|
|
*/
|
|
|
|
|
void Enter(int num)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
int i;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
|
fprintf(stdout, "\n");
|
|
|
|
|
fflush(stdout);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pout(int fg, int bg, char *Str)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
colour(fg, bg);
|
|
|
|
|
fprintf(stdout, Str);
|
|
|
|
|
fflush(stdout);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void poutCenter(int fg, int bg, char *Str)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
colour(fg, bg);
|
|
|
|
|
Center(Str);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void poutCR(int fg, int bg, char *Str)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
colour(fg, bg);
|
|
|
|
|
fputs(Str, stdout);
|
2003-02-20 21:06:46 +00:00
|
|
|
|
fprintf(stdout, "\n");
|
2002-07-29 20:31:18 +00:00
|
|
|
|
fflush(stdout);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Changes ansi background and foreground color
|
|
|
|
|
*/
|
|
|
|
|
void colour(int fg, int bg)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
if (termmode == 1) {
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
int att=0, fore=37, back=40;
|
|
|
|
|
|
|
|
|
|
if (fg<0 || fg>31 || bg<0 || bg>7) {
|
|
|
|
|
fprintf(stdout, "ANSI: Illegal colour specified: %i, %i\n", fg, bg);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(stdout, "[");
|
2004-02-21 14:24:03 +00:00
|
|
|
|
if ( fg > WHITE) {
|
2002-07-29 20:31:18 +00:00
|
|
|
|
fprintf(stdout, "5;");
|
2004-02-21 14:24:03 +00:00
|
|
|
|
fg-= 16;
|
2002-07-29 20:31:18 +00:00
|
|
|
|
}
|
2004-02-21 14:24:03 +00:00
|
|
|
|
if (fg > LIGHTGRAY) {
|
2002-07-29 20:31:18 +00:00
|
|
|
|
att=1;
|
|
|
|
|
fg=fg-8;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
2002-07-29 20:31:18 +00:00
|
|
|
|
|
2004-02-21 14:24:03 +00:00
|
|
|
|
if (fg == BLACK) fore=30;
|
|
|
|
|
else if (fg == BLUE) fore=34;
|
|
|
|
|
else if (fg == GREEN) fore=32;
|
|
|
|
|
else if (fg == CYAN) fore=36;
|
|
|
|
|
else if (fg == RED) fore=31;
|
|
|
|
|
else if (fg == MAGENTA) fore=35;
|
|
|
|
|
else if (fg == BROWN) fore=33;
|
|
|
|
|
else fore=37;
|
|
|
|
|
|
|
|
|
|
if (bg == BLUE) back=44;
|
|
|
|
|
else if (bg == GREEN) back=42;
|
|
|
|
|
else if (bg == CYAN) back=46;
|
|
|
|
|
else if (bg == RED) back=41;
|
|
|
|
|
else if (bg == MAGENTA) back=45;
|
|
|
|
|
else if (bg == BROWN) back=43;
|
|
|
|
|
else if (bg == LIGHTGRAY) back=47;
|
|
|
|
|
else back=40;
|
2002-07-29 20:31:18 +00:00
|
|
|
|
|
|
|
|
|
fprintf(stdout, "%d;%d;%dm", att, fore, back);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Center(char *string)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
int Strlen;
|
2004-02-21 17:22:00 +00:00
|
|
|
|
int Maxlen = termx;
|
2002-07-29 20:31:18 +00:00
|
|
|
|
int i, x, z;
|
|
|
|
|
char *Str;
|
|
|
|
|
|
2004-02-21 17:22:00 +00:00
|
|
|
|
Str = calloc(1024, sizeof(char));
|
2002-07-29 20:31:18 +00:00
|
|
|
|
Strlen = strlen(string);
|
|
|
|
|
|
|
|
|
|
if (Strlen == Maxlen)
|
|
|
|
|
fprintf(stdout, "%s\n", string);
|
|
|
|
|
else {
|
|
|
|
|
x = Maxlen - Strlen;
|
|
|
|
|
z = x / 2;
|
|
|
|
|
for (i = 0; i < z; i++)
|
|
|
|
|
strcat(Str, " ");
|
|
|
|
|
strcat(Str, string);
|
|
|
|
|
fprintf(stdout, "%s\n", Str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
free(Str);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
if (termmode == 1) {
|
|
|
|
|
colour(LIGHTGRAY, BLACK);
|
|
|
|
|
fprintf(stdout, ANSI_HOME);
|
|
|
|
|
fprintf(stdout, ANSI_CLEAR);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
} else
|
|
|
|
|
Enter(1);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Moves cursor to specified position
|
|
|
|
|
*/
|
|
|
|
|
void locate(int y, int x)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
if (termmode > 0) {
|
2004-02-21 17:22:00 +00:00
|
|
|
|
if (y > termy || x > termx) {
|
|
|
|
|
fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
2002-07-29 20:31:18 +00:00
|
|
|
|
fprintf(stdout, "\x1B[%i;%iH", y, x);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fLine(int Len)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
int x;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
if (termmode == 0)
|
|
|
|
|
for (x = 0; x < Len; x++)
|
|
|
|
|
fprintf(stdout, "-");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
if (termmode == 1)
|
|
|
|
|
for (x = 0; x < Len; x++)
|
|
|
|
|
fprintf(stdout, "%c", 196);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
fprintf(stdout, " \n");
|
|
|
|
|
fflush(stdout);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sLine()
|
|
|
|
|
{
|
2004-02-21 17:22:00 +00:00
|
|
|
|
fLine(termx -1);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* curses compatible functions
|
|
|
|
|
*/
|
|
|
|
|
void mvprintw(int y, int x, const char *format, ...)
|
|
|
|
|
{
|
2002-07-29 20:31:18 +00:00
|
|
|
|
char *outputstr;
|
|
|
|
|
va_list va_ptr;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
outputstr = calloc(2048, sizeof(char));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
va_start(va_ptr, format);
|
|
|
|
|
vsprintf(outputstr, format, va_ptr);
|
|
|
|
|
va_end(va_ptr);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
2002-07-29 20:31:18 +00:00
|
|
|
|
locate(y, x);
|
|
|
|
|
fprintf(stdout, outputstr);
|
|
|
|
|
free(outputstr);
|
|
|
|
|
fflush(stdout);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|