* Handle full-screen curses stuff
*/
-#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdarg.h>
-#include <unistd.h>
#include <sys/types.h>
+#include "sysdep.h"
#ifdef HAVE_VW_PRINTW
#define _vwprintw vw_printw
#else
#include "snprintf.h"
#endif
#include "citadel.h"
+#include "citadel_ipc.h"
+#include "citadel_decls.h"
#include "commands.h"
#include "screen.h"
-#include "citadel_decls.h"
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
static SCREEN *myscreen = NULL;
static WINDOW *mainwindow = NULL;
static WINDOW *statuswindow = NULL;
char rc_screen;
char arg_screen;
+#endif
extern int screenheight;
extern int screenwidth;
extern int rc_ansi_color;
extern void check_screen_dims(void);
-#endif
void do_keepalive(void);
int is_curses_enabled(void) {
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
return mainwindow != NULL;
#else
return 0;
* status_line() is a convenience function for writing a "typical"
* status line to the window.
*/
-void status_line(const char *humannode, const char *bbs_city,
+void status_line(const char *humannode, const char *site_location,
const char *room_name, int secure, int newmailcount)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (statuswindow) {
if (secure) {
sln_printf("Encrypted ");
sln_printf("%s on ", room_name);
if (humannode)
sln_printf("%s ", humannode);
- if (newmailcount > -1) {
+ if (newmailcount > 0) {
waddch(statuswindow, ACS_VLINE);
- sln_printf(" Mail: %d new ", newmailcount);
+ sln_printf(" %d new mail ", newmailcount);
}
sln_printf("\n");
}
}
+/*
+ * Display a 3270-style "wait" indicator at the bottom of the screen
+ */
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
+void wait_indicator(int state) {
+
+ if (!isendwin() && statuswindow) {
+
+ mvwinch(statuswindow, 0, screenwidth - 2);
+ switch (state) {
+ default:
+ case 0: /* Idle */
+ waddch(statuswindow, ' ');
+ break;
+ case 1: /* Waiting */
+ waddch(statuswindow, 'X');
+ break;
+ case 2: /* Receiving */
+ waddch(statuswindow, '<');
+ break;
+ case 3: /* Sending */
+ waddch(statuswindow, '>');
+ break;
+ }
+ waddch(statuswindow, '\r');
+ wrefresh(statuswindow);
+ wrefresh(mainwindow); /* this puts the cursor back */
+ }
+}
+#endif
+
+
/*
* Initialize the screen. If newterm() fails, myscreen will be NULL and
* further handlers will assume we should be in line mode.
*/
void screen_new(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (arg_screen != RC_NO && rc_screen != RC_NO)
myscreen = newterm(NULL, stdout, stdin);
if (myscreen) {
{
windows_delete();
screen_reset();
-#ifdef HAVE_CURSES_H
- if (myscreen)
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
+ if (myscreen) {
delscreen(myscreen);
+ }
myscreen = NULL;
#endif
}
+/*
+ * Beep.
+ */
+void ctdl_beep(void) {
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
+ if (myscreen)
+ beep();
+ else
+#endif
+ putc(7, stdout);
+}
+
+
/*
* Set screen/IO parameters, e.g. at start of program or return from external
*/
int screen_set(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (myscreen) {
set_term(myscreen);
wrefresh(curscr);
*/
int screen_reset(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (myscreen) {
- endwin();
+ if (!isendwin()) endwin();
return 1;
}
#endif /* HAVE_CURSES_H */
register int retval;
va_start(ap, fmt);
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow) {
retval = _vwprintw(mainwindow, fmt, ap);
} else
register int retval;
va_start(ap, fmt);
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow) { /* FIXME: direct to error window */
retval = _vwprintw(mainwindow, fmt, ap);
if (fmt[strlen(fmt) - 1] == '\n')
{
va_list ap;
register int retval;
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
static char buf[4096];
#endif
va_start(ap, fmt);
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (statuswindow) {
register char *i;
int sln_printf_if(char *fmt, ...)
{
register int retval = 1;
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
static char buf[4096];
va_list ap;
int scr_getc(int delay)
{
- char buf;
+ unsigned char buf;
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow) {
wtimeout(mainwindow, delay);
return wgetch(mainwindow);
}
#endif
- buf = '\0';
- read (0, &buf, 1);
+ buf = '\0';
+ if (!read (0, &buf, 1))
+ logoff(NULL, 3);
return buf;
}
int scr_blockread(void)
{
int a = 0;
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
wtimeout(mainwindow, S_KEEPALIVE);
while (1)
{
*/
int scr_putc(int c)
{
-#ifdef HAVE_CURSES_H
- if (mainwindow)
- return ((waddch(mainwindow, c) == OK) ? c : EOF);
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
+ if (mainwindow) {
+ if (c == 7) beep();
+ if (waddch(mainwindow, c) != OK)
+ logoff(NULL, 3);
+ return c;
+ }
#endif
- return putc(c, stdout);
+ if (putc(c, stdout) == EOF)
+ logoff(NULL, 3);
+ return c;
}
int sln_putc(int c)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (statuswindow)
return ((waddch(statuswindow, c) == OK) ? c : EOF);
#endif
int sln_putc_if(int c)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (statuswindow)
return ((waddch(statuswindow, c) == OK) ? c : EOF);
#endif
*/
int scr_color(int colornum)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow) {
#ifdef HAVE_WCOLOR_SET
wcolor_set(mainwindow, (colornum & 7), NULL);
void scr_flush(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow)
wrefresh(mainwindow);
else
void err_flush(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow) /* FIXME: error status window needed */
wrefresh(mainwindow);
else
void sln_flush(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (statuswindow)
wrefresh(statuswindow);
else
/*
* this is not supposed to be called from a signal handler.
*/
-int scr_set_windowsize()
+int scr_set_windowsize(CtdlIPC* ipc)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow && caught_sigwinch) {
caught_sigwinch = 0;
+#ifdef HAVE_RESIZETERM
resizeterm(screenheight + 1, screenwidth);
+#endif
+#ifdef HAVE_WRESIZE
wresize(mainwindow, screenheight, screenwidth);
wresize(statuswindow, 1, screenwidth);
+#endif
mvwin(statuswindow, screenheight, 0);
- status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
- room_name, secure, -1);
+ status_line(ipc->ServInfo.humannode, ipc->ServInfo.site_location,
+ room_name, secure, -1);
wnoutrefresh(mainwindow);
wnoutrefresh(statuswindow);
doupdate();
*/
void windows_new(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
register int x, y;
if (myscreen) {
*/
void windows_delete(void)
{
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
if (mainwindow)
delwin(mainwindow);
mainwindow = NULL;