forked from test34/can_wizard
working prompt update
This commit is contained in:
parent
860bdd833d
commit
563c2fd641
2 changed files with 19 additions and 15 deletions
|
@ -928,7 +928,7 @@ int linenoiseEditStart(struct linenoiseState *l) {
|
|||
/* Populate the linenoise state that we pass to functions implementing
|
||||
* specific editing functionalities. */
|
||||
l->in_completion = 0;
|
||||
l->plen = strlen(l->prompt);
|
||||
// l->plen = strlen(l->prompt);
|
||||
l->oldpos = l->pos = 0;
|
||||
l->len = 0;
|
||||
l->cols = getColumns();
|
||||
|
@ -944,16 +944,16 @@ int linenoiseEditStart(struct linenoiseState *l) {
|
|||
xSemaphoreTake(stdout_taken_sem, portMAX_DELAY);
|
||||
if (!dumbmode) {
|
||||
linenoiseHistoryAdd("");
|
||||
int pos1 = getCursorPosition();
|
||||
// int pos1 = getCursorPosition();
|
||||
if (fwrite(l->prompt,l->plen,1,stdout) == -1) {
|
||||
xSemaphoreGive(stdout_taken_sem);
|
||||
return -1;
|
||||
}
|
||||
flushWrite();
|
||||
int pos2 = getCursorPosition();
|
||||
if (pos1 >= 0 && pos2 >= 0) {
|
||||
l->plen = pos2 - pos1;
|
||||
}
|
||||
// int pos2 = getCursorPosition();
|
||||
// if (pos1 >= 0 && pos2 >= 0) {
|
||||
// l->plen = pos2 - pos1;
|
||||
// }
|
||||
} else {
|
||||
if (fwrite(l->prompt,l->plen,1,stdout) == -1) {
|
||||
xSemaphoreGive(stdout_taken_sem);
|
||||
|
|
|
@ -36,44 +36,48 @@ struct linenoiseState ls;
|
|||
SemaphoreHandle_t console_taken_sem;
|
||||
|
||||
static void update_prompt() {
|
||||
static char* text;
|
||||
char text[30];
|
||||
int text_len;
|
||||
static char* prompt_color;
|
||||
text[0] = '\0';
|
||||
switch (curr_can_state.state) {
|
||||
case CAN_NOT_INSTALLED:
|
||||
text = "not installed";
|
||||
strcat(text, "not installed");
|
||||
prompt_color = LOG_COLOR(LOG_COLOR_RED);
|
||||
break;
|
||||
case CAN_STOPPED:
|
||||
text = "stopped";
|
||||
strcat(text, "stopped");
|
||||
prompt_color = LOG_COLOR(LOG_COLOR_RED);
|
||||
break;
|
||||
case CAN_ERROR_ACTIVE:
|
||||
text = "error active";
|
||||
strcat(text, "error active");
|
||||
prompt_color = LOG_COLOR(LOG_COLOR_GREEN);
|
||||
break;
|
||||
case CAN_ERROR_PASSIVE:
|
||||
text = "error passive";
|
||||
strcat(text, "error passive");
|
||||
prompt_color = LOG_COLOR(LOG_COLOR_BROWN);
|
||||
break;
|
||||
case CAN_BUF_OFF:
|
||||
text = "bus off";
|
||||
strcat(text, "bus off");
|
||||
prompt_color = LOG_COLOR(LOG_COLOR_RED);
|
||||
break;
|
||||
case CAN_RECOVERING:
|
||||
text = "recovering";
|
||||
strcat(text, "recovering");
|
||||
prompt_color = LOG_COLOR(LOG_COLOR_RED);
|
||||
break;
|
||||
}
|
||||
strcat(text, " > ");
|
||||
prompt_buf[0] = '\0';
|
||||
if (use_colors) {
|
||||
strcat(prompt_buf, prompt_color);
|
||||
strcat(prompt_buf, text);
|
||||
strcat(prompt_buf, " > ");
|
||||
strcat(prompt_buf, LOG_RESET_COLOR);
|
||||
} else {
|
||||
strcat(prompt_buf, text);
|
||||
}
|
||||
text_len = strlen(text);
|
||||
ls.prompt = prompt_buf;
|
||||
ls.plen = text_len;
|
||||
}
|
||||
|
||||
void console_task_tx(void* arg) {
|
||||
|
@ -84,7 +88,7 @@ void console_task_tx(void* arg) {
|
|||
size_t msg_to_print_size;
|
||||
while(1) {
|
||||
msg_to_print = (char *)xRingbufferReceive(can_messages, &msg_to_print_size, prompt_timeout);
|
||||
// update_prompt();
|
||||
update_prompt();
|
||||
xSemaphoreTake(console_taken_sem, portMAX_DELAY);
|
||||
xSemaphoreTake(stdout_taken_sem, portMAX_DELAY);
|
||||
linenoiseHide(&ls);
|
||||
|
|
Loading…
Reference in a new issue