Back to index

citadel  8.12
Functions | Variables
screen.c File Reference
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "sysdep.h"
#include "snprintf.h"
#include <libcitadel.h>
#include "citadel.h"
#include "citadel_ipc.h"
#include "citadel_decls.h"
#include "commands.h"
#include "screen.h"

Go to the source code of this file.

Functions

void do_keepalive (void)
void check_screen_dims (void)
void screen_new (void)
void ctdl_beep (void)
int scr_printf (char *fmt,...)
int scr_getc (int delay)
void hit_any_key (void)
int scr_putc (int c)
void scr_flush (void)
RETSIGTYPE scr_winch (int signum)
void scr_wait_indicator (int state)

Variables

int enable_status_line = 0
char status_line [1024] = " "
char * moreprompt = " -- more -- "
int screenheight = 24
int screenwidth = 80
int lines_printed = 0
int cols_printed = 0
int rc_ansi_color
int rc_prompt_control
static volatile int caught_sigwinch = 0

Function Documentation

void check_screen_dims ( void  )

Definition at line 55 of file screen.c.

{
#ifdef TIOCGWINSZ
       struct {
              unsigned short height;      /* rows */
              unsigned short width;       /* columns */
              unsigned short xpixels;
              unsigned short ypixels;     /* pixels */
       } xwinsz;

       if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
              if (xwinsz.height)
                     screenheight = (int) xwinsz.height;
              if (xwinsz.width)
                     screenwidth = (int) xwinsz.width;
       }
#endif
}

Here is the caller graph for this function:

void ctdl_beep ( void  )

Definition at line 91 of file screen.c.

                     {
       putc(7, stdout);
}

Here is the caller graph for this function:

void do_keepalive ( void  )

Definition at line 362 of file commands.c.

{
       time_t now;

       time(&now);
       if ((now - idlet) < ((long) S_KEEPALIVE))
              return;

       /* Do a space-backspace to keep telnet sessions from idling out */
       scr_printf(" %c", 8);
       scr_flush();

#ifdef THREADED_CLIENT
       if (async_ka_enabled)
              async_ka_exec();
       else
#endif
              really_do_keepalive();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hit_any_key ( void  )

Definition at line 140 of file screen.c.

                       {
       int a, b;

       color(COLOR_PUSH);
       color(DIM_RED);
       scr_printf("%s\r", moreprompt);
       color(COLOR_POP);
       b=inkey();
       for (a=0; a<screenwidth; ++a) {
              scr_putc(' ');
       }
       scr_printf("\r");

       if ( (rc_prompt_control == 1) || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
              if (b == 'q' || b == 'Q' || b == 's' || b == 'S') {
                     b = STOP_KEY;
              }
              if (b == 'n' || b == 'N') {
                     b = NEXT_KEY;
              }
       }

       if (b==NEXT_KEY) sigcaught = SIGINT;
       if (b==STOP_KEY) sigcaught = SIGQUIT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void scr_flush ( void  )

Definition at line 216 of file screen.c.

{
       if ((enable_color) && (screenwidth > 0) && (enable_status_line)) {
              if (strlen(status_line) < screenwidth) {
                     memset(&status_line[strlen(status_line)], 32, screenwidth - strlen(status_line));
              }
              printf("\033[s\033[1;1H\033[K\033[7m");
              fwrite(status_line, screenwidth, 1, stdout);
              printf("\033[27m\033[u");
       }
       fflush(stdout);
}

Here is the caller graph for this function:

int scr_getc ( int  delay)

Definition at line 123 of file screen.c.

{
       unsigned char buf;

       scr_flush();

       buf = '\0';
       if (!read (0, &buf, 1))
              logoff(NULL, 3);

       lines_printed = 0;
       return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int scr_printf ( char *  fmt,
  ... 
)

Definition at line 101 of file screen.c.

{
       static char outbuf[4096];   /* static for performance -- not re-entrant -- change if needed */
       va_list ap;
       register int retval;
       int i, len;

       va_start(ap, fmt);
       retval = vsnprintf(outbuf, sizeof outbuf, fmt, ap);
       va_end(ap);

       len = strlen(outbuf);
       for (i=0; i<len; ++i) {
              scr_putc(outbuf[i]);
       }
       return retval;
}

Here is the call graph for this function:

int scr_putc ( int  c)

Definition at line 170 of file screen.c.

{
       /* handle tabs normally */
       if (c == '\t') {
              do {
                     scr_putc(' ');
              } while ((cols_printed % 8) != 0);
              return(c);
       }

       /* Output the character... */
       if (putc(c, stdout) == EOF) {
              logoff(NULL, 3);
       }

       if (c == '\n') {
              ++lines_printed;
              cols_printed = 0;
       }
       else if (c == '\r') {
              cols_printed = 0;
       }
       else if (isprint(c)) {
              ++cols_printed;
              if ((screenwidth > 0) && (cols_printed > screenwidth)) {
                     ++lines_printed;
                     cols_printed = 0;
              }
       }

       /* How many lines output before stopping for the paginator?
        * Depends on whether we are displaying a status line.
        */
       int height_offset = ( ((enable_color) && (screenwidth > 0) && (enable_status_line)) ? (3) : (2) ) ;

       /* Ok, go check it.  Stop and display the paginator prompt if necessary. */
       if ((screenheight > 0) && (lines_printed > (screenheight-height_offset))) {
              lines_printed = 0;
              hit_any_key();
              lines_printed = 0;
              cols_printed = 0;
       }

       return c;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void scr_wait_indicator ( int  state)

Definition at line 252 of file screen.c.

                                   {
       int sp = (screenwidth - 2);

       if (!enable_status_line) return;

       if (screenwidth > 0) {
              switch (state) {
                     default:
                     case 0:        /* Idle */
                            status_line[sp] = ' ';
                            break;
                     case 1:        /* Waiting */
                            status_line[sp] = 'X';
                            break;
                     case 2:        /* Receiving */
                            status_line[sp] = '<';
                            break;
                     case 3:        /* Sending */
                            status_line[sp] = '>';
                            break;
              }
              scr_flush();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

RETSIGTYPE scr_winch ( int  signum)

Definition at line 237 of file screen.c.

{
       /* if we receive this signal, we must be running
        * in a terminal that supports resizing.
        */
       caught_sigwinch = 1;
       check_screen_dims();
       signal(SIGWINCH, scr_winch);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void screen_new ( void  )

Definition at line 78 of file screen.c.

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

volatile int caught_sigwinch = 0 [static]

Definition at line 230 of file screen.c.

int cols_printed = 0

Definition at line 45 of file screen.c.

Definition at line 36 of file screen.c.

int lines_printed = 0

Definition at line 44 of file screen.c.

char* moreprompt = " -- more -- "

Definition at line 40 of file screen.c.

Definition at line 87 of file commands.c.

Definition at line 89 of file commands.c.

int screenheight = 24

Definition at line 42 of file screen.c.

int screenwidth = 80

Definition at line 43 of file screen.c.

char status_line[1024] = " "

Definition at line 37 of file screen.c.