Beispiel #1
0
/*--------------------------------------------------------------------------*/
char *TerminalGetString(char *prompt)
{
    if (InitTerm)
    {
        InitializeTerminal();
        InitTerm = FALSE;
    }

    newLine();

    setCurrentPrompt(prompt);

    /* print the prompt */
    displayPrompt();

    /* initialize history search */
    setSearchedTokenInScilabHistory(NULL);

    for (;;)
    {
        unsigned char cur_char = TerminalGetchar();

        if (cur_char <= 0)
        {
            return NULL;
        }

        /* http://bugzilla.scilab.org/show_bug.cgi?id=1052 */
        if (ismenu () == 1)
        {
            /* Abort current line */
            return NULL;
        }

        if ( (cur_char == CR_1) || (cur_char == CR_2) )
        {
            if ( isHistorySearch() )
            {
                putLineSearchedHistory();
            }
            else
            {
                char *line = getCurrentLine();
                TerminalPutc('\n');
                appendLineToScilabHistory(line);
                return line;
            }
        }
        else
        {
            TerminalPutc(cur_char);
            addCharacterCurrentLine(cur_char);
        }
    }
    return NULL;
}
Beispiel #2
0
/*--------------------------------------------------------------------------*/
void moveForwardSingleWord(void)
{
    reallocLineBuffer();
    while ( !isspace(cur_line[cur_pos]) && (cur_pos < max_pos) )
    {
        TerminalPutc(cur_line[cur_pos]);
        cur_pos++;
    }
    while ( isspace(cur_line[cur_pos]) && (cur_pos < max_pos) )
    {
        TerminalPutc(cur_line[cur_pos]);
        cur_pos++;
    }
    refreshLine();
}
Beispiel #3
0
/*--------------------------------------------------------------------------*/
void refreshLine(void)
{
	int i = 0;

	reallocLineBuffer();

	/* write tail of string */
	for (i = cur_pos; i < max_pos; i++) TerminalPutc(cur_line[i]);

	/* write a space at the end of the line in case we deleted one */
	TerminalPutc(VK_SPACE);

	/* backup to original position */
	for (i = max_pos + 1; i > cur_pos; i--) backSpace ();

}
Beispiel #4
0
/*--------------------------------------------------------------------------*/
void clearCurrentLine(void)
{
	int i = 0;

	reallocLineBuffer();

	for (i = 0; i < max_pos; i++) cur_line[i] = '\0';

	moveBeginningLine();
	
	for (i = 0; i < max_pos; i++) TerminalPutc(VK_SPACE);

	TerminalPutc('\r');
	displayPrompt();

	newLine();
}
Beispiel #5
0
/*--------------------------------------------------------------------------*/
void moveEndLine(void)
{
    reallocLineBuffer();
    while (cur_pos < max_pos)
    {
        TerminalPutc (cur_line[cur_pos]);
        cur_pos += 1;
    }
}
Beispiel #6
0
/*--------------------------------------------------------------------------*/
void moveForwardSingleChar(void)
{
    reallocLineBuffer();
    if (cur_pos < max_pos)
    {
        TerminalPutc(cur_line[cur_pos]);
        cur_pos += 1;
    }
}
Beispiel #7
0
/*--------------------------------------------------------------------------*/
void killCurrentPositionToEndLine(void)
{
	int i = 0;
	reallocLineBuffer();
	for (i = cur_pos; i < max_pos; i++)  cur_line[i] = '\0';
	for (i = cur_pos; i < max_pos; i++) TerminalPutc(VK_SPACE);
	for (i = cur_pos; i < max_pos; i++) backSpace ();
	max_pos = cur_pos;
}
Beispiel #8
0
/*--------------------------------------------------------------------------*/
static void backSpace(void)
{
	int X = 0, Y = 0;
	reallocLineBuffer();

	TermGetPosition(&X, &Y);
	if ( (X - 1) < 0 )
	{
		X = getXConsoleScreenSize();
		Y = Y - 1;
		TermSetPosition(X, Y);
	}
	else TerminalPutc(VK_BACK);
}