Beispiel #1
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;

		/* Block further signals, so double signals wont confuse us */
		SLsig_block_signals();

		/* Shut down (temporarily) */
		if (SLsmg_suspend_smg() < 0)
			quit("Could not save S-Lang state");
		SLang_reset_tty();

		/* Done with blocking */
		SLsig_unblock_signals();
	}

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

		/* Block further signals, so double signals wont confuse us */
		SLsig_block_signals();

		/* Initialize, check for errors */
		if (SLang_init_tty(-1, TRUE, 0) == -1)
		    quit("S-Lang re-initialization failed");

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

		/* Restore the and screen and screen management state */
		if (SLsmg_resume_smg() == -1)
		{
		    SLang_reset_tty();
		    quit("Could not get back virtual display memory");
		}

		/* Done with blocking */
		SLsig_unblock_signals();

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

	/* Success */
	return (0);
}
Beispiel #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);
}
Beispiel #3
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;
}
Beispiel #4
0
static int example_3 (void)
{
   SLrline_Type *rl;
   unsigned int width = 80;

   if ((-1 == SLang_init_all ())
       || (-1 == SLang_init_array_extra ())
       || (-1 == SLang_init_import ()))
     return -1;

   (void) SLpath_set_load_path ("../slsh/lib");

   if (-1 == SLrline_init ("demo/rline", NULL, NULL))
     return -1;

   issue_instructions ();

   SLang_init_tty (-1, 0, 1);
   SLang_set_abort_signal (NULL);

   rl = SLrline_open2 ("rline", width, SL_RLINE_BLINK_MATCH);
   if (rl == NULL)
     return -1;

   while (1)
     {
	char *line;
	unsigned int len;

	line = SLrline_read_line (rl, "prompt>", &len);
	if (line == NULL)
	  {
	     int err = SLang_get_error ();
	     if (err == SL_UserBreak_Error)
	       {
		  (void) fprintf (stderr, "*Interrupted*\n");
		  SLang_set_error (0);
		  SLKeyBoard_Quit = 0;
		  continue;
	       }
	     if (err == 0)
	       break;		       /* EOF */
	     fprintf (stderr, "Error Occurred: %s\n", SLerr_strerror (err));
	     break;
	  }
	if (0 == strcmp (line, "quit"))
	  {
	     SLfree (line);
	     break;
	  }
	(void) fprintf (stdout, "\nRead %d bytes: %s\n", strlen(line), line);
	if (-1 == SLrline_save_line (rl))
	  break;

	SLfree (line);
     }
   SLrline_close (rl);
   SLang_reset_tty ();
   return 0;
}
Beispiel #5
0
static int example_1 (void)
{
   SLrline_Type *rl;
   unsigned int width = 80;

   issue_instructions ();

   SLang_init_tty (-1, 0, 1);
   rl = SLrline_open (width, SL_RLINE_BLINK_MATCH);

   while (1)
     {
	char *line;
	unsigned int len;

	line = SLrline_read_line (rl, "prompt>", &len);
	if (line == NULL)
	  break;
	if (0 == strcmp (line, "quit"))
	  {
	     SLfree (line);
	     break;
	  }
	(void) fprintf (stdout, "\nRead %d bytes: %s\n", strlen(line), line);
	SLfree (line);
     }
   SLrline_close (rl);
   SLang_reset_tty ();
   return 0;
}
Beispiel #6
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();

    /* heart of the program goes here */

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

    return 0;
}
Beispiel #7
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;
}
Beispiel #8
0
int SLcurses_endwin (void)
{
   SLcurses_Is_Endwin = 1;
   SLsmg_suspend_smg ();
   SLang_reset_tty ();
   return 0;
}
Beispiel #9
0
static void slang_uninit(aa_context * c)
{
    if (uninitslang) {
	uninitslang = 0;
	__slang_is_up = 0;
    }
    SLang_reset_tty();
}
int newtFinished(void) {
    SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
    newtCursorOn();
    SLsmg_refresh();
    SLsmg_reset_smg();
    SLang_reset_tty();

    return 0;
}
Beispiel #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;
    }
}
Beispiel #12
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);
}
Beispiel #13
0
static void sigtstp_handler (int sig)
{
   sig = errno;

   SLsmg_suspend_smg ();

   if (TTY_State)
     SLang_reset_tty ();

   kill(getpid(),SIGSTOP);

   SLsmg_resume_smg ();

   if (TTY_State) init_tty (TTY_State - 1);

   signal (SIGTSTP, sigtstp_handler);
   errno = sig;
}
Beispiel #14
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;
}
Beispiel #15
0
static void reset_tty (void)
{
    if (TTY_Inited == 0)
        return;

    TTY_Inited--;

    if (TTY_Inited)
        return;

# if SYSTEM_SUPPORTS_SIGNALS
    SLsig_block_signals ();
    deinit_sigtstp ();
# endif
    SLang_reset_tty ();
# if SYSTEM_SUPPORTS_SIGNALS
    SLsig_unblock_signals ();
# endif
}
Beispiel #16
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();
}
Beispiel #17
0
static void reset_tty (void)
{
   if (TTY_Inited == 0)
     return;
   TTY_Inited = 0;
# if SYSTEM_SUPPORTS_SIGNALS
   SLsig_block_signals ();
   SLsignal (SIGTSTP, last_sig_sigtstp);
# endif
   SLang_reset_tty ();
# if SYSTEM_SUPPORTS_SIGNALS
   SLsig_unblock_signals ();
# endif
   /* Add a \r here to work around what I believe is a solaris kernel bug.
    * The terminal is being reset by SLang_reset_tty which uses TCSADRAIN
    * option.  However, that is not supposed to affect output after that
    * call is made (like the output below), but it does.
    */
   fputs ("\r\n", stdout);
   fflush (stdout);
}
Beispiel #18
0
void display_setup(void)
{
    SLtt_get_terminfo();

    if (SLang_init_tty (ABORT, 1, 0) == -1) {
	fprintf(stderr, "tweak: SLang_init_tty: returned error code\n");
	exit (1);
    }
    SLang_set_abort_signal (NULL);
    SLtt_Use_Ansi_Colors = TRUE;

    get_screen_size ();
    if (SLsmg_init_smg () < 0) {
	fprintf(stderr, "tweak: SLsmg_init_smg: returned error code\n");
	SLang_reset_tty ();
	exit (1);
    }

#if defined(unix) && !defined(GO32)
    signal (SIGWINCH, (void *) sigwinch);
#endif
}
Beispiel #19
0
int main(void) {
    int i;
    char * buf;

    SLtt_get_terminfo();
    SLang_init_tty(4, 0, 0);

    buf = SLtt_tgetstr("ku");
    if (!buf) {
	printf("termcap entry not found for kl\n\r");
    } else {
	printf("termcap entry found for kl: %s", buf);
	while (*buf) {
	    printf("0x%02x ", *buf++);
	}
	printf("\n\r");
    }

    printf("\n\r");

    printf("Press a key: ");
    fflush(stdout);
   
    SLang_input_pending(50);

    printf("\n\r");
    printf("You pressed: ");

    while (SLang_input_pending(1)) {
	i = SLang_getkey();
	printf("0x%02x ", i);
    }

    printf("\n\r");

    SLang_reset_tty();
    return 0;
}
Beispiel #20
0
void
tty_shutdown (void)
{
    char *op_cap;

    disable_mouse ();
    tty_reset_shell_mode ();
    tty_noraw_mode ();
    tty_keypad (FALSE);
    tty_reset_screen ();
    do_exit_ca_mode ();
    SLang_reset_tty ();

    /* Load the op capability to reset the colors to those that were 
     * active when the program was started up 
     */
    op_cap = SLtt_tgetstr ((char *) "op");
    if (op_cap != NULL)
    {
        fputs (op_cap, stdout);
        fflush (stdout);
    }
}
Beispiel #21
0
static void reset_tty (void) /*{{{*/
{
#ifdef HAVE_GNU_READLINE
   if (Use_SLang_Readline == 0)
     {
        SLsig_block_signals ();
        SLsignal (SIGINT, last_sig_sigint);
        SLsignal (SIGTSTP, last_sig_sigtstp);
        SLsig_unblock_signals ();
        return;
     }
#endif

   if (TTY_Inited == 0)
     return;
   TTY_Inited = 0;

   SLsig_block_signals ();
   SLsignal (SIGTSTP, last_sig_sigtstp);
   SLang_reset_tty ();
   SLsig_unblock_signals ();
   fputs ("\r\n", stdout);   /* need this with buggy Linux rlogin? */
   fflush (stdout);
}
Beispiel #22
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;
}
Beispiel #23
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;
}
Beispiel #24
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();
}
Beispiel #25
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;
}
Beispiel #26
0
void SLangConsole::close() {

  SLsmg_reset_smg();
  SLang_reset_tty();
}
Beispiel #27
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;
}
Beispiel #28
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;
}
Beispiel #29
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;
}
Beispiel #30
0
static void sigint_handler (int sig)
{
   SLang_reset_tty ();
   SLsmg_reset_smg ();
   exit (sig);
}