Exemplo n.º 1
0
/**
 * @brief Closedown the newt library, tidying screen.
 * @returns int , 0. (no errors reported)
 */
int newtFinished(void) {
    if (currentWindow) {
	for (; currentWindow >= windowStack; currentWindow--) {
	    free(currentWindow->buffer);
	    free(currentWindow->title);
	}
	currentWindow = NULL;
    }

    if (currentHelpline) {
	for (; currentHelpline >= helplineStack; currentHelpline--)
	    free(*currentHelpline);
	currentHelpline = NULL;
    }

    freeKeymap();

    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
    newtCursorOn();
    SLsmg_refresh();
    SLsmg_reset_smg();
    SLang_reset_tty();

    return 0;
}
Exemplo n.º 2
0
/*
 * Suspend / Resume
 */
static errr Term_xtra_sla_alive(int v)
{
	/* Suspend */
	if (!v)
	{
		/* Oops */
		if (!slang_on) return (1);

		/* We are now off */
		slang_on = FALSE;

		/* Shut down (temporarily) */
		SLsmg_reset_smg();
		SLang_reset_tty();
	}

	/* Resume */
	else
	{
		/* Oops */
		if (slang_on) return (1);

		/* Fix the screen */
		SLsmg_refresh();

		/* Note that we are on */
		slang_on = TRUE;
	}

	/* Success */
	return (0);
}
Exemplo n.º 3
0
Arquivo: slinit.c Projeto: Cergoo/junk
int main(void) {
    struct winsize ws;

    /* get the size of the terminal connected to stdout */
    if (ioctl(1, TIOCGWINSZ, &ws)) {
        perror("failed to get window size");
        return 1;
    }

    SLtt_get_terminfo();

    SLtt_Screen_Rows = ws.ws_row;
    SLtt_Screen_Cols = ws.ws_col;

    SLsmg_init_smg();

    /* heart of the program goes here */

    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
    SLsmg_refresh();
    SLsmg_reset_smg();
    SLang_reset_tty();

    return 0;
}
Exemplo n.º 4
0
int main(void) {
    struct winsize ws;

    /* get the size of the terminal connected to stdout */
    if (ioctl(1, TIOCGWINSZ, &ws)) {
        perror("failed to get window size");
        return 1;
    }

    SLtt_get_terminfo();

    SLtt_Screen_Rows = ws.ws_row;
    SLtt_Screen_Cols = ws.ws_col;

    SLsmg_init_smg();
    SLang_init_tty(-1, 0, 1);

    drawCharSet(0, 0, "Normal Character Set");
    drawCharSet(40, 1, "Alternate Character Set");

    SLsmg_refresh();
    SLang_getkey();

    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
    SLsmg_refresh();
    SLsmg_reset_smg();
    SLang_reset_tty();

    return 0;
}
Exemplo n.º 5
0
static void slang_getsize(aa_context * c, int *width, int *height)
{
    SLtt_get_screen_size();
    SLsmg_reset_smg();
    if (SLsmg_init_smg() != 0)
	printf("Internal error!\n");
    SLtt_set_mono(AA_NORMAL, "normal", 0);
    SLtt_set_mono(AA_BOLD, "bold", SLTT_BOLD_MASK);
    SLtt_set_mono(AA_DIM, "dim", SLTT_ALTC_MASK);
    SLtt_set_mono(AA_REVERSE, "reverse", SLTT_REV_MASK);
    SLtt_set_mono(AA_SPECIAL, "special", 0);
    SLtt_set_mono(AA_BOLDFONT, "boldfont", SLTT_BOLD_MASK);

    SLtt_set_color(AA_NORMAL, "normal", "lightgray", "black");
    SLtt_set_color(AA_BOLD, "bold", "white", "black");
    SLtt_set_color(AA_DIM, "dim", "gray", "black");
    SLtt_set_color(AA_REVERSE, "bold", "black", "lightgray");
    SLtt_set_color(AA_SPECIAL, "dim", "lightgray", "blue");
    SLtt_set_color(AA_BOLDFONT, "bold", "white", "black");
    *width = SLtt_Screen_Cols;
    *height = SLtt_Screen_Rows;
    /*if(i==2) exit(1); */
#ifdef GPM_MOUSEDRIVER
    gpm_mx = *width;
    gpm_my = *height;
#endif

}
Exemplo n.º 6
0
int
tty_reset_screen (void)
{
    SLsmg_reset_smg ();
    slsmg_active = FALSE;
    return 0;                   /* OK */
}
Exemplo n.º 7
0
int SLsmg_init_smg (void)
{
   int ret;

   BLOCK_SIGNALS;

   if (tt_Screen_Rows == NULL)
     init_tt_symbols ();

   if (Smg_Inited)
     SLsmg_reset_smg ();

   if (UTF8_Mode == -1)
     (void) SLsmg_utf8_enable (-1);

   if (-1 == (*tt_init_video) ())
     {
	UNBLOCK_SIGNALS;
	return -1;
     }
   
   if (-1 == (ret = init_smg ()))
     (void) (*tt_reset_video)();

   UNBLOCK_SIGNALS;
   return ret;
}
Exemplo n.º 8
0
static void slang_uninit(aa_context * c)
{
    SLsmg_reset_smg();
    if (uninitslang) {
	uninitslang = 0;
	__slang_is_up = 0;
    }
}
Exemplo n.º 9
0
int newtFinished(void) {
    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
    newtCursorOn();
    SLsmg_refresh();
    SLsmg_reset_smg();
    SLang_reset_tty();

    return 0;
}
Exemplo n.º 10
0
static void smg_reset_smg (void)
{
   if (Smg_Initialized <= 0)
     return;
   SLsig_block_signals ();
   SLsmg_reset_smg ();
   SLsig_unblock_signals ();
   Smg_Initialized = 0;
}
Exemplo n.º 11
0
static void ctl_close(void)
{
  if (ctl.opened)
    {
        SLsmg_normal();
        SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
        SLsmg_refresh();
        SLsmg_reset_smg();
        SLang_reset_tty();
      ctl.opened=0;
    }
}
Exemplo n.º 12
0
void os_inner_done(void)
{
	log_std(("os: os_inner_done\n"));

#ifdef USE_X
	if (OS.x_display) {
		log_std(("os: XCloseDisplay()\n"));
		OS.curses_active = 0;
		XCloseDisplay(OS.x_display);
	}
#endif
#ifdef USE_CURSES
	if (OS.curses_active) {
		log_std(("os: endwin()\n"));
		OS.curses_active = 0;
		endwin();
	}
#endif
#ifdef USE_SLANG
	if (OS.slang_active) {
		log_std(("os: SLsmg_reset_smg()\n"));
		OS.slang_active = 0;
		SLsmg_reset_smg();
	}
#endif
#ifdef USE_SDL
	if (OS.sdl_active) {
		log_std(("os: SDL_Quit()\n"));
		OS.sdl_active = 0;
		SDL_Quit();
	}
#endif
#ifdef USE_SVGALIB
	if (OS.svgalib_active) {
		OS.svgalib_active = 0;
		mouse_close(); /* always called */
	}
#endif

	/* restore term */
	if (OS.term_active) {
		log_std(("os: tcsetattr(%sICANON %sECHO)\n", (OS.term.c_lflag & ICANON) ? "" : "~", (OS.term.c_lflag & ECHO) ? "" : "~"));
		OS.term_active = 0;
		if (tcsetattr(fileno(stdin), TCSAFLUSH, &OS.term) != 0) {
			/* ignore error */
			log_std(("os: tcsetattr(TCSAFLUSH) failed\n"));
		}
	}

	log_std(("os: os_inner_done completed\n"));
}
Exemplo n.º 13
0
void ui__exit(bool wait_for_ok)
{
	if (wait_for_ok)
		ui__question_window("Fatal Error",
				    ui_helpline__last_msg,
				    "Press any key...", 0);

	SLtt_set_cursor_visibility(1);
	SLsmg_refresh();
	SLsmg_reset_smg();
	SLang_reset_tty();

	perf_error__unregister(&perf_tui_eops);
}
Exemplo n.º 14
0
Arquivo: screen.c Projeto: hankem/jed
void jed_reset_display (void)
{
   if (Jed_Display_Initialized == 0) return;
   if (Batch) return;

   Jed_Display_Initialized = 0;

#if defined(VMS) || defined(REAL_UNIX_SYSTEM)
   (void) jed_va_run_hooks ("_jed_reset_display_hooks", JED_HOOKS_RUN_ALL, 0);
#endif

   dealloc_display ();
   SLsmg_reset_smg ();
}
Exemplo n.º 15
0
/* this routine should be called after receiving SIGWINCH */
void mutt_resize_screen (void)
{
  char *cp;
  int fd;
  struct winsize w;
#ifdef HAVE_RESIZETERM
  int SLtt_Screen_Rows, SLtt_Screen_Cols;
#endif

  SLtt_Screen_Rows = -1;
  SLtt_Screen_Cols = -1;
  if ((fd = open ("/dev/tty", O_RDONLY)) != -1)
  {
    if (ioctl (fd, TIOCGWINSZ, &w) != -1)
    {
      SLtt_Screen_Rows = w.ws_row;
      SLtt_Screen_Cols = w.ws_col;
    }
    close (fd);
  }
  if (SLtt_Screen_Rows <= 0)
  {
    if ((cp = getenv ("LINES")) != NULL)
    {
      SLtt_Screen_Rows = atoi (cp);
    }
    else
      SLtt_Screen_Rows = 24;
  }
  if (SLtt_Screen_Cols <= 0)
  {
    if ((cp = getenv ("COLUMNS")) != NULL)
      SLtt_Screen_Cols = atoi (cp);
    else
      SLtt_Screen_Cols = 80;
  }
#ifdef USE_SLANG_CURSES
  delwin (stdscr);
  SLsmg_reset_smg ();
  SLsmg_init_smg ();
  stdscr = newwin (0, 0, 0, 0);
  keypad (stdscr, TRUE);
#else
  resizeterm (SLtt_Screen_Rows, SLtt_Screen_Cols);
#endif
}
Exemplo n.º 16
0
static int slang_end_graphics(caca_display_t *dp)
{
    _caca_set_term_title("");
    SLtt_set_mouse_mode(0, 0);
    SLtt_set_cursor_visibility(1);
    SLang_reset_tty();
    SLsig_block_signals();
    SLsmg_reset_smg();
    SLsig_unblock_signals();

#if defined HAVE_GETENV && defined HAVE_PUTENV
    slang_uninstall_terminal(dp);
#endif

    free(dp->drv.p);

    return 0;
}
Exemplo n.º 17
0
/*
 * Nuke SLang
 */
