/** Run the terminal */
void term_Run()
{
   char args[TERM_BUFSIZE];
   const TERM_CMD *pCurCmd = NULL;
   int lastIdx = 0;

   while (1)
   {
      int currentIdx = TERM_BUFSIZE - TERM_USART_CNDTR;

      if (0 == TERM_USART_CNDTR)
         ResetDMA();

      while (lastIdx < currentIdx) //echo
         usart_send_blocking(TERM_USART, inBuf[lastIdx++]);

      if (currentIdx > 0)
      {
         if (inBuf[currentIdx - 1] == '\n' || inBuf[currentIdx - 1] == '\r')
         {
            inBuf[currentIdx] = 0;
            lastIdx = 0;
            char *space = (char*)my_strchr(inBuf, ' ');

            if (0 == *space) //No args after command, look for end of line
            {
               space = (char*)my_strchr(inBuf, '\n');
               args[0] = 0;
            }
            else //There are arguments, copy everything behind the space
            {
               my_strcpy(args, space + 1);
            }

            if (0 == *space) //No \n found? try \r
               space = (char*)my_strchr(inBuf, '\r');

            *space = 0;
            pCurCmd = CmdLookup(inBuf);
            ResetDMA();

            if (NULL != pCurCmd)
            {
               pCurCmd->CmdFunc(args);
            }
            else if (currentIdx > 1)
            {
               term_send(TERM_USART, "Unknown command sequence\r\n");
            }
         }
         else if (inBuf[0] == '!' && NULL != pCurCmd)
         {
            ResetDMA();
            lastIdx = 0;
            pCurCmd->CmdFunc(args);
         }
      }
   } /* while(1) */
} /* term_Run */
Example #2
0
static void directkey(void)
{
	char *shell[32] = SHELL;
	char *mail[32] = MAIL;
	char *editor[32] = EDITOR;
	int c = readchar();
	if (PASS && locked) {
		if (c == '\r') {
			pass[passlen] = '\0';
			if (!strcmp(PASS, pass))
				locked = 0;
			passlen = 0;
			return;
		}
		if (isprint(c) && passlen + 1 < sizeof(pass))
			pass[passlen++] = c;
		return;
	}
	if (c == ESC) {
		switch ((c = readchar())) {
		case 'c':
			execterm(shell);
			return;
		case 'm':
			execterm(mail);
			return;
		case 'e':
			execterm(editor);
			return;
		case 'j':
		case 'k':
			showterm(altterm(cterm()));
			return;
		case 'o':
			showtag(ltag);
			return;
		case 'p':
			listtags();
			return;
		case '\t':
			if (nextterm() != cterm())
				showterm(nextterm());
			return;
		case CTRLKEY('q'):
			exitit = 1;
			return;
		case 's':
			term_screenshot();
			return;
		case 'y':
			term_redraw(1);
			return;
		case CTRLKEY('l'):
			locked = 1;
			passlen = 0;
			return;
		case CTRLKEY('o'):
			taglock = 1 - taglock;
			return;
		case ',':
			term_scrl(pad_rows() / 2);
			return;
		case '.':
			term_scrl(-pad_rows() / 2);
			return;
		default:
			if (strchr(tags, c)) {
				showtag(strchr(tags, c) - tags);
				return;
			}
			if (mainterm())
				term_send(ESC);
		}
	}
	if (c != -1 && mainterm())
		term_send(c);
}