Display SSH completion candidates for ambiguous prefixes

This commit is contained in:
2026-08-30 23:00:01 +02:00
parent 21d1b12f31
commit 35a6f32e8b
5 changed files with 68 additions and 2 deletions
+41
View File
@@ -270,6 +270,47 @@ bool console_completion_expand(const char *line, char *completed, size_t capacit
return true;
}
typedef struct {
char *output;
size_t capacity;
size_t length;
bool complete;
} completion_format_context_t;
static bool format_completion_candidate(const char *candidate, void *context)
{
completion_format_context_t *result = context;
size_t candidate_length = strlen(candidate);
if (candidate_length + 2U > result->capacity - result->length) {
result->complete = false;
return false;
}
memcpy(result->output + result->length, candidate, candidate_length);
result->length += candidate_length;
result->output[result->length++] = '\r';
result->output[result->length++] = '\n';
return true;
}
bool console_completion_format_matches(const char *line, char *output, size_t capacity,
size_t *output_length)
{
if (line == NULL || output == NULL || output_length == NULL || capacity == 0U) {
return false;
}
completion_format_context_t result = {
.output = output,
.capacity = capacity,
.complete = true,
};
console_completion_visit(line, format_completion_candidate, &result);
if (!result.complete) {
return false;
}
*output_length = result.length;
return true;
}
static ssize_t console_read_with_late_terminal_upgrade(int file_descriptor,
void *buffer,
size_t size)