//// 
// tab completion

import { cmdInput } from "./dom.js"
import { commands } from "./commands.js"

export function initCompletion() {
  cmdInput.addEventListener("keydown", handleCompletion)
}

function handleCompletion(e: KeyboardEvent) {
  if (e.key !== "Tab") return

  e.preventDefault()
  const input = cmdInput.value

  for (const command of commands) {
    console.log(input, command)
    if (command.startsWith(input)) {
      cmdInput.value = command
      return
    }
  }
}