"Rewind" to a Previous Step #1099
johnlindquist
started this conversation in
General
Replies: 1 comment
-
|
This is not perfect but it's working fine for my use case for now 🤷♂️ // Name: Rewind choices
import '@johnlindquist/kit'
const menu = [
{
name: 'Arcade',
choices: [
{ name: 'Inscryption', choices: () => [{ name: 'Buy' }] },
{ name: 'Hotline Miami', choices: [{ name: 'Play' }, { name: 'Delete' }] },
],
},
{
name: 'RPG',
choices: [
{ name: 'Loop Hero', choices: [{ name: 'Buy' }] },
{
name: 'The Swords of Ditto',
choices: async () => {
await wait(760)
return [{ name: 'Play' }, { name: 'Delete' }]
},
},
],
},
]
const stack = [menu]
async function start() {
const choices = stack.at(-1)
const { name } = await arg({
placeholder: 'Choose an option',
shortcuts: [
{
name: 'Back',
key: 'escape',
bar: 'left',
onPress: () => {
if (stack.length > 1) {
stack.pop()
start()
} else {
exit(0)
}
},
},
],
choices,
})
const selected = choices.find(c => c.name === name)
if (selected?.choices) {
stack.push(selected.choices)
start()
}
}
start() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Open back-to-previous-choices in Script Kit
"Back" to a Script instead of a Step
Beta Was this translation helpful? Give feedback.
All reactions