示例#1
0
文件: shelldlg.c 项目: LeSpocky/eis
/* ---------------------------------------------------------------------
 * ShellDlgCreateHook
 * Create dialog controls
 * ---------------------------------------------------------------------
 */
static void
ShellDlgCreateHook(void* w)
{
	CUIWINDOW* win = (CUIWINDOW*) w;
	CUIWINDOW* ctrl;
	SHELLDLGDATA* data = (SHELLDLGDATA*) win->InstData;
	CUIRECT rc;

	WindowGetClientRect(win, &rc);

	ctrl = TerminalNew(win,
		data->pTitle ? data->pTitle : L"",
		rc.X, rc.Y, rc.W, rc.H,
		IDC_TERMINAL,
		CWS_NONE, CWS_NONE);
	WindowCreate(ctrl);
	TerminalSetCoProcExitHook(ctrl, ShellDlgCoProcExitHook, win);

	if (data->pCommand)
	{
		TerminalWrite(ctrl, _T("\033[32m"), wcslen(_T("\033[32m")));
		TerminalWrite(ctrl, data->pCommand, wcslen(data->pCommand));
		TerminalWrite(ctrl, _T("\033[0m\n"), wcslen(_T("\033[0m\n")));
		TerminalRun(ctrl, data->pCommand);
	}
}
示例#2
0
int
ttyflush(int drop)
{
    int n, n0, n1;

    n0 = ring_full_count(&ttyoring);
    if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
	if (drop) {
	    TerminalFlushOutput();
	    /* we leave 'n' alone! */
	} else {
	    n = TerminalWrite(ttyoring.consume, n);
	}
    }
    if (n > 0) {
	if (termdata && n) {
	    Dump('>', ttyoring.consume, n);
	}
	/*
	 * If we wrote everything, and the full count is
	 * larger than what we wrote, then write the
	 * rest of the buffer.
	 */
	if (n1 == n && n0 > n) {
		n1 = n0 - n;
		if (!drop)
			n1 = TerminalWrite(ttyoring.bottom, n1);
		if (n1 > 0)
			n += n1;
	}
	ring_consumed(&ttyoring, n);
    }
    if (n < 0) {
	if (errno == EAGAIN || errno == EINTR) {
	    return -1;
	} else {
	    ring_consumed(&ttyoring, ring_full_count(&ttyoring));
	    setconnmode(0);
	    setcommandmode();
	    NetClose(net);
	    fprintf(stderr, "Write error on local output.\n");
	    exit(1);
	}
	return -1;
    }
    if (n == n0) {
	if (n0)
	    return -1;
	return 0;
    }
    return n0 - n + 1;
}
示例#3
0
int
ttyflush (int drop)
{
  register int n, n0, n1;

  n0 = ring_full_count (&ttyoring);
  if ((n1 = n = ring_full_consecutive (&ttyoring)) > 0)
    {
      if (drop)
	{
	  TerminalFlushOutput ();
	  /* we leave 'n' alone! */
	}
      else
	{
	  n = TerminalWrite ((char *) ttyoring.consume, n);
	}
    }
  if (n > 0)
    {
      if (termdata && n)
	{
	  Dump ('>', ttyoring.consume, n);
	}
      /*
       * If we wrote everything, and the full count is
       * larger than what we wrote, then write the
       * rest of the buffer.
       */
      if (n1 == n && n0 > n)
	{
	  n1 = n0 - n;
	  if (!drop)
	    n1 = TerminalWrite ((char *) ttyoring.bottom, n1);
	  if (n1 > 0)
	    n += n1;
	}
      ring_consumed (&ttyoring, n);
    }
  if (n < 0)
    return -1;
  if (n == n0)
    {
      if (n0)
	return -1;
      return 0;
    }
  return n0 - n + 1;
}
示例#4
0
文件: shelldlg.c 项目: LeSpocky/eis
/* ---------------------------------------------------------------------
 * ShellDlgCoProcExitHook
 * CoProc terminate hook event
 * ---------------------------------------------------------------------
 */
static void 
ShellDlgCoProcExitHook(void* w, void* c, int code)
{
	wchar_t buffer[128 + 1];
	CUIWINDOW* win = (CUIWINDOW*) w;
	
	CUI_USE_ARG(code);

#ifdef BE_VERBOSE
	swprintf(buffer, 128, _T("Terminated with exit code %i"), code);

	TerminalWrite((CUIWINDOW*) c, _T("\033[33m\033[1m"), wcslen(_T("\033[33m\033[1m")));
	TerminalWrite((CUIWINDOW*) c, buffer, wcslen(buffer));
	TerminalWrite((CUIWINDOW*) c, _T("\033[0m\n"), wcslen(_T("\033[0m\n")));
#endif

	((SHELLDLGDATA*)win->InstData)->ExitCode = code;
	if ((((SHELLDLGDATA*)win->InstData)->DoAutoClose) && (code == 0))
	{
		WindowClose((CUIWINDOW*) w, IDOK);
	}
	else
	{
		wcscpy(buffer, _T("Press ENTER to continue"));
		TerminalWrite((CUIWINDOW*) c, _T("\033[33m\033[1m"), wcslen(_T("\033[33m\033[1m")));
		TerminalWrite((CUIWINDOW*) c, buffer, wcslen(buffer));
		TerminalWrite((CUIWINDOW*) c, _T("\033[0m"), wcslen(_T("\033[0m")));
	}
}
示例#5
0
文件: terminal.c 项目: LeSpocky/eis
/* ---------------------------------------------------------------------
 * TerminalUpdateView
 * Check if data is available for display
 * ---------------------------------------------------------------------
 */
void
TerminalUpdateView(CUIWINDOW* win)
{
	if (win && (wcscmp(win->Class, _T("TERMINAL")) == 0))
	{
		TERMINALDATA* data = (TERMINALDATA*) win->InstData;
		if (data->CoProc)
		{
			wchar_t buffer[256 + 1];

			int c = TerminalCoRead(data->CoProc, buffer, 255);
			while (c > 0)
			{
				TerminalWrite(win, buffer, c);
				c = TerminalCoRead(data->CoProc, buffer, 255);
			}
		}
	}	
}
示例#6
0
文件: terminal.c 项目: LeSpocky/eis
/* ---------------------------------------------------------------------
 * TerminalTimerHook
 * Handle EVENT_TIMER events
 * ---------------------------------------------------------------------
 */
static void
TerminalTimerHook(void* w, int id)
{
	CUIWINDOW* win = (CUIWINDOW*) w;
	TERMINALDATA* data = (TERMINALDATA*) win->InstData;

	WindowKillTimer(win, id);

	if (data && data->CoProc)
	{
		int exitcode;
		wchar_t buffer[256 + 1];

		int c = TerminalCoRead(data->CoProc, buffer, 255);
		while (c > 0)
		{
			TerminalWrite(win, buffer, c);

			c = TerminalCoRead(data->CoProc, buffer, 255);
		}

		if (TerminalCoIsRunning(data->CoProc, &exitcode))
		{
			WindowSetTimer(win, id, REFRESH_CYCLE);
		}
		else
		{
			TerminalCoDelete(data->CoProc);
			data->CoProc = NULL;

			if (data->CoProcExitHook)
			{
				data->CoProcExitHook(data->CoProcExitTarget, win, exitcode);
			}
		}
	}
}
示例#7
0
    virtual int writeurg(const char *buf, int len) {
	return TerminalWrite(buf, len);
    }