This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbsetup/screen.c

307 lines
5.9 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Screen functions for setup.
*
*****************************************************************************
2004-01-25 10:57:35 +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.
*
* MB 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 MB 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 17:22:00 +00:00
#include "../lib/mbselib.h"
2001-08-17 05:46:24 +00:00
#include "screen.h"
extern int init;
2002-05-04 19:45:19 +00:00
int bbs_free;
2001-08-17 05:46:24 +00:00
/*************************************************************************
*
* Global section
*/
void clrtoeol()
{
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
fprintf(stdout, "\r");
for (i = 0; i < COLS; i++)
fputc(' ', stdout);
fprintf(stdout, "\r");
fflush(stdout);
2001-08-17 05:46:24 +00:00
}
void hor_lin(int y, int x, int len)
{
2002-07-29 20:31:18 +00:00
int i;
2001-08-17 05:46:24 +00:00
mbse_locate(y, x);
2002-07-29 20:31:18 +00:00
for (i = 0; i < len; i++)
fputc('-', stdout);
fflush(stdout);
2001-08-17 05:46:24 +00:00
}
static int old_f = -1;
static int old_b = -1;
void set_color(int f, int b)
{
2002-01-12 16:36:56 +00:00
f = f & 15;
b = b & 7;
if ((f != old_f) || (b != old_b)) {
old_f = f;
old_b = b;
mbse_colour(f, b);
2002-01-12 16:36:56 +00:00
fflush(stdout);
}
2001-08-17 05:46:24 +00:00
}
static time_t lasttime;
/*
* Show the current date & time in the second status row
*/
void show_date(int fg, int bg, int y, int x)
{
2002-07-29 20:31:18 +00:00
time_t now;
char *p, buf[128];
now = time(NULL);
if (now != lasttime) {
lasttime = now;
set_color(LIGHTGREEN, BLUE);
p = ctime(&now);
Striplf(p);
mbse_mvprintw(1, 44, (char *)"%s TZUTC %s", p, gmtoffset(now));
2002-07-29 20:31:18 +00:00
p = asctime(gmtime(&now));
Striplf(p);
mbse_mvprintw(2, 44, (char *)"%s UTC", p);
2002-05-04 19:45:19 +00:00
2002-07-29 20:31:18 +00:00
/*
* Indicator if bbs is free
*/
strcpy(buf, SockR("SFRE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
strcpy(buf, SockR("SBBS:0;"));
if (strncmp(buf, "100:2,1", 7) == 0) {
set_color(WHITE, RED);
mbse_mvprintw(2,74, (char *)" Down ");
2002-07-29 20:31:18 +00:00
} else {
set_color(WHITE, BLUE);
mbse_mvprintw(2,74, (char *)" Free ");
2002-07-29 20:31:18 +00:00
}
bbs_free = TRUE;
} else {
set_color(WHITE, RED);
mbse_mvprintw(2,74, (char *)" Busy ");
2002-07-29 20:31:18 +00:00
bbs_free = FALSE;
2001-08-17 05:46:24 +00:00
}
2002-07-29 20:31:18 +00:00
if (y && x)
mbse_locate(y, x);
2002-07-29 20:31:18 +00:00
set_color(fg, bg);
}
2001-08-17 05:46:24 +00:00
}
void center_addstr(int y, char *s)
{
mbse_mvprintw(y, (COLS / 2) - (strlen(s) / 2), s);
2001-08-17 05:46:24 +00:00
}
/*
* Curses and screen initialisation.
*/
void screen_start(char *name)
{
2002-07-29 20:31:18 +00:00
int i;
mbse_TermInit(1, COLS, LINES);
2002-07-29 20:31:18 +00:00
/*
* Overwrite screen the first time, if user had it black on white
* it will change to white on black. clear() won't do the trick.
*/
set_color(LIGHTGRAY, BLUE);
mbse_locate(1, 1);
2002-07-29 20:31:18 +00:00
for (i = 0; i < LINES; i++) {
if (i == 3)
mbse_colour(LIGHTGRAY, BLACK);
2002-07-29 20:31:18 +00:00
clrtoeol();
if (i < LINES)
fprintf(stdout, "\n");
}
fflush(stdout);
set_color(WHITE, BLUE);
mbse_locate(1, 1);
2002-07-29 20:31:18 +00:00
printf((char *)"%s for MBSE BBS version %s", name, VERSION);
set_color(YELLOW, BLUE);
mbse_locate(2, 1);
2002-07-29 20:31:18 +00:00
printf((char *)SHORTRIGHT);
set_color(LIGHTGRAY, BLACK);
show_date(LIGHTGRAY, BLACK, 0, 0);
fflush(stdout);
2001-08-17 05:46:24 +00:00
}
/*
* Screen deinit
*/
void screen_stop()
{
2002-07-29 20:31:18 +00:00
set_color(LIGHTGRAY, BLACK);
mbse_clear();
2002-07-29 20:31:18 +00:00
fflush(stdout);
2001-08-17 05:46:24 +00:00
}
/*
* Message at the upperright window about actions
*/
void working(int txno, int y, int x)
{
2002-07-29 20:31:18 +00:00
int i;
if (init)
return;
/*
* If txno not 0 there will be something written. The
* reversed attributes for mono, or white on red for
* color screens is set. The cursor is turned off and
* original cursor position is saved.
*/
show_date(LIGHTGRAY, BLACK, 0, 0);
if (txno != 0)
set_color(YELLOW, RED);
else
set_color(LIGHTGRAY, BLACK);
2001-08-17 05:46:24 +00:00
2002-07-29 20:31:18 +00:00
switch (txno) {
case 0: mbse_mvprintw(4, 66, (char *)" ");
2001-08-17 05:46:24 +00:00
break;
case 1: mbse_mvprintw(4, 66, (char *)"Working . . .");
2001-08-17 05:46:24 +00:00
break;
case 2: mbse_mvprintw(4, 66, (char *)">>> ERROR <<<");
2001-08-17 05:46:24 +00:00
for (i = 1; i <= 5; i++) {
2002-07-29 20:31:18 +00:00
fputc(7, stdout);
fflush(stdout);
2004-01-25 10:57:35 +00:00
msleep(150);
2001-08-17 05:46:24 +00:00
}
2004-01-25 10:57:35 +00:00
msleep(550);
2001-08-17 05:46:24 +00:00
break;
case 3: mbse_mvprintw(4, 66, (char *)"Form inserted");
2002-07-29 20:31:18 +00:00
fputc(7, stdout);
2001-08-17 05:46:24 +00:00
fflush(stdout);
sleep(1);
break;
case 4: mbse_mvprintw(4, 66, (char *)"Form deleted ");
2002-07-29 20:31:18 +00:00
fputc(7, stdout);
2001-08-17 05:46:24 +00:00
fflush(stdout);
sleep(1);
break;
case 5: mbse_mvprintw(4, 66, (char *)"Moving . . . ");
2002-02-18 15:19:10 +00:00
break;
case 6: mbse_mvprintw(4, 66, (char *)"Data updated ");
2004-02-05 21:05:31 +00:00
fputc(7, stdout);
fflush(stdout);
sleep(1);
break;
2002-07-29 20:31:18 +00:00
}
2001-08-17 05:46:24 +00:00
2002-07-29 20:31:18 +00:00
show_date(LIGHTGRAY, BLACK, 0, 0);
set_color(LIGHTGRAY, BLACK);
if (y && x)
mbse_locate(y, x);
2002-07-29 20:31:18 +00:00
fflush(stdout);
2001-08-17 05:46:24 +00:00
}
/*
* Clear the middle window
*/
void clr_index()
{
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
set_color(LIGHTGRAY, BLACK);
for (i = 3; i <= (LINES - 1); i++) {
mbse_locate(i, 1);
2002-07-29 20:31:18 +00:00
clrtoeol();
}
2001-08-17 05:46:24 +00:00
}
/*
* Show help at the bottom of the screen.
*/
void showhelp(char *T)
{
2002-07-29 20:31:18 +00:00
int f, i, x, forlim;
f = FALSE;
mbse_locate(LINES-1, 1);
2002-07-29 20:31:18 +00:00
set_color(WHITE, RED);
clrtoeol();
x = 0;
forlim = strlen(T);
for (i = 0; i < forlim; i++) {
if (T[i] == '^') {
if (f == FALSE) {
f = TRUE;
set_color(YELLOW, RED);
} else {
f = FALSE;
set_color(WHITE, RED);
}
} else {
fputc(T[i], stdout);
x++;
2001-08-17 05:46:24 +00:00
}
2002-07-29 20:31:18 +00:00
}
set_color(LIGHTGRAY, BLACK);
fflush(stdout);
2001-08-17 05:46:24 +00:00
}