diff --git a/bin/repl b/bin/repl index 647f574..7a15277 100755 --- a/bin/repl +++ b/bin/repl @@ -169,7 +169,8 @@ function showWelcome() { console.log(`${colors.bright}${colors.cyan}═══════════════════════════════════════════════════════════════${colors.reset}`) console.log(`${colors.bright}🪸 ReefVM REPL${colors.reset}`) console.log(`${colors.bright}${colors.cyan}═══════════════════════════════════════════════════════════════${colors.reset}`) - console.log(`\nType instructions one at a time. Commands:`) + console.log(`\nType instructions one at a time. Use ${colors.bright}Tab${colors.reset} for autocomplete.`) + console.log(`\nCommands:`) console.log(` ${colors.bright}clear${colors.reset} - Clear screen and reset state`) console.log(` ${colors.bright}reset${colors.reset} - Reset VM state (keep history visible)`) console.log(` ${colors.bright}exit${colors.reset} - Quit REPL`) @@ -182,10 +183,24 @@ function showWelcome() { } async function repl() { + // Get all opcode names for autocomplete + const opcodes = Object.keys(OpCode) + .filter(key => isNaN(Number(key))) // Filter out numeric keys (enum values) + + const commands = ['clear', 'reset', 'exit', 'quit'] + const completions = [...opcodes, ...commands] + + // Autocomplete function + function completer(line: string) { + const hits = completions.filter(c => c.toLowerCase().startsWith(line.toLowerCase())) + return [hits.length ? hits : completions, line] + } + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, prompt: `${colors.green}reef>${colors.reset} `, + completer, }) let instructions: string[] = []