static void Term_nuke_sla(term *t)
{
	if (!slang_on) return;

	/* Show the cursor */
	/* curs_set(1); */

	/* Clear the screen */
	(void)SLsmg_cls();

	/* Refresh */
	SLsmg_refresh();

	/* We are now off */
	slang_on = FALSE;

	/* Shut down */
	SLsmg_reset_smg();
	SLang_reset_tty();
}
Exemplo n.º 18
0
int main(void) {
    SLtt_get_terminfo();

    SLtt_Use_Ansi_Colors = 1;

    SLsmg_init_smg();
    SLang_init_tty(4, 0, 0);

    SLsmg_cls();

    printall(0);
    SLsmg_set_char_set(1);
    printall(40);

    SLsmg_refresh();
    SLang_getkey();

    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
    SLsmg_refresh();
    SLsmg_reset_smg();
    SLang_reset_tty();

    return 0;
}
Exemplo n.º 19
0
void SLangConsole::close() {

  SLsmg_reset_smg();
  SLang_reset_tty();
}
Exemplo n.º 20
0
int main() {
	int i, j;
	int keepRunning;
	int input;
	unsigned int ch;
	int ch2;
	char inputBuffer[40];
	int terminalIndex;
	struct tesiObject *to;

	for(i = 0; i < 10; i++)
		tesiObjects[i] = NULL;

	SLtt_get_terminfo();
	SLang_init_tty(-1, 0, 0);
	SLsmg_init_smg();
	SLsmg_refresh();

	inputBuffer[0] = 0;

	terminalIndex = -1;
	keepRunning = 1;
	while(keepRunning) {
		j = 0;
		for(i = 0; i < 10; i++) {
			if(tesiObjects[i] != NULL)
				j += tesi_handleInput(tesiObjects[i]);
		}
		if(j)
			SLsmg_refresh();

		if(!SLang_input_pending(1)) // wait 1/10 of a second
			continue;
		ch = SLang_getkey();

		switch(ch) {
			case '`': // tilde pressed, cycle through terms?
				terminalIndex++;
				if(terminalIndex == 10 || vtGet(terminalIndex) == NULL)
					terminalIndex = -1;
				// highlight selected terminal
				break;
			case 'Q':
				keepRunning = 0;
				break;
			default:
				if(terminalIndex > -1) { // send input to terminal
					to = vtGet(terminalIndex);
					if(to) // this should never be null, but check anyway
						write(to->fd_input, &ch, 1);

				} else { // build input buffer
#ifdef DEBUG
					fprintf(stderr, "Keypress: %d\n", ch);
#endif
					if(ch == 13) { // parse buffer when Enter is pressed
						// new terminal
						processInput(inputBuffer);
						inputBuffer[0] = 0;

					} else {
						i = strlen(inputBuffer);
						inputBuffer[ i ] = ch;
						inputBuffer[ i + 1 ] = 0;
						SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
						SLsmg_write_string(inputBuffer);
						SLsmg_refresh();
					}
				}
				break;
		}
	}

	for(i = 0; i < 10; i++) {
		if(tesiObjects[i] != NULL) {
			vtDestroy(i);
		}
	}

	SLsmg_reset_smg();
	SLang_reset_tty();
	return 0;
}
Exemplo n.º 21
0
/*
 * Prepare "S-Lang" for use by the file "z-term.c"
 * Installs the "hook" functions defined above
 */
