Pavel Chromy: hopefully perfection for async output and prompt/partially typed command line handling.
git-svn-id: svn://svn.berlios.de/openocd/trunk@487 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
parent
e378eeec36
commit
cce7512ca9
|
@ -72,6 +72,7 @@ int telnet_prompt(connection_t *connection)
|
||||||
{
|
{
|
||||||
telnet_connection_t *t_con = connection->priv;
|
telnet_connection_t *t_con = connection->priv;
|
||||||
|
|
||||||
|
telnet_write(connection, "\r", 1); /* the prompt is always placed at the line beginning */
|
||||||
return telnet_write(connection, t_con->prompt, strlen(t_con->prompt));
|
return telnet_write(connection, t_con->prompt, strlen(t_con->prompt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,12 +115,22 @@ void telnet_log_callback(void *priv, const char *file, int line,
|
||||||
const char *function, const char *string)
|
const char *function, const char *string)
|
||||||
{
|
{
|
||||||
connection_t *connection = priv;
|
connection_t *connection = priv;
|
||||||
|
telnet_connection_t *t_con = connection->priv;
|
||||||
|
int i;
|
||||||
|
|
||||||
telnet_write(connection, "\b\b \b\b", strlen("\b\b \b\b"));
|
/* clear the command line */
|
||||||
|
telnet_write(connection, "\r", 1);
|
||||||
|
for (i = strlen(t_con->prompt) + t_con->line_size; i>0; i-=16)
|
||||||
|
telnet_write(connection, " ", i>16 ? 16 : i);
|
||||||
|
|
||||||
|
telnet_write(connection, "\r", 1);
|
||||||
telnet_outputline(connection, string);
|
telnet_outputline(connection, string);
|
||||||
|
|
||||||
|
/* put the command line to its previous state */
|
||||||
telnet_prompt(connection);
|
telnet_prompt(connection);
|
||||||
|
telnet_write(connection, t_con->line, t_con->line_size);
|
||||||
|
for (i=t_con->line_size; i>t_con->line_cursor; i--)
|
||||||
|
telnet_write(connection, "\b", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int telnet_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv)
|
int telnet_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv)
|
||||||
|
@ -289,19 +300,11 @@ int telnet_input(connection_t *connection)
|
||||||
telnet_write(connection, "\r\n\x00", 3);
|
telnet_write(connection, "\r\n\x00", 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
telnet_prompt(connection);
|
|
||||||
t_con->line_size = 0;
|
t_con->line_size = 0;
|
||||||
t_con->line_cursor = 0;
|
t_con->line_cursor = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = command_run_line(command_context, t_con->line);
|
|
||||||
|
|
||||||
if (retval == ERROR_COMMAND_CLOSE_CONNECTION)
|
|
||||||
{
|
|
||||||
return ERROR_SERVER_REMOTE_CLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save only non-blank lines in the history */
|
/* Save only non-blank lines in the history */
|
||||||
if (t_con->line_size > 0)
|
if (t_con->line_size > 0)
|
||||||
{
|
{
|
||||||
|
@ -327,12 +330,17 @@ int telnet_input(connection_t *connection)
|
||||||
t_con->history[t_con->current_history] = strdup("");
|
t_con->history[t_con->current_history] = strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
int t = telnet_prompt(connection);
|
|
||||||
if (t == ERROR_SERVER_REMOTE_CLOSED)
|
|
||||||
return t;
|
|
||||||
|
|
||||||
t_con->line_size = 0;
|
t_con->line_size = 0;
|
||||||
t_con->line_cursor = 0;
|
t_con->line_cursor = 0;
|
||||||
|
|
||||||
|
retval = command_run_line(command_context, t_con->line);
|
||||||
|
if (retval == ERROR_COMMAND_CLOSE_CONNECTION)
|
||||||
|
return ERROR_SERVER_REMOTE_CLOSED;
|
||||||
|
|
||||||
|
retval = telnet_prompt(connection);
|
||||||
|
if (retval == ERROR_SERVER_REMOTE_CLOSED)
|
||||||
|
return ERROR_SERVER_REMOTE_CLOSED;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ((*buf_p == 0x7f) || (*buf_p == 0x8)) /* delete character */
|
else if ((*buf_p == 0x7f) || (*buf_p == 0x8)) /* delete character */
|
||||||
{
|
{
|
||||||
|
@ -579,6 +587,9 @@ int telnet_set_prompt(connection_t *connection, char *prompt)
|
||||||
{
|
{
|
||||||
telnet_connection_t *t_con = connection->priv;
|
telnet_connection_t *t_con = connection->priv;
|
||||||
|
|
||||||
|
if (t_con->prompt != NULL)
|
||||||
|
free(t_con->prompt);
|
||||||
|
|
||||||
t_con->prompt = strdup(prompt);
|
t_con->prompt = strdup(prompt);
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
Loading…
Reference in New Issue