[Space-Lua] Prompt for input

Let’s say I’m trying to create a script that:

  • Registers a command that
  • takes input from a user (say a name of a new page)
  • prints the name of the page (as a link) at the cursor
  • navigates to the new page

I can do all of those things except prompting for input. I’m not experienced with Lua, so I might have missed something reviewing the API, but is there a way to fire a prompt in this way? I am prepared for it to be something silly and obvious.

You can use editor.prompt("The prompt"). Which isn’t really documented I think, but I’ve seen Zef using it in some other post on Git plug replacement.

But because it’s undocumented I think it’s worth noting that it might be gone or changed in the future before v2 merges to master.

EDIT:

There is also the js.window.prompt("The prompt") which uses the JS prompt function, so you’ve got options :smiley:

1 Like

Well that’s the sound of my whole world opening up, lol. Thank you, that’s exactly what I needed and it worked exactly as I’d hoped. I’m going to use editor.prompt for now and see what happens.

1 Like

In this case it’s purely a lack of not getting to document all the syscalls yet. You can assume it will stay there. You can indeed also go the js.window.prompt route, that uses the browser’s native prompt dialog then.

1 Like

Just pushed some missing API docs. Disclaimer: AI generated, so may have hallucinated.

2 Likes

Still better than nixos docs lol

1 Like