errr init_sla(int argc, char **argv)
{
	int err;

	term *t = &term_screen_body;

	/* Unused parameters */
	(void)argc;
	(void)argv;

	/* Block signals, so signals cannot confuse the setup */
	SLsig_block_signals();

	/* Initialize, check for errors */
	err = (SLang_init_tty(-1, TRUE, 0) == -1);

	/* Quit on error */
	if (err) quit("SLang initialization failed");

	/* Get terminal info */
	SLtt_get_terminfo();

#ifdef HANDLE_SIGNALS
	/* Allow keyboard generated suspend signal (on Unix, ^Z) */
	SLtty_set_suspend_state(TRUE);

	/* Instead of signal(), use sigaction():SA_RESTART via SLsignal() */
	signal_aux = SLsignal;
#endif

	/* Initialize some more */
	if (SLsmg_init_smg() == -1)
	{
		SLang_reset_tty();
		quit("Could not get virtual display memory");
	}

	/* Check we have enough screen. */
	err = ((SLtt_Screen_Rows < 24) || (SLtt_Screen_Cols < 80));

	/* Quit with message */
	if (err)
	{
		SLsmg_reset_smg();
		SLang_reset_tty();
		quit("SLang screen must be at least 80x24");
	}

	/* Now let's go for a little bit of color! */
	err = !has_colors();

	/* Do we have color available? */
	can_use_color = !err;

	/* Init the Color-pairs and set up a translation table */
	/* If the terminal has enough colors */
	/* Color-pair 0 is *always* WHITE on BLACK */

	/* XXX XXX XXX See "main-gcu.c" for proper method */

	/* Only do this on color machines */
	if (can_use_color)
	{
		/* Prepare the color pairs */
		init_pair(1, COLOR_RED,     COLOR_BLACK);
		init_pair(2, COLOR_GREEN,   COLOR_BLACK);
		init_pair(3, COLOR_YELLOW,  COLOR_BLACK);
		init_pair(4, COLOR_BLUE,    COLOR_BLACK);
		init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
		init_pair(6, COLOR_CYAN,    COLOR_BLACK);
		init_pair(7, COLOR_BLACK,   COLOR_BLACK);
		init_pair(9, COLOR_BRED,    COLOR_BLACK);
		init_pair(10, COLOR_BGREEN,   COLOR_BLACK);
		init_pair(11, COLOR_BYELLOW,  COLOR_BLACK);
		init_pair(12, COLOR_BBLUE,    COLOR_BLACK);
		init_pair(13, COLOR_BMAGENTA, COLOR_BLACK);
		init_pair(14, COLOR_BCYAN,    COLOR_BLACK);
		init_pair(15, COLOR_BBLACK,   COLOR_BLACK);

		/* Prepare the color table */
		colortable[0] = 7;       /* Black */
		colortable[1] = 0;       /* White */
		colortable[2] = 6;       /* Grey XXX */
		colortable[3] = 11;      /* Orange XXX */
		colortable[4] = 1;       /* Red */
		colortable[5] = 2;       /* Green */
		colortable[6] = 4;       /* Blue */
		colortable[7] = 3;       /* Brown */
		colortable[8] = 15;      /* Dark-grey XXX */
		colortable[9] = 14;      /* Light-grey XXX */
		colortable[10] = 5;       /* Purple */
		colortable[11] = 11;      /* Yellow */
		colortable[12] = 9;       /* Light Red */
		colortable[13] = 10;      /* Light Green */
		colortable[14] = 12;      /* Light Blue */
		colortable[15] = 3;       /* Light Brown XXX */
	}

	/* Done with blocking */
	SLsig_unblock_signals();

	/* Initialize the term */
	term_init(t, 80, 24, 64);

	/* Stick in some hooks */
	t->nuke_hook = Term_nuke_sla;
	t->init_hook = Term_init_sla;

	/* Stick in some more hooks */
	t->xtra_hook = Term_xtra_sla;
	t->curs_hook = Term_curs_sla;
	t->wipe_hook = Term_wipe_sla;
	t->text_hook = Term_text_sla;

	/* Save the term */
	term_screen = t;

	/* Activate it */
	Term_activate(t);


	/* Success */
	return 0;
}
Exemplo n.º 22
0
Arquivo: slang.c Projeto: rdebath/sgt
void display_cleanup(void)
{
    SLsmg_reset_smg ();
    SLang_reset_tty ();
}
Exemplo n.º 23
0
int
tty_reset_screen (void)
{
    SLsmg_reset_smg ();
    return 0;                   /* OK */
}
Exemplo n.º 24
0
Arquivo: slang.c Projeto: rdebath/sgt
void display_recheck_size(void)
{
    SLsmg_reset_smg ();
    get_screen_size ();
    SLsmg_init_smg ();
}
Exemplo n.º 25
0
static int sl_output(int port, char *buf, int len)
{
    int x,y,z,v,w;
    char *str, *t1, *t2, *t3;
    int ret;
    char ch;


    /* check for signals */

    if (signal_cought != 0) {  /* async out signal */
	char xxx[5];

	xxx[0] = 0;
	put_int32(signal_cought, xxx+1);
	driver_output(port, xxx, 5);
	signal_cought = 0;
    }

    switch (*buf++) {
    case INIT_TTY: {
	int abort_char, flow_ctl, opost;
	abort_char = get_int32(buf); buf+=4;
	flow_ctl = get_int32(buf); buf+= 4;
	opost = get_int32(buf); buf+= 4;
	ret = SLang_init_tty (abort_char,flow_ctl, opost);
	return ret_int(port, ret);
    }
    
    case SET_ABORT_FUNCTION: {
	SLang_set_abort_signal (NULL);
	return ret_int(port, 0);
    }
    case GETKEY: {
	unsigned int key;
	if (SLang_input_pending (0) == 0) {
	    wait_for = GETKEY;
	    driver_select(port, 0, DO_READ, 1);
	    return 0;
	}
	x = SLang_getkey ();
	return ret_int(port, x);
    }
    /* read a symbol */
    case KP_GETKEY: {
	if (SLang_input_pending (0) == 0) {
	    wait_for = KP_GETKEY;
	    driver_select(port, 0, DO_READ, 1);
	    return 0;
	}
	x = SLkp_getkey ();
	return ret_int(port, x);
    }
    case UNGETKEY: {
	unsigned char  key =  (unsigned char) *buf;
	SLang_ungetkey (key); 
	return 0;
    }
    case RESET_TTY: {
	SLang_reset_tty();
	return 0;
    }
    case KP_INIT: {
	return ret_int(port, SLkp_init ());
    }
    case SETVAR: {
	x = get_int32(buf);buf+= 4;
	y = get_int32(buf);
	switch (x) {
	case  esl_baud_rate:
	    SLang_TT_Baud_Rate = y; return 0;
	case esl_read_fd:
	    return 0;
	case esl_abort_char:
	    SLang_Abort_Char = y; return 0;
	case esl_ignore_user_abort:
	    SLang_Ignore_User_Abort=y; return 0;
	case esl_input_buffer_len :
	    SLang_Input_Buffer_Len=y; return 0;
	case  esl_keyboard_quit:
	    SLKeyBoard_Quit=y; return 0;
	case esl_last_key_char:
	    SLang_Last_Key_Char=y; return 0;
	case esl_rl_eof_char:
	    SLang_RL_EOF_Char=y; return 0;
	case esl_rline_quit:
	    SLang_Rline_Quit=y; return 0;
	case esl_screen_rows:
	case  esl_screen_cols :
	    return 0;
	case esl_tab_width:
	    SLsmg_Tab_Width=y; return 0;
	case  esl_newline_behaviour:
	    SLsmg_Newline_Behavior=y; return 0;
	case esl_error:
	    SLang_Error=y; return 0;
	case esl_version:
	    return 0;
	case  esl_backspace_moves :
	    SLsmg_Backspace_Moves=y; return 0;
	case esl_display_eight_bit:
	    SLsmg_Display_Eight_Bit=y; return 0;
	default:
	    return 0;
	}
    }

    case GETVAR: {
	x = get_int32(buf);
	switch (x) {
	case  esl_baud_rate:
	    return ret_int(port, SLang_TT_Baud_Rate);
	case esl_read_fd:
	    return ret_int(port,  SLang_TT_Read_FD);
	case esl_abort_char:
	    return (ret_int(port, SLang_Abort_Char));
	case esl_ignore_user_abort:
	    return ret_int(port, SLang_Ignore_User_Abort);
	case esl_input_buffer_len :
	    return ret_int(port, SLang_Input_Buffer_Len);
	case  esl_keyboard_quit:
	    return ret_int(port, SLKeyBoard_Quit);
	case esl_last_key_char:
	    return ret_int(port, SLang_Last_Key_Char);
	case esl_rl_eof_char:
	    return ret_int(port, SLang_RL_EOF_Char);
	case esl_rline_quit:
	    return ret_int(port, SLang_Rline_Quit);
	case esl_screen_rows:
	    return ret_int(port, SLtt_Screen_Rows);
	case  esl_screen_cols :
	    return ret_int(port, SLtt_Screen_Cols);
	case esl_tab_width:
	    return ret_int(port, SLsmg_Tab_Width);
	case  esl_newline_behaviour:
	    return ret_int(port, SLsmg_Newline_Behavior);
	case esl_error:
	    return ret_int(port, SLang_Error);
	case esl_version:
	    return ret_int(port, SLang_Version); 
	case  esl_backspace_moves :
	    return ret_int(port, SLsmg_Backspace_Moves);
	case esl_display_eight_bit:
	    return  ret_int(port, SLsmg_Display_Eight_Bit);
	default:
	    return ret_int(port, -1);
	}
    }
	    


    /*{{{ SLsmg Screen Management Functions */


    
    case SMG_FILL_REGION: {
	x = get_int32(buf); buf+= 4;
	y =  get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	ch = *buf;
	SLsmg_fill_region(x, y,z,v,ch);
	return 0;
    }			  
    case SMG_SET_CHAR_SET: {
	x = get_int32(buf); buf+= 4;
	SLsmg_set_char_set(x);
	return 0;
    }			
    case SMG_SUSPEND_SMG: {
	return ret_int(port, SLsmg_suspend_smg());
    }				  
    case SMG_RESUME_SMG: {
	ret_int(port, SLsmg_resume_smg());
    }				     
    case SMG_ERASE_EOL: {
	SLsmg_erase_eol();
	return 0;
    }					
    case SMG_GOTORC: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	SLsmg_gotorc(x,  y);
	return 0;
    }					 
    case SMG_ERASE_EOS: {
	SLsmg_erase_eos();
	return 0;
    }						
    case SMG_REVERSE_VIDEO: {
	SLsmg_reverse_video();
	return 0;
    }							
    case SMG_SET_COLOR: {
	x = get_int32(buf); buf+= 4;
	SLsmg_set_color(x);
	return 0;
    }							
    case SMG_NORMAL_VIDEO: {
	SLsmg_normal_video();
	return 0;
    }							
    case SMG_WRITE_STRING: {
	SLsmg_write_string(buf);
	return 0;
    }									   
    case SMG_WRITE_CHAR: {
	ch = *buf;
	SLsmg_write_char(ch);
	return 0;
    }
    case SMG_WRITE_WRAPPED_STRING: {
	t1 = buf;
	buf += strlen(t1) + 1;
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	w = get_int32(buf); buf+= 4;
	SLsmg_write_wrapped_string(t1, x,y,z,v,w);
	return 0;
    }												   
    case SMG_CLS: {
	SLsmg_cls();
	return 0;
    }									
    case SMG_REFRESH: {
	SLsmg_refresh();
	return 0;
    }										
    case SMG_TOUCH_LINES: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	SLsmg_touch_lines(x, y);
	return 0;
    }											
    case SMG_TOUCH_SCREEN: {
#if (SLANG_VERSION < 10400 )
	return ret_int(port, -1);
#else
	SLsmg_touch_screen();
#endif
	return 0;
    }													   
    case SMG_INIT_SMG: {
	return ret_int(port,  SLsmg_init_smg());
    }													   
    case SMG_REINIT_SMG: {
#if (SLANG_VERSION < 10400 )
	return ret_int(port, -1);
#else
	return ret_int(port, SLsmg_reinit_smg());
#endif
    }														 
    case SMG_RESET_SMG: {
	SLsmg_reset_smg();
	return 0;
    }														    
    case SMG_CHAR_AT: {
	return ret_int(port, SLsmg_char_at());
    }														     
    case SMG_SET_SCREEN_START: {
	int *ip1, *ip2;
	*ip1 = get_int32(buf); buf+= 4;
	*ip2 = get_int32(buf); buf+= 4;

	SLsmg_set_screen_start(ip1, ip2);
	return ret_int_int(port, *ip1, *ip2);
    }
    case SMG_DRAW_HLINE: {
	x = get_int32(buf); buf+= 4;
	SLsmg_draw_hline(x);
	return 0;
    }																 
    case SMG_DRAW_VLINE: {
	x = get_int32(buf); buf+= 4;
	SLsmg_draw_vline(x);
	return 0;
    }																     
    case SMG_DRAW_OBJECT: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	x = get_int32(buf); buf+= 4;
	SLsmg_draw_object(x, y,z);
	return 0;
    }																	  
    case SMG_DRAW_BOX: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	SLsmg_draw_box(x, y,z,v);
	return 0;
    }																	   
    case SMG_GET_COLUMN: {
	return ret_int(port, SLsmg_get_column());
    }																		
    case SMG_GET_ROW: {
	return ret_int(port, SLsmg_get_row());
    }		

    case SMG_FORWARD: {
	x = get_int32(buf); buf+= 4;
	SLsmg_forward(x);
	return 0;
    }							
    case SMG_WRITE_COLOR_CHARS: {
	SLsmg_Char_Type * sl;
	sl = decode_smg_char_type(&buf);
	x = get_int32(buf); buf+= 4;
	SLsmg_write_color_chars(sl, x);
	return 0;
    }		
    case SMG_READ_RAW: {
	x = get_int32(buf); buf+= 4;
	t1 = malloc((2*x) + 2 + 1);
	y = SLsmg_read_raw((unsigned short*)t1 +1, x);
	t1[1] = 1;
	driver_output(port, t1, y+1);
	free(t1);
	return 0;
    }
    case SMG_WRITE_RAW: {
	SLsmg_Char_Type * sl;
	sl = decode_smg_char_type(&buf);
	x = get_int32(buf); 
	y = SLsmg_write_raw(sl, x);
	return ret_int(port, y);
    }																				
    case SMG_SET_COLOR_IN_REGION: {
	x = get_int32(buf); buf+= 4;
	y = get_int32(buf); buf+= 4;
	z = get_int32(buf); buf+= 4;
	v = get_int32(buf); buf+= 4;
	w = get_int32(buf); buf+= 4;
	SLsmg_set_color_in_region(x, y,z,v,w);
	return 0;
    }																				
    
    




    /* all the tt_functions  */

    case TT_FLUSH_OUTPUT: {
	ret = SLtt_flush_output();
	return ret_int(port, ret);
    }
    case TT_SET_SCROLL_REGION: {

	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_set_scroll_region(x, y);
	return 0;
    }
    case TT_RESET_SCROLL_REGION: {
	SLtt_reset_scroll_region();
	return 0;
    }
    case TT_REVERSE_VIDEO: {
	SLtt_reverse_video (get_int32(buf));
	return 0;
    }
    case TT_BOLD_VIDEO: {
	SLtt_begin_insert();
	return 0;
    }
    case TT_BEGIN_INSERT: {
	SLtt_begin_insert();
	return 0;
    }
    case TT_END_INSERT: {
	SLtt_end_insert();
	return 0;
    }
    case TT_DEL_EOL: {
	SLtt_del_eol();
	return 0;
    }
    case TT_GOTO_RC: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_goto_rc (x, y);
	return 0;
    }
    case TT_DELETE_NLINES: {
	SLtt_delete_nlines(get_int32(buf));
	return 0;
    }
    case TT_DELETE_CHAR: {
	SLtt_delete_char();
	return 0;
    }
    case TT_ERASE_LINE: {
	SLtt_erase_line();
	return 0;
    }
    case TT_NORMAL_VIDEO: {
	SLtt_normal_video();
	return 0;
    }
    case TT_CLS: {
	SLtt_cls();
	return 0;
    }
    case TT_BEEP: {
	SLtt_beep();
	return 0;
    }
    case TT_REVERSE_INDEX: {
	SLtt_reverse_index(get_int32(buf));
	return 0;
    }
    case TT_SMART_PUTS: {
	SLsmg_Char_Type *t1 ;
	SLsmg_Char_Type *t2;

	t1 = decode_smg_char_type(&buf);
	t2 = decode_smg_char_type(&buf);
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_smart_puts(t1, t2,x,y);
	return 0;
    }
    case TT_WRITE_STRING: {
	SLtt_write_string (buf);
	return 0;
    }
    case TT_PUTCHAR: {
	SLtt_putchar((char) get_int32(buf));
	return 0;
    }
    case TT_INIT_VIDEO: {
	ret = SLtt_init_video ();
	return ret_int(port, ret);	
    }
    case TT_RESET_VIDEO: {
	SLtt_reset_video ();
	return 0;
    }
    case TT_GET_TERMINFO: {
	SLtt_get_terminfo();
	return 0;
    }
    case TT_GET_SCREEN_SIZE: {
	SLtt_get_screen_size ();
	return 0;
    }
    case TT_SET_CURSOR_VISIBILITY: {
	ret = SLtt_set_cursor_visibility (get_int32(buf));
	return ret_int(port, ret);	
    }
    case TT_SET_MOUSE_MODE: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	ret = SLtt_set_mouse_mode (x,y);
	return ret_int(port, ret);	
    }

    case TT_INITIALIZE: {
	ret =SLtt_initialize (buf);
	return ret_int(port, ret);	
    }
    case TT_ENABLE_CURSOR_KEYS: {
	SLtt_enable_cursor_keys();
	return 0;
    }
    case TT_SET_TERM_VTXXX: {
	
	return 0;
    }
    case TT_SET_COLOR_ESC: {
	x = get_int32(buf); buf+=4;
	SLtt_set_color_esc (x, buf);
	return 0;
    }
    case TT_WIDE_WIDTH: {
	SLtt_narrow_width();
	return 0;
    }
    case TT_NARROW_WIDTH: {
	SLtt_narrow_width();
	return 0;
    }
    case TT_SET_ALT_CHAR_SET: {
	SLtt_set_alt_char_set (get_int32(buf));
	return 0;
    }
    case TT_WRITE_TO_STATUS_LINE: {
	x = get_int32(buf); buf+=4;
	SLtt_write_to_status_line (buf, x);
	return 0;
    }
    case TT_DISABLE_STATUS_LINE: {
	SLtt_disable_status_line ();
	return 0;
    }


    case TT_TGETSTR: {
	str = SLtt_tgetstr (buf);
	return ret_string(port, str);
    }
    case TT_TGETNUM: {
	x = SLtt_tgetnum (buf);
	return ret_int(port, x);
    }
    case TT_TGETFLAG: {
	x = SLtt_tgetflag (buf);
	return  ret_int(port, x);
    }
    case TT_TIGETENT: {
	str = SLtt_tigetent (buf);
	return ret_string(port, str);
    }
    case TT_TIGETSTR: {
	
	return 0;
    }
    case TT_TIGETNUM: {

	return 0;
    }

    case SLTT_GET_COLOR_OBJECT: {
	x = get_int32(buf); buf+=4;
	y = SLtt_get_color_object (x);
	return  ret_int(port, y);
	return 0;
    }
    case TT_SET_COLOR_OBJECT: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_set_color_object (x, y);
	return 0;
    }
    case TT_SET_COLOR: {
	x = get_int32(buf); buf+=4;
	t1 = buf;
	t2 = buf + (strlen(t1) + 1);
	t3 = buf + (strlen(t1) + strlen(t2) + 2);
	SLtt_set_color (x, t1, t2, t3);
	return 0;
    }
    case TT_SET_MONO: {
	x = get_int32(buf); buf+=4;
	t1 = buf;
	buf += strlen(t1) + 1;
	y = get_int32(buf);
	SLtt_set_mono (x, t1, y);
	return 0;
    }
    case TT_ADD_COLOR_ATTRIBUTE: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	SLtt_add_color_attribute (x, y);
	return 0;
    }
    case TT_SET_COLOR_FGBG: {
	x = get_int32(buf); buf+=4;
	y = get_int32(buf); buf+=4;
	z = get_int32(buf); buf+=4;
	SLtt_set_color_fgbg (x, y, z);
	return 0;
    }
    case ISATTY: {
	x = get_int32(buf); buf+=4;
	return ret_int(port, isatty(x));
    }
    case EFORMAT: {
	fprintf(stderr, "%s", buf);
	fflush(stderr);
	return 0;
    }
    case SIGNAL: {
	x = get_int32(buf); buf+=4;
	SLsignal(x_to_sig(x), sig_handler);
	return 0;
    }
    case SIGNAL_CHECK: {
	/* polled */
	if (signal_cought != 0)
	    signal_cought = 0;
	return ret_int(port, signal_cought);
    }

    default:
	return 0;
    }
}
Exemplo n.º 26
0
static void sigint_handler (int sig)
{
   SLang_reset_tty ();
   SLsmg_reset_smg ();
   exit (sig);
}
Exemplo n.º 27
0
int SLcurses_wscrl (SLcurses_Window_Type *w, int n)
{
   SLcurses_Cell_Type **lines;
   unsigned int r0, r1, rmax, rmin, ncols;
   SLsmg_Color_Type color;

   if ((w == NULL) || (w->scroll_ok == 0))
     return -1;

   w->modified = 1;
#if 0
   if (w->is_subwin)
     {
	SLang_reset_tty ();
	SLsmg_reset_smg ();
	fprintf (stderr, "\rAttempt to scroll a subwindow\n");
	exit (1);
     }
#endif

   color = w->color;
   ncols = w->ncols;
   lines = w->lines;
   rmax = w->scroll_max;
   rmin = w->scroll_min;
   if (rmax > w->nrows)
     rmax = w->nrows;
   if ((rmin >= rmax) || (rmax == 0))
     return 0;

   if (n == 0)
     return 0;

   if (n > 0)
     {
	r0 = rmin;
	r1 = rmin + n;

	while (r1 < rmax)
	  {
	     if (w->is_subwin)
	       memcpy ((char *)lines[r0], (char *)lines[r1],
		       sizeof (SLcurses_Cell_Type) * ncols);
	     else
	       {
		  SLcurses_Cell_Type *swap = lines[r0];
		  lines[r0] = lines[r1];
		  lines[r1] = swap;
	       }
	     r0++;
	     r1++;
	  }
	while (r0 < rmax)
	  {
	     blank_line (lines[r0], ncols, color);
	     r0++;
	  }
	return 0;
     }

   /* else n < 0 */
   n = -n;

   r1 = rmax - 1;
   if (r1 < (unsigned int) n)
     n = r1;
   r0 = r1 - n;

   while (r0 >= rmin)
     {
	if (w->is_subwin)
	  memcpy ((char *)lines[r1], (char *)lines[r0],
		  sizeof (SLcurses_Cell_Type) * ncols);
	else
	  {
	     SLcurses_Cell_Type *swap = lines[r1];
	     lines[r1] = lines[r0];
	     lines[r0] = swap;
	  }
	r1--;
	if (r0 == 0)
	  break;
	r0--;
     }
   r0 = rmin;
   while (r0 <= r1)
     {
	blank_line (lines[r0], ncols, color);
	r0++;
     }

   return 0;
}
Exemplo n.º 28
0
int main() {
	TerminalIO *tio;
	VTCore *vt;
	VTScreenView *view;

	char *argv[] = {"/bin/bash", 0};
	//char input[65];
	unsigned int input;
	char ch[2];
	int fd;
	fd_set fileDescriptors;
	struct timeval timeout;

	// Initialize Terminal
	SLtt_get_terminfo ();
	SLang_init_tty (-1, 0, 0);
	SLsmg_init_smg ();
	SLsmg_refresh();

	// iTerm Setup
	// new iTerm TerminalIO object
	tio = TtyTerminalIO_new(SLtt_Screen_Cols, SLtt_Screen_Rows, "/bin/bash", argv); // width, height, program, argv
	if(tio == NULL) {
		printf("Error initializing TerminalIO\n");
		return 1;
	}

	// new Virtual Terminal Screen View object
	view = malloc (sizeof (VTScreenView));
	if (view == NULL) {
		perror ("VTScreenView_new");
		return 1;
	}

	VTScreenView_init (view);
	view->draw_text = vtDrawText;
	view->update_cursor_position = vtMoveCursor;
	view->clear_rect = vtClearRect;
	view->scroll_view = vtScroll;


	// Start the iTerm core
	vt = VTCore_new(tio, SLtt_Screen_Cols, SLtt_Screen_Rows, 10); // terminalIO, cols, rows, history
	if(vt == NULL) {
		printf("Error initializing VTCore\n");
		return 1;
	}

	// Tell the core with view to use ... can we have multiple?
	VTCore_set_screen_view(vt, view);

	timeout.tv_sec = 0;
	timeout.tv_usec = 100000;
	fd = TtyTerminalIO_get_associated_fd(tio);

	while(1) {
		FD_ZERO(&fileDescriptors);
		FD_SET(0, &fileDescriptors);
		FD_SET( TtyTerminalIO_get_associated_fd(tio), &fileDescriptors);
		timeout.tv_sec = 0;
		timeout.tv_usec = 100000;
		select(fd + 1, &fileDescriptors, NULL, NULL, &timeout); 

		if(FD_ISSET(fd, &fileDescriptors)) {
			VTCore_dispatch(vt);
			SLsmg_refresh();
		}
		if(FD_ISSET(0, &fileDescriptors)) {
			input = SLang_getkey();

			//printf("input: %c\n", (char)input);
			ch[0] = (char) input;
			ch[1] = 0;

			write(fd, &ch, 1);

			if(ch[0] == 'Q')
				break;
		}
	}
		

	free(view);
	VTCore_destroy(vt);
	TtyTerminalIO_destroy(tio);

	// Shut down s-lang IO
	SLsmg_reset_smg ();
	SLang_reset_tty ();

	return 0;
}
Exemplo n.º 29
0
int main() {
    int i, j, k, screenHeight, screenWidth;
    int input;
    unsigned int ch;
    char *boundString;
    int ch2;
    char inputBuffer[40];
    int terminalIndex, fdMax;
    fd_set fileDescriptors;
    struct timespec timeout;
    //struct tesiObject *to;
    struct virtualTerminal *vt;

    for(i = 0; i < 10; i++)
        virtualTerminals[i] = NULL;

    fdMax = 0;
    timeout.tv_sec = 0;
    timeout.tv_nsec = 50000000; // 10E-9

#ifdef USE_NCURSES
    ncursesScreen = initscr();
    if(ncursesScreen == NULL) {
        perror("Error initializing nCurses\n");
        exit(1);
    }

    if(has_colors()) {
        start_color();
#ifdef DEBUG
        fprintf(stderr, "max colors: %d\n", COLORS);
        fprintf(stderr, "max color pairs: %d\n", COLOR_PAIRS);
#endif
        k = 1;
        for(i = 0; i < COLORS; i++) {
            for(j = 0; j < COLORS; j++) {
                vt_colors[i][j] = k;
                init_pair(k, i, j);
                k++;
            }
        }
        //init all color pairs
        /*
         * black red green yellow blue magenta cyan white
         * attributes 30-37
         * in iterm, black starts at 1
         * */
    }

    keypad(ncursesScreen, true); // cause nCurses to package key combos into special, single values
    nodelay(ncursesScreen, TRUE); // return immediately if no input is waiting
    raw();
    noecho(); // don't echo input
    refresh(); // clear the main window

    // Get main window dimensions. This will be used when creating additional virtual terminals
    getmaxyx(ncursesScreen, screenHeight, screenWidth);
#endif

    inputBuffer[0] = 0;
    mvwaddstr(ncursesScreen, screenHeight - 1, 0, ":");

    mvwaddstr(ncursesScreen, 1, 0, "USING KNOX\n\nCommands\n\t\"create\" - creates a new Virtual Terminal\n\t\"create #\" - create # number of new Virtual Terminals\n\t\"NUMBER\" - sets focus to so numbered terminal\n\t\"NUMBER COMMAND\" - sends COMMAND to numbered terminal followed by newline");
    wmove(ncursesScreen, screenHeight - 1, 1);

    terminalIndex = -1;
    keepRunning = 1;
    k = 0;
    while(keepRunning) {
        FD_ZERO(&fileDescriptors);
        for(i = 0; i < 10; i++) {
            //if(vtGet(i) != NULL && tesi_handleInput(vtGet(i))) {
            vt = vtGet(i);
            if(vt && vt->fd != -1) {
                if(vt->fd > fdMax)
                    fdMax = vt->fd;
                FD_SET(vt->fd, &fileDescriptors);
            }
        }

        pselect(fdMax + 1, &fileDescriptors, NULL, NULL, &timeout, NULL);
        j = 0;
        for(i = 0; i < 10; i++) {
            //if(vtGet(i) != NULL && tesi_handleInput(vtGet(i))) {
            vt = vtGet(i);
            if(vt != NULL && vt->fd != -1 && FD_ISSET(vt->fd, &fileDescriptors)) {
                VTCore_dispatch(vt->core);
#ifdef USE_NCURSES
                //vt = (struct virtualTerminal*) vtGet(i)->pointer;
                wnoutrefresh(vt->window);
#endif
                j++; // keep track of the terminals that need updating
            }
        }
        if(j || k) { // if a VT or command window needs updating
#ifdef USE_NCURSES
            // re-move cursor to correct location after updating screens
            if(terminalIndex > -1) {
                //to = (struct tesiObject*) vtGet(terminalIndex);
                //vt = (struct virtualTerminal*) to->pointer;
                vt = vtGet(terminalIndex);
                //wmove(vt->window, to->y, to->x);
            } else {
                wmove(ncursesScreen, screenHeight - 1, 1 + strlen(inputBuffer));
            }

            doupdate();
        }
        k = 0;
        ch = wgetch(ncursesScreen); // ?
#endif
#ifdef USE_SLANG
        SLsmg_refresh();
        if(!SLang_input_pending(1)) // wait 1/10 of a second
            continue;
        ch = SLang_getkey();
#endif

#ifdef USE_NCURSES
#endif

        switch(ch) {
        case '`': // tilde pressed, cycle through terms?
            //case KEY_RIGHT: // tilde pressed, cycle through terms?
            terminalIndex++;
            if(terminalIndex == 10 || vtGet(terminalIndex) == NULL)
                terminalIndex = -1;
            vtHighlight(terminalIndex);
            k = 1; // update cursor position
            break;
        case ERR: // no input
            break;
        default:
            if(terminalIndex > -1) { // send input to terminal
                //to = vtGet(terminalIndex);
                vt = vtGet(terminalIndex);
                if(vt) { // this should never be null, but check anyway
                    boundString = keybound(ch, 0);
                    if(boundString) {
#ifdef DEBUG
                        fprintf(stderr, "key string: %s\n", boundString);
#endif
                        write(vt->fd, boundString, strlen(boundString));
                        free(boundString);
                    } else
                        write(vt->fd, &ch, 1);

                }

            } else { // build input buffer
#ifdef DEBUG
                fprintf(stderr, "Keypress: %d\n", ch);
#endif
                if(ch == 10) { // parse buffer when Enter is pressed, returns active terminal index
                    //wclear(ncursesScreen);
                    terminalIndex = processInput(inputBuffer, terminalIndex, screenHeight, screenWidth);
                    vtHighlight(terminalIndex);

                    FD_ZERO(&fileDescriptors);
                    FD_SET(0, &fileDescriptors);
#ifdef USE_NCURSES
                    // clear command window
                    mvwaddch(ncursesScreen, screenHeight - 1, 0, ':');
                    wmove(ncursesScreen, screenHeight - 1, 1);
                    wclrtoeol(ncursesScreen);
                    wmove(ncursesScreen, screenHeight - 1, 1);
                    wnoutrefresh(ncursesScreen);
                    k = 1;
#endif
                    inputBuffer[0] = 0;

                } else {
                    i = strlen(inputBuffer);
                    inputBuffer[ i ] = ch;
                    inputBuffer[ i + 1 ] = 0;
#ifdef USE_NCURSES
                    mvwaddstr(ncursesScreen, screenHeight - 1, 1, inputBuffer);
#endif
#ifdef USE_SLANG
                    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
                    SLsmg_write_string(inputBuffer);
                    SLsmg_refresh();
#endif
                }
            }
            break;
        }
    }

    for(i = 0; i < 10; i++) {
        if(virtualTerminals[i] != NULL) {
            vtDestroy(i);
        }
    }

#ifdef USE_NCURSES
    endwin();
#endif
#ifdef USE_SLANG
    SLsmg_reset_smg();
    SLang_reset_tty();
#endif
    return 0;
}
Exemplo n.º 30
0
/* this is the main key processing loop for interactive mode */
void display_results_interactively() {

  bool_t done = 0;
  int c, c1;

  /* set up the terminal etc. */
  SLang_init_tty(-1, 0, 0);
  SLtt_get_terminfo();
  if(-1 == SLsmg_init_smg() ) {
    fprintf (stderr, "Unable to initialize terminal.");
    return;
  }
  SLkp_init(); /* for cursor keys */

  SLsignal(SIGWINCH, sigwinch_handler);

  init_disp_state();

  while(!done) {

    redraw_current_state();

    c = SLang_getkey();

    /* if it's a meta combination, translate */
    if( c == '' ) {
      c1 = SLang_getkey();
      switch(c1) {

      case '<':
	c = SL_KEY_HOME;
	break;

      case '>':
	c = SL_KEY_END;
	break;

      case 'v':
      case 'V':
	c = SL_KEY_PPAGE;
	break;

      case 'r':
      case 'R':
	c = '?';
	break;

      case 's':
      case 'S':
	c = '/';
	break;

      default:
	/* could be special cursor keys */
	SLang_ungetkey(c1);
	SLang_ungetkey(c);
	c = SLkp_getkey();
      }
    }

    /* handle key press */
    switch(c) {

    case 'q':
    case 'Q':
      done = 1;
      break;

    case 'c':
      interactive_categorize();
      disp.highlighted = disp.first_visible = 0;
      break;

    case '\r':
    case 'v':
      if( emails.num_limited > 0 ) {
	view_current_email();
      }
      break;

    case SL_KEY_F(1):
      if( emails.num_limited > 0 && disp.fkey_cmd[0] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[0]);
      }
      break;

    case SL_KEY_F(2):
      if( emails.num_limited > 0 && disp.fkey_cmd[1] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[1]);
      }
      break;

    case SL_KEY_F(3):
      if( emails.num_limited > 0 && disp.fkey_cmd[2] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[2]);
      }
      break;

    case SL_KEY_F(4):
      if( emails.num_limited > 0 && disp.fkey_cmd[3] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[3]);
      }
      break;

    case SL_KEY_F(5):
      if( emails.num_limited > 0 && disp.fkey_cmd[4] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[4]);
      }
      break;

    case SL_KEY_F(6):
      if( emails.num_limited > 0 && disp.fkey_cmd[5] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[5]);
      }
      break;

    case SL_KEY_F(7):
      if( emails.num_limited > 0 && disp.fkey_cmd[6] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[6]);
      }
      break;

    case SL_KEY_F(8):
      if( emails.num_limited > 0 && disp.fkey_cmd[7] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[7]);
      }
      break;

    case SL_KEY_F(9):
      if( emails.num_limited > 0 && disp.fkey_cmd[8] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[8]);
      }
      break;

    case SL_KEY_F(10):
      if( emails.num_limited > 0 && disp.fkey_cmd[9] ) {
	interactive_pipe_all_tagged(disp.fkey_cmd[9]);
      }
      break;

    case 's':
      if( emails.num_limited > 0 ) {
	interactive_pipe_current("");
      }
      break;

    case 'S':
      if( emails.num_limited > 0 ) {
	interactive_pipe_all_tagged("");
      }
      break;

    case 'o':
      if( ++emails.score_type >= MAX_SCORES ) {
	emails.score_type = 0;
      }
      qsort(emails.list, emails.num_emails, sizeof(mbox_item), compare_scores);
      recalculate_limited();
      break;

    case 'p':
      if( ++emails.index_format >= MAX_FORMATS ) {
	emails.index_format = 0;
      }
      break;

    case 't':
      if( emails.num_limited > 0 ) {
	tag_current(1);
      }
      break;

    case 'T':
      if( emails.num_limited > 0 ) {
	tag_all_limited(1);
      }
      break;

    case 'u':
      if( emails.num_limited > 0 ) {
	tag_current(0);
      }
      break;

    case 'U':
      if( emails.num_limited > 0 ) {
	tag_all_limited(0);
      }
      break;

    case 'z':
      reverse_sort();
      recalculate_limited();
      break;

    case 'G':
    case SL_KEY_END:
      if( emails.num_limited > 0 ) {
	disp.first_visible = emails.num_limited - 1;
      } else {
	disp.highlighted = disp.first_visible = 0;
      }
      break;

    case '1':
    case SL_KEY_HOME:
      disp.first_visible = 0;
      break;

    case '':
    case SL_KEY_PPAGE:
      if( disp.first_visible > disp.num_rows )
	{ disp.first_visible -= disp.num_rows; }
      else
	{ disp.first_visible = 0; disp.highlighted = 0; }

      /* assert emails.num_limited >= disp.first_visible */
      if( disp.highlighted > (emails.num_limited - disp.first_visible) ) {
	disp.highlighted = (emails.num_limited - disp.first_visible);
      }
      break;

    case 'k':
    case '':
    case SL_KEY_UP:
      if( disp.highlighted > 0 ) {
	disp.highlighted--;
      } else {
	if( disp.first_visible > 1 ) 
	  { disp.first_visible -= 1; }
	else
	  { disp.first_visible = 0; }
      }
      break;

    case 'j':
    case '':
    case SL_KEY_DOWN:
      if( emails.num_limited > 0 ) {
	if( disp.highlighted < (emails.num_limited - disp.first_visible - 1) ) {
	  if( disp.highlighted < (disp.num_rows - 3) ) {
	    disp.highlighted++;
	  } else {
	    if( (disp.first_visible += 1) >= emails.num_limited ) 
	      { disp.first_visible = emails.num_limited - 1; }
	  }
	}
      } else {
	disp.highlighted = disp.first_visible = 0;
      }
      break;

    case '':
    case '':
    case ' ':
    case SL_KEY_NPAGE:
      if( emails.num_limited > 0 ) {
	if( (disp.first_visible += disp.num_rows) >= emails.num_limited ) 
	  { disp.first_visible = emails.num_limited - 1; }

	if( disp.highlighted > (emails.num_limited - disp.first_visible) ) {
	  disp.highlighted = (emails.num_limited - disp.first_visible) - 1;
	}
      } else {
	disp.highlighted = disp.first_visible = 0;
      }
      break;

    case '?':
      interactive_search(0, "");
      disp.highlighted = disp.first_visible = 0;
      break;
    case '/':
      interactive_search(1, "");
      disp.highlighted = disp.first_visible = 0;
      break;

    default:
      break;
    }

  }

  /* we're done */
  SLsmg_reset_smg();
  SLang_reset_tty();
}