Quick Keys

Quick Keys

A quick key allows you to bind a single key to submit a prompt.

You can add quick keys inside the "hint" if you don't want to bother with choices:

//Type "y" or "n"
let confirm = await arg({
placeholder: "Eat a taco?",
hint: `[y]es/[n]o`,
})
console.log(confirm) //"y" or "n"

Otherwise, add the quick keys in the name of the choices and it will return the quick key:

// Type "a", "b", or "g"
let fruit = await arg(`Pick one`, [
`An [a]pple`,
`A [b]anana`,
`a [g]rape`,
])
console.log(fruit) //"a", "b", or "g"

You can add a value, then typing the quick key will return the value:

// Type "c" or "a"
let vegetable = await arg("Pick a veggie", [
{ name: "[C]elery", value: "Celery" },
{ name: "C[a]rrot", value: "Carrot" },
])
console.log(vegetable) //"Celery" or "Carrot"
Discuss Post