autocompleter
This commit is contained in:
parent
ec53a6420e
commit
146b0a2883
17
bin/repl
17
bin/repl
|
|
@ -169,7 +169,8 @@ function showWelcome() {
|
||||||
console.log(`${colors.bright}${colors.cyan}═══════════════════════════════════════════════════════════════${colors.reset}`)
|
console.log(`${colors.bright}${colors.cyan}═══════════════════════════════════════════════════════════════${colors.reset}`)
|
||||||
console.log(`${colors.bright}🪸 ReefVM REPL${colors.reset}`)
|
console.log(`${colors.bright}🪸 ReefVM REPL${colors.reset}`)
|
||||||
console.log(`${colors.bright}${colors.cyan}═══════════════════════════════════════════════════════════════${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}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}reset${colors.reset} - Reset VM state (keep history visible)`)
|
||||||
console.log(` ${colors.bright}exit${colors.reset} - Quit REPL`)
|
console.log(` ${colors.bright}exit${colors.reset} - Quit REPL`)
|
||||||
|
|
@ -182,10 +183,24 @@ function showWelcome() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function repl() {
|
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({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
prompt: `${colors.green}reef>${colors.reset} `,
|
prompt: `${colors.green}reef>${colors.reset} `,
|
||||||
|
completer,
|
||||||
})
|
})
|
||||||
|
|
||||||
let instructions: string[] = []
|
let instructions: string[] = []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user