Display SSH completion candidates for ambiguous prefixes
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#define ADMIN_UART_CONSOLE_TASK_PRIORITY 3U
|
||||
#define ADMIN_SSH_CONSOLE_MAX_ARGUMENTS 10U
|
||||
#define ADMIN_SSH_CONSOLE_HISTORY_DEPTH 4U
|
||||
#define ADMIN_SSH_CONSOLE_COMPLETION_OUTPUT_CAPACITY 2048U
|
||||
#define ADMIN_SSH_CONTROL_QUEUE_LENGTH 2U
|
||||
#define ADMIN_SSH_CONTROL_TASK_STACK_SIZE 4096U
|
||||
#define ADMIN_SSH_CONTROL_TASK_PRIORITY 3U
|
||||
@@ -92,6 +93,8 @@ typedef struct {
|
||||
|
||||
static portMUX_TYPE s_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||
static admin_session_t s_sessions[ADMIN_SSH_CONSOLE_MAX_SESSIONS];
|
||||
/* admin_ssh_console_feed_input() is called only by the sole SSH owner task. */
|
||||
static char s_completion_output[ADMIN_SSH_CONSOLE_COMPLETION_OUTPUT_CAPACITY];
|
||||
|
||||
static StaticQueue_t s_request_queue_storage;
|
||||
static uint8_t s_request_queue_bytes[ADMIN_SSH_CONSOLE_REQUEST_QUEUE_LENGTH *
|
||||
@@ -967,8 +970,13 @@ bool admin_ssh_console_feed_input(const admin_ssh_console_token_t *token,
|
||||
++*consumed;
|
||||
taskEXIT_CRITICAL(&s_lock);
|
||||
char completed[ADMIN_SSH_CONSOLE_COMMAND_LINE_CAPACITY + 1U] = {0};
|
||||
size_t candidates_length = 0U;
|
||||
bool expanded = console_completion_expand(current, completed,
|
||||
sizeof(completed));
|
||||
bool candidates_formatted = !expanded &&
|
||||
console_completion_format_matches(current, s_completion_output,
|
||||
sizeof(s_completion_output),
|
||||
&candidates_length);
|
||||
taskENTER_CRITICAL(&s_lock);
|
||||
session = &s_sessions[token->slot_index];
|
||||
if (token_matches(session, token) && !session->command_pending &&
|
||||
@@ -979,6 +987,14 @@ bool admin_ssh_console_feed_input(const admin_ssh_console_token_t *token,
|
||||
session->input_cursor = session->input_length;
|
||||
session->history_position = -1;
|
||||
(void)redraw_line_locked(session);
|
||||
} else if (candidates_formatted && candidates_length > 0U &&
|
||||
candidates_length + 2U + sizeof("admin@serial-tool> ") - 1U +
|
||||
session->input_length <=
|
||||
ADMIN_SSH_CONSOLE_OUTPUT_CAPACITY - session->output_length) {
|
||||
(void)append_output_locked(session, (const uint8_t *)"\r\n", 2U);
|
||||
(void)append_output_locked(session, (const uint8_t *)s_completion_output,
|
||||
candidates_length);
|
||||
(void)redraw_line_locked(session);
|
||||
} else {
|
||||
(void)append_output_locked(session, (const uint8_t *)"\a", 1U);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user