Beispiel #1
0
/*
==================
CON_Hide

Clear the display of the line currently edited
bring cursor back to beginning of line
==================
*/
static void CON_Hide(void)
{
	if(ttycon_on)
	{
		int             i;

		if(ttycon_hide)
		{
			ttycon_hide++;
			return;
		}
		if(TTY_con.cursor > 0)
		{
			for(i = 0; i < TTY_con.cursor; i++)
			{
				CON_Back();
			}
		}
		// Delete prompt
		for (i = strlen(TTY_CONSOLE_PROMPT); i > 0; i--) {
			CON_Back();
		}
		ttycon_hide++;
	}
}
Beispiel #2
0
/*
==================
CON_Hide

Clear the display of the line currently edited
bring cursor back to beginning of line
==================
*/
static void CON_Hide()
{
	if ( ttycon_on )
	{
		if ( ttycon_hide )
		{
			ttycon_hide++;
			return;
		}

		for (int i = TTY_field.GetText().size(); i-->0;) {
			CON_Back();
		}

		CON_Back(); // Delete "]"
		ttycon_hide++;
	}
}
Beispiel #3
0
/*
==================
CON_Shutdown

Never exit without calling this, or your terminal will be left in a pretty bad state
==================
*/
void CON_Shutdown( void )
{
    if (ttycon_on)
    {
        CON_Back(); // Delete "]"
        tcsetattr (STDIN_FILENO, TCSADRAIN, &TTY_tc);
    }

    // Restore blocking to stdin reads
    fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) & ~O_NONBLOCK);
}
Beispiel #4
0
/*
==================
CON_Hide

Clear the display of the line currently edited
bring cursor back to beginning of line
==================
*/
static void CON_Hide( void )
{
    if( ttycon_on )
    {
        int i;
        if (ttycon_hide)
        {
            ttycon_hide++;
            return;
        }
        if (TTY_con.cursor>0)
        {
            for (i=0; i<TTY_con.cursor; i++)
            {
                CON_Back();
            }
        }
        CON_Back(); // Delete "]"
        ttycon_hide++;
    }
}
Beispiel #5
0
/*
==================
CON_Shutdown

Never exit without calling this, or your terminal will be left in a pretty bad state
==================
*/
void CON_Shutdown( void )
{
	if (ttycon_on)
	{
		CON_Back(); // Delete "]"
		tcsetattr (0, TCSADRAIN, &TTY_tc);
	}

  // Restore blocking to stdin reads
  fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~O_NONBLOCK );
  
  // close named pipe
  close(urtpipe_fd);
}
Beispiel #6
0
/*
==================
CON_Input
==================
*/
char *CON_Input( void )
{
    // we use this when sending back commands
    static char text[MAX_EDIT_LINE];
    int avail;
    char key;
    field_t *history;
    size_t size;

    if(ttycon_on)
    {
        avail = read(STDIN_FILENO, &key, 1);
        if (avail != -1)
        {
            // we have something
            // backspace?
            // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere
            if ((key == TTY_erase) || (key == 127) || (key == 8))
            {
                if (TTY_con.cursor > 0)
                {
                    TTY_con.cursor--;
                    TTY_con.buffer[TTY_con.cursor] = '\0';
                    CON_Back();
                }
                return NULL;
            }
            // check if this is a control char
            if ((key) && (key) < ' ')
            {
                if (key == '\n')
                {
                    // push it in history
                    Hist_Add(&TTY_con);
                    Q_strncpyz(text, TTY_con.buffer, sizeof(text));
                    Field_Clear(&TTY_con);
                    key = '\n';
                    size = write(1, &key, 1);
                    size = write( 1, "]", 1 );
                    return text;
                }
                if (key == '\t')
                {
                    CON_Hide();
                    Field_AutoComplete( &TTY_con );
                    CON_Show();
                    return NULL;
                }
                avail = read(STDIN_FILENO, &key, 1);
                if (avail != -1)
                {
                    // VT 100 keys
                    if (key == '[' || key == 'O')
                    {
                        avail = read(STDIN_FILENO, &key, 1);
                        if (avail != -1)
                        {
                            switch (key)
                            {
                            case 'A':
                                history = Hist_Prev();
                                if (history)
                                {
                                    CON_Hide();
                                    TTY_con = *history;
                                    CON_Show();
                                }
                                CON_FlushIn();
                                return NULL;
                                break;
                            case 'B':
                                history = Hist_Next();
                                CON_Hide();
                                if (history)
                                {
                                    TTY_con = *history;
                                } else
                                {
                                    Field_Clear(&TTY_con);
                                }
                                CON_Show();
                                CON_FlushIn();
                                return NULL;
                                break;
                            case 'C':
                                return NULL;
                            case 'D':
                                return NULL;
                            }
                        }
                    }
                }
                Com_DPrintf("droping ISCTL sequence: %d, TTY_erase: %d\n", key, TTY_erase);
                CON_FlushIn();
                return NULL;
            }
            if (TTY_con.cursor >= sizeof(text) - 1)
                return NULL;
            // push regular character
            TTY_con.buffer[TTY_con.cursor] = key;
            TTY_con.cursor++;
            // print the current line (this is differential)
            size = write(STDOUT_FILENO, &key, 1);
        }

        return NULL;
    }
    else if (stdin_active)
    {
        int     len;
        fd_set  fdset;
        struct timeval timeout;

        FD_ZERO(&fdset);
        FD_SET(STDIN_FILENO, &fdset); // stdin
        timeout.tv_sec = 0;
        timeout.tv_usec = 0;
        if(select (STDIN_FILENO + 1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(STDIN_FILENO, &fdset))
            return NULL;

        len = read(STDIN_FILENO, text, sizeof(text));
        if (len == 0)
        {   // eof!
            stdin_active = qfalse;
            return NULL;
        }

        if (len < 1)
            return NULL;
        text[len-1] = 0;    // rip off the /n and terminate

        return text;
    }
    return NULL;
}
Beispiel #7
0
/*
==================
CON_Input
==================
*/
char           *CON_Input(void)
{
	// we use this when sending back commands
	static char     text[MAX_EDIT_LINE];
	int             avail;
	char            key;
	field_t        *history;
	size_t UNUSED_VAR size;

	if(ttycon_on)
	{
		avail = read(STDIN_FILENO, &key, 1);
		if(avail != -1)
		{
			// we have something
			// backspace?
			// NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere
			if((key == TTY_erase) || (key == 127) || (key == 8))
			{
				if(TTY_con.cursor > 0)
				{
					TTY_con.cursor--;
					TTY_con.buffer[TTY_con.cursor] = '\0';
					CON_Back();
				}
				return NULL;
			}
			// check if this is a control char
			if((key) && (key) < ' ')
			{
				if(key == '\n')
				{
#ifndef DEDICATED
					// if not in the game explicitly prepend a slash if needed
					if (clc.state != CA_ACTIVE && TTY_con.cursor &&
						TTY_con.buffer[0] != '/' && TTY_con.buffer[0] != '\\')
					{
						memmove(TTY_con.buffer + 1, TTY_con.buffer, sizeof(TTY_con.buffer) - 1);
						TTY_con.buffer[0] = '\\';
						TTY_con.cursor++;
					}

					if (TTY_con.buffer[0] == '/' || TTY_con.buffer[0] == '\\') {
						Q_strncpyz(text, TTY_con.buffer + 1, sizeof(text));
					} else if (TTY_con.cursor) {
						Com_sprintf(text, sizeof(text), "cmd say %s", TTY_con.buffer);
					} else {
						text[0] = '\0';
					}

					// push it in history
					Hist_Add(&TTY_con);
					CON_Hide();
					Com_Printf("%s%s\n", TTY_CONSOLE_PROMPT, TTY_con.buffer);
					Field_Clear(&TTY_con);
					CON_Show();
#else
					// push it in history
					Hist_Add(&TTY_con);
					Q_strncpyz(text, TTY_con.buffer, sizeof(text));
					Field_Clear(&TTY_con);
					key = '\n';
					size = write(STDOUT_FILENO, &key, 1);
					size = write(STDOUT_FILENO, TTY_CONSOLE_PROMPT, strlen(TTY_CONSOLE_PROMPT));
#endif
					return text;
				}
				if(key == '\t')
				{
					CON_Hide();
					Field_AutoComplete(&TTY_con);
					CON_Show();
					return NULL;
				}
				avail = read(STDIN_FILENO, &key, 1);
				if(avail != -1)
				{
					// VT 100 keys
					if(key == '[' || key == 'O')
					{
						avail = read(STDIN_FILENO, &key, 1);
						if(avail != -1)
						{
							switch (key)
							{
								case 'A':
									history = Hist_Prev();
									if(history)
									{
										CON_Hide();
										TTY_con = *history;
										CON_Show();
									}
									CON_FlushIn();
									return NULL;
									break;
								case 'B':
									history = Hist_Next();
									CON_Hide();
									if(history)
									{
										TTY_con = *history;
									}
									else
									{
										Field_Clear(&TTY_con);
									}
									CON_Show();
									CON_FlushIn();
									return NULL;
									break;
								case 'C':
									return NULL;
								case 'D':
									return NULL;
							}
						}
					}
				}
				Com_DPrintf("droping ISCTL sequence: %d, TTY_erase: %d\n", key, TTY_erase);
				CON_FlushIn();
				return NULL;
			}
			if(TTY_con.cursor >= sizeof(text) - 1)
				return NULL;
			// push regular character
			TTY_con.buffer[TTY_con.cursor] = key;
			TTY_con.cursor++; // next char will always be '\0'
			// print the current line (this is differential)
			size = write(STDOUT_FILENO, &key, 1);
		}

		return NULL;
	}
	else if(stdin_active)
	{
		int             len;
		fd_set          fdset;
		struct timeval  timeout;

		FD_ZERO(&fdset);
		FD_SET(STDIN_FILENO, &fdset);	// stdin
		timeout.tv_sec = 0;
		timeout.tv_usec = 0;
		if(select(STDIN_FILENO + 1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(STDIN_FILENO, &fdset))
			return NULL;

		len = read(STDIN_FILENO, text, sizeof(text));
		if(len == 0)
		{						// eof!
			stdin_active = qfalse;
			return NULL;
		}

		if(len < 1)
			return NULL;
		text[len - 1] = 0;		// rip off the /n and terminate

		return text;
	}
	return NULL;
}
Beispiel #8
0
/*
==================
CON_Input
==================
*/
char *CON_Input( void )
{
	// we use this when sending back commands
	static char text[MAX_EDIT_LINE];
	int avail;
	char key;

	if(ttycon_on)
	{
		CON_CheckRep();
		avail = read(STDIN_FILENO, &key, 1);
		if (avail != -1)
		{
			// we have something

			// disable hibernation for ten seconds to workaround console input lagg
			svs.hibernation.disableUntil = svs.time + 10000;

			// backspace?
			// NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere
			if ((key == TTY_erase) || (key == 127) || (key == 8))
			{
				if (TTY_con.cursor > 0)
				{
					TTY_con.cursor--;
					TTY_con.buffer[TTY_con.cursor] = '\0';
					CON_Back();
				}
				return NULL;
			}
			// check if this is a control char
			if ((key) && (key) < ' ')
			{
				if (key == '\n')
				{
#ifndef DEDICATED
					if (TTY_con.buffer[0] == '/' || TTY_con.buffer[0] == '\\') {
						Q_strncpyz(text, TTY_con.buffer + 1, sizeof(text));
					} else if (TTY_con.cursor) {
						Q_strncpyz(text, TTY_con.buffer, sizeof(text));
					} else {
						text[0] = '\0';
					}

					// push it in history
					Hist_Add();
					CON_Hide();
					Com_Printf("%s%s\n", TTY_CONSOLE_PROMPT, TTY_con.buffer);
					Field_Clear(&TTY_con);
					CON_Show();
#else
					// push it in history
					Hist_Add();
					Q_strncpyz(text, TTY_con.buffer, sizeof(text));
					Field_Clear(&TTY_con);
					key = '\n';
					write(STDOUT_FILENO, &key, 1);
					write(STDOUT_FILENO, TTY_CONSOLE_PROMPT, strlen(TTY_CONSOLE_PROMPT));
#endif
					return text;
				}
				if (key == '\t')
				{
					CON_Hide();
					Field_AutoComplete( &TTY_con );
					CON_Show();
					return NULL;
				}
				avail = read(STDIN_FILENO, &key, 1);
				if (avail != -1)
				{
					// VT 100 keys
					if (key == '[' || key == 'O')
					{
						avail = read(STDIN_FILENO, &key, 1);
						if (avail != -1)
						{
							switch (key)
							{
								case 'A':
									Hist_Prev();
									CON_FlushIn();
									return NULL;
									break;
								case 'B':
									Hist_Next();
									CON_FlushIn();
									return NULL;
									break;
								case 'C':
									return NULL;
								case 'D':
									return NULL;
							}
						}
					}
				}
				Com_DPrintf("droping ISCTL sequence: %d, TTY_erase: %d\n", key, TTY_erase);
				CON_FlushIn();
				return NULL;
			}
			if (TTY_con.cursor >= (int)sizeof(text) - 1)
				return NULL;
			// push regular character
			TTY_con.buffer[TTY_con.cursor] = key;
			TTY_con.cursor++; // next char will always be '\0'
			// print the current line (this is differential)
			write(STDOUT_FILENO, &key, 1);
		}

		return NULL;
	}
	else if (stdin_active)
	{
		int	 len;
		fd_set  fdset;
		struct timeval timeout;

		FD_ZERO(&fdset);
		FD_SET(STDIN_FILENO, &fdset); // stdin
		timeout.tv_sec = 0;
		timeout.tv_usec = 0;
		if(select (STDIN_FILENO + 1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(STDIN_FILENO, &fdset))
			return NULL;

		len = read(STDIN_FILENO, text, sizeof(text));
		if (len == 0)
		{ // eof!
			stdin_active = qfalse;
			return NULL;
		}

		if (len < 1)
			return NULL;
		text[len-1] = 0;	// rip off the /n and terminate

		return text;
	}
	return NULL;
}