Align UART completion with SSH behavior
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "console_completion.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -327,15 +328,34 @@ static ssize_t console_read_with_late_terminal_upgrade(int file_descriptor,
|
||||
return received;
|
||||
}
|
||||
|
||||
static bool add_linenoise_completion(const char *candidate, void *context)
|
||||
{
|
||||
linenoiseAddCompletion(context, candidate);
|
||||
return true;
|
||||
}
|
||||
/* The UART frontend is the sole caller of linenoise's completion callback. */
|
||||
static char s_uart_completion_output[2048U];
|
||||
|
||||
static void console_completion_callback(const char *buffer, linenoiseCompletions *completions)
|
||||
{
|
||||
console_completion_visit(buffer, add_linenoise_completion, completions);
|
||||
char completed[257U] = {0};
|
||||
if (console_completion_expand(buffer, completed, sizeof(completed))) {
|
||||
linenoiseAddCompletion(completions, completed);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t output_length = 0U;
|
||||
if (!console_completion_format_matches(buffer, s_uart_completion_output,
|
||||
sizeof(s_uart_completion_output),
|
||||
&output_length) ||
|
||||
output_length == 0U) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Linenoise cycles every completion it receives. Print the shared list
|
||||
* ourselves, then return the unchanged line as its one completion so its
|
||||
* normal refresh restores the prompt without selecting a candidate.
|
||||
*/
|
||||
fputs("\r\n", stdout);
|
||||
(void)fwrite(s_uart_completion_output, 1U, output_length, stdout);
|
||||
fflush(stdout);
|
||||
linenoiseAddCompletion(completions, buffer);
|
||||
}
|
||||
|
||||
void console_completion_install(void)
|
||||
|
||||
Reference in New Issue
Block a user