feat: add support for shell builtins to command completion
This commit is contained in:
@@ -12,4 +12,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MONTAUK_BUILD_NUMBER 79
|
#define MONTAUK_BUILD_NUMBER 82
|
||||||
|
|||||||
@@ -436,6 +436,8 @@ extern "C" void _start() {
|
|||||||
if (ev.scancode == SC_TAB) {
|
if (ev.scancode == SC_TAB) {
|
||||||
line[pos] = '\0';
|
line[pos] = '\0';
|
||||||
|
|
||||||
|
if (pos == 0) continue;
|
||||||
|
|
||||||
char* table[128] = { };
|
char* table[128] = { };
|
||||||
int n = get_completions(line, table, 128);
|
int n = get_completions(line, table, 128);
|
||||||
|
|
||||||
|
|||||||
@@ -130,3 +130,18 @@ int exec_external(const char* cmd, const char* args);
|
|||||||
// ---- Tab completion (tabcompletion.cpp) ----
|
// ---- Tab completion (tabcompletion.cpp) ----
|
||||||
|
|
||||||
int get_completions(char* string, char** array, int arrayMax);
|
int get_completions(char* string, char** array, int arrayMax);
|
||||||
|
|
||||||
|
// ---- Shell builtins ----
|
||||||
|
|
||||||
|
constexpr const char* shell_builtins[] = {
|
||||||
|
"help",
|
||||||
|
"ls",
|
||||||
|
"cd",
|
||||||
|
"pwd",
|
||||||
|
"echo",
|
||||||
|
"set",
|
||||||
|
"unset",
|
||||||
|
"true",
|
||||||
|
"false",
|
||||||
|
"exit"
|
||||||
|
};
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <montauk/string.h>
|
#include <montauk/string.h>
|
||||||
#include <montauk/syscall.h>
|
#include <montauk/syscall.h>
|
||||||
|
#include "shell.h"
|
||||||
|
|
||||||
#define RD_MAX 128
|
#define RD_MAX 128
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ int get_completions( // returns no. of results
|
|||||||
int arrayMax
|
int arrayMax
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
// --- System commands (0:/os/*.elf) ----
|
||||||
const char* names[RD_MAX] = { };
|
const char* names[RD_MAX] = { };
|
||||||
|
|
||||||
int n = montauk::readdir("0:/os", names, RD_MAX);
|
int n = montauk::readdir("0:/os", names, RD_MAX);
|
||||||
@@ -89,5 +91,19 @@ int get_completions( // returns no. of results
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- Shell builtins ----
|
||||||
|
|
||||||
|
size_t builtins_count = sizeof(shell_builtins) / sizeof(const char*);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < builtins_count; i++) {
|
||||||
|
if (montauk::starts_with(shell_builtins[i], (const char*)string)) {
|
||||||
|
if (r > arrayMax)
|
||||||
|
break;
|
||||||
|
|
||||||
|
array[r] = (char *)shell_builtins[i];
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user