Exemplo n.º 1
0
bool SetCursorPosConcrete(
	struct Tracker_Windows *window,
	struct WBlocks *wblock,
	NInt tracknum,
	int subtrack
){
        struct WTracks *wtrack;
	int ret=0,tempret;

	if(tracknum>=wblock->block->num_tracks || tracknum<TEMPOTRACK) return false;

	if(tracknum<0){
		if(tracknum==window->curr_track) return true;

		if(tracknum>window->curr_track){
			while(window->curr_track!=tracknum){
				tempret=CursorRight(window,wblock);
				ret=R_MAX(tempret,ret);
			}
		}else{
			while(window->curr_track!=tracknum){
				tempret=CursorLeft(window,wblock);
				ret=R_MAX(tempret,ret);
			}
		}
	}else{
		wtrack=ListFindElement1(&wblock->wtracks->l,tracknum);
                int num_subtracks = GetNumSubtracks(wtrack);

		subtrack=R_MIN(num_subtracks-1,subtrack);

		if(tracknum==window->curr_track && subtrack==window->curr_track_sub)
                  return 0;

		if(tracknum>window->curr_track || (tracknum==window->curr_track && subtrack>window->curr_track_sub)){
			while(window->curr_track!=tracknum || window->curr_track_sub!=subtrack){
				tempret=CursorRight(window,wblock);
                                //printf("wtrack->num: %d, curr_track: %d, num_tracks: %d\n",wtrack->l.num, window->curr_track,wblock->block->num_tracks);
				ret=R_MAX(tempret,ret);
			}
		}else{
			while(window->curr_track!=tracknum || window->curr_track_sub!=subtrack){
				tempret=CursorLeft(window,wblock);
				ret=R_MAX(tempret,ret);
			}
		}
	}

	return true;
}
Exemplo n.º 2
0
/*****************************************************************************
 * FUNCTION: ProcessEscapeSequence
 *
 * RETURNS: None
 *
 * PARAMS:  pEscapeSequence -- escape sequence string to be processed.
 *
 * NOTES:   Processes an escape sequence received by the state machine
 *
 *****************************************************************************/
static void ProcessEscapeSequence(INT8 *pEscapeSequence)
{

   /* if a Left Arrow Key */
   if (strcmppgm2ram( (const char *) pEscapeSequence, (ROM FAR char*) leftArrowEscapeSequence) == 0)
   {
      CursorLeft();
   }
   /* else if Right Arrow Key */
   else if (strcmppgm2ram( (const char *) pEscapeSequence, (ROM FAR char*) rightArrowEscapeSequence) == 0)
   {
      CursorRight();
   }
#if (kWFNumHistoryEntries > 0)
   /* else if Up Arrow Key */
   else if (strcmppgm2ram( (const char *) pEscapeSequence, (ROM FAR char*) upArrowEscapeSequence) == 0)
   {

      DisplayHistoryEntry(kWFPrevHistory);
   }
   /* else if Down Arrow Key */
   else if (strcmppgm2ram( (const char *) pEscapeSequence, (ROM FAR char*) downArrowEscapeSequence) == 0)
   {
      DisplayHistoryEntry(kWFNextHistory);
   }
#endif
   /* else if Home Key */
   else if (strcmppgm2ram( (const char *) pEscapeSequence, (ROM FAR char*) homeKeyEscapeSequence) == 0)
   {
      CursorHome();
   }
   /* else if End Key */
   else if (strcmppgm2ram( (const char *) pEscapeSequence, (ROM FAR char*) endKeyEscapeSequence) == 0)
   {
      CursorEnd();
   }
}
Exemplo n.º 3
0
void CursorLeft_CurrPos(struct Tracker_Windows *window){
	struct WBlocks *wblock=window->wblock;
	TrackSelectUpdate(window,wblock,CursorLeft(window,wblock));
}
Exemplo n.º 4
0
void CScreenDevice::Write (char chChar)
{
	switch (m_nState)
	{
	case ScreenStateStart:
		switch (chChar)
		{
		case '\b':
			CursorLeft ();
			break;

		case '\t':
			Tabulator ();
			break;

		case '\n':
			NewLine ();
			break;

		case '\r':
			CarriageReturn ();
			break;

		case '\x1b':
			m_nState = ScreenStateEscape;
			break;

		default:
			DisplayChar (chChar);
			break;
		}
		break;

	case ScreenStateEscape:
		switch (chChar)
		{
		case 'M':
			ReverseScroll ();
			m_nState = ScreenStateStart;
			break;

		case '[':
			m_nState = ScreenStateBracket;
			break;

		default:
			m_nState = ScreenStateStart;
			break;
		}
		break;

	case ScreenStateBracket:
		switch (chChar)
		{
		case '?':
			m_nState = ScreenStateQuestionMark;
			break;

		case 'A':
			CursorUp ();
			m_nState = ScreenStateStart;
			break;

		case 'B':
			CursorDown ();
			m_nState = ScreenStateStart;
			break;

		case 'C':
			CursorRight ();
			m_nState = ScreenStateStart;
			break;

		case 'H':
			CursorHome ();
			m_nState = ScreenStateStart;
			break;

		case 'J':
			ClearDisplayEnd ();
			m_nState = ScreenStateStart;
			break;

		case 'K':
			ClearLineEnd ();
			m_nState = ScreenStateStart;
			break;

		case 'L':
			InsertLines (1);
			m_nState = ScreenStateStart;
			break;

		case 'M':
			DeleteLines (1);
			m_nState = ScreenStateStart;
			break;

		case 'P':
			DeleteChars (1);
			m_nState = ScreenStateStart;
			break;

		default:
			if ('0' <= chChar && chChar <= '9')
			{
				m_nParam1 = chChar - '0';
				m_nState = ScreenStateNumber1;
			}
			else
			{
				m_nState = ScreenStateStart;
			}
			break;
		}
		break;

	case ScreenStateNumber1:
		switch (chChar)
		{
		case ';':
			m_nState = ScreenStateSemicolon;
			break;

		case 'L':
			InsertLines (m_nParam1);
			m_nState = ScreenStateStart;
			break;

		case 'M':
			DeleteLines (m_nParam1);
			m_nState = ScreenStateStart;
			break;

		case 'P':
			DeleteChars (m_nParam1);
			m_nState = ScreenStateStart;
			break;

		case 'X':
			EraseChars (m_nParam1);
			m_nState = ScreenStateStart;
			break;

		case 'h':
		case 'l':
			if (m_nParam1 == 4)
			{
				InsertMode (chChar == 'h');
			}
			m_nState = ScreenStateStart;
			break;
			
		case 'm':
			SetStandoutMode (m_nParam1);
			m_nState = ScreenStateStart;
			break;

		default:
			if ('0' <= chChar && chChar <= '9')
			{
				m_nParam1 *= 10;
				m_nParam1 += chChar - '0';

				if (m_nParam1 > 99)
				{
					m_nState = ScreenStateStart;
				}
			}
			else
			{
				m_nState = ScreenStateStart;
			}
			break;
		}
		break;

	case ScreenStateSemicolon:
		if ('0' <= chChar && chChar <= '9')
		{
			m_nParam2 = chChar - '0';
			m_nState = ScreenStateNumber2;
		}
		else
		{
			m_nState = ScreenStateStart;
		}
		break;

	case ScreenStateQuestionMark:
		if ('0' <= chChar && chChar <= '9')
		{
			m_nParam1 = chChar - '0';
			m_nState = ScreenStateNumber3;
		}
		else
		{
			m_nState = ScreenStateStart;
		}
		break;

	case ScreenStateNumber2:
		switch (chChar)
		{
		case 'H':
			CursorMove (m_nParam1, m_nParam2);
			m_nState = ScreenStateStart;
			break;

		case 'r':
			SetScrollRegion (m_nParam1, m_nParam2);
			m_nState = ScreenStateStart;
			break;

		default:
			if ('0' <= chChar && chChar <= '9')
			{
				m_nParam2 *= 10;
				m_nParam2 += chChar - '0';

				if (m_nParam2 > 199)
				{
					m_nState = ScreenStateStart;
				}
			}
			else
			{
				m_nState = ScreenStateStart;
			}
			break;
		}
		break;

	case ScreenStateNumber3:
		switch (chChar)
		{
		case 'h':
		case 'l':
			if (m_nParam1 == 25)
			{
				SetCursorMode (chChar == 'h');
			}
			m_nState = ScreenStateStart;
			break;

		default:
			if ('0' <= chChar && chChar <= '9')
			{
				m_nParam1 *= 10;
				m_nParam1 += chChar - '0';

				if (m_nParam1 > 99)
				{
					m_nState = ScreenStateStart;
				}
			}
			else
			{
				m_nState = ScreenStateStart;
			}
			break;
		}
		break;

	default:
		m_nState = ScreenStateStart;
		break;
	}
}
Exemplo n.º 5
0
uint32_t ReadShellPrompt(int fd, char *buf, size_t len) {
	size_t total_len = 0;
	size_t rx_bytes;
	size_t i;
	char c;
	char t[2];
	t[1] = '\0';
	int8_t CurrCommandHistory = -1;
	char TmpBuf[MAX_CMD_LEN];
	uint32_t CursorPos = 0;
	
	bzero(TmpBuf, MAX_CMD_LEN);

	while ((receive(fd, &c, 1, &rx_bytes) == 0) && total_len < len-1) {
		if (rx_bytes == 0) {
			buf[0] = '\0';
			return(0);
		}
//		t[0] = c;
//		printf("$08x\n", t[0]);

		// backspace
		if (c == '\x7f') {
			if (CursorPos == total_len) {
				printf("\b\b\b   \b\b\b");
				total_len--;
				CursorPos--;
				continue;
			}
			for (i = CursorPos-1; i < total_len-1; i++) {
				buf[i] = buf[i+1];
			}
			total_len--;
			CursorPos--;
			EraseLine(0);
			PrintPrompt();
			buf[total_len] = '\0';
			printf("$s", buf);
			CursorLeft(total_len-CursorPos);
			continue;
		}

		// ctrl-c
		if (c == '\x03') {
			return(0);
		}

		// ctrl-e
		if (c == '\x05') {
			// move the cursor to the end
			EraseLine(0);
			PrintPrompt();
			buf[total_len] = '\0';
			printf("$s", buf);
			CursorPos = total_len;
			continue;
		}

		// ctrl-u
		if (c == '\x15') {
			EraseLine(0);
			PrintPrompt();
			total_len = 0;
			CursorPos = 0;
			continue;
		}

		// ctrl-d
		if (c == '\x04') {
			if (total_len > 0) {
				printf("\b\b  \b\b");
				continue;
			} else {
				printf("\b\b  \b\b");
				printf("exit  ");
				strcpy(buf, "exit");
				return(1);
			}
		}

		// escape codes
		if (c == '\x1b') {
			// receive the next char
			if (receive(fd, &c, 1, &rx_bytes) != 0) {
				buf[0] = '\0';
				return(0);
			}
			if (rx_bytes == 0) {
				buf[0] = '\0';
				return(0);
			}

			if (c == '\x5b') {
				// receive the next char
				if (receive(fd, &c, 1, &rx_bytes) != 0) {
					buf[0] = '\0';
					return(0);
				}
				if (rx_bytes == 0) {
					buf[0] = '\0';
					return(0);
				}

				if (c == '\x41') {
					// up arrow	
					// if there's no command history
					if (ENV.NumCommandHistory == 0) {
						EraseLine(0);
						PrintPrompt();
						buf[total_len] = '\0';
						printf("$s", buf);
						CursorPos = total_len;
						continue;
					}

					// if we're printing the first history buf,
					// save the current buf in case the user
					// arrow's back to it
					if (CurrCommandHistory == -1) {
						buf[total_len] = '\0';
						strcpy(TmpBuf, buf);
					}
					CurrCommandHistory++;
					if (CurrCommandHistory >= ENV.NumCommandHistory) {
						CurrCommandHistory = ENV.NumCommandHistory-1;
					}
					// print the next command in the history buf
					EraseLine(0);
					PrintPrompt();
					strcpy(buf, ENV.CommandHistory[CurrCommandHistory]);
					total_len = strlen(ENV.CommandHistory[CurrCommandHistory]);
					CursorPos = total_len;
					printf("$s", ENV.CommandHistory[CurrCommandHistory]);
					continue;
				} else if (c == '\x42') {
					// down arrow	
					if (CurrCommandHistory == -1) {
						// nothing to do
						EraseLine(0);
						PrintPrompt();
						buf[total_len] = '\0';
						printf("$s", buf);
						continue;
					}

					// see if we're at the first command in the history
					if (CurrCommandHistory == 0) {
						// go back to the user's original command
						EraseLine(0);
						PrintPrompt();
						strcpy(buf, TmpBuf);
						total_len = strlen(buf);
						CursorPos = total_len;
						printf("$s", buf);
						CurrCommandHistory = -1;
						continue;
					}

					// print the next command in the history
					CurrCommandHistory--;
					EraseLine(0);
					PrintPrompt();
					strcpy(buf, ENV.CommandHistory[CurrCommandHistory]);
					total_len = strlen(ENV.CommandHistory[CurrCommandHistory]);
					CursorPos = total_len;
					printf("$s", ENV.CommandHistory[CurrCommandHistory]);
					continue;

				} else if (c == '\x43') {
					// right arrow	
					if (CursorPos == total_len) {
						// nothing to do but remove the arrow control chars
						EraseLine(0);
						PrintPrompt();
						buf[total_len] = '\0';
						printf("$s", buf);
						continue;
					}

					// not at the end of the line, so move the cursor
					// right one character
					CursorPos++;
					EraseLine(0);
					PrintPrompt();
					buf[total_len] = '\0';
					printf("$s", buf);
					if (total_len != CursorPos) {
						CursorLeft(total_len-CursorPos);
					}
					continue;
				} else if (c == '\x44') {
					// left arrow	
					if (CursorPos == 0) {
						// nothing to do, re-print the line (to remove the control chars)
						EraseLine(0);
						PrintPrompt();
						buf[total_len] = '\0';
						printf("$s", buf);
						CursorLeft(total_len);
						continue;
					}
					// not at the beginning of the line, so move the cursor
					// left one character
					CursorPos--;
					EraseLine(0);
					PrintPrompt();
					buf[total_len] = '\0';
					printf("$s", buf);
					CursorLeft(total_len-CursorPos);
					continue;
				}
			}
		}

		if (c == '\r') {
			buf[CursorPos] = '\0';
			break;
		}
		if (c == '\n') {
			// receive the corresponding '\r'
			if (receive(fd, &c, 1, &rx_bytes) != 0) {
				buf[0] = '\0';
				return(0);
			}
			if (rx_bytes == 0) {
				buf[0] = '\0';
				return(0);
			}
			if (c != '\r') {
				buf[0] = '\0';
				return(0);
			}
			buf[CursorPos] = '\0';
//			EraseToEOL();
			break;
		}
		if (CursorPos == total_len) {
			buf[total_len++] = c;
			CursorPos++;
		} else {
			buf[CursorPos++] = c;
		}
		
	}
	if (rx_bytes == 0) {
		buf[0] = '\0';
		return(0);
	}
	buf[total_len] = '\0';

	return(total_len);
}
Exemplo n.º 6
0
    void LineEditData::DeletePrev(int times) {
        times = std::min(times, (int)cursor);

        CursorLeft(times);
        DeleteNext(times);
    }