// // Promise wrappers around Nova's workspace prompts. // // Asks for confirmation before something destructive. Resolves true when the // destructive button is chosen. function confirm(message, buttonTitle = "Delete") { return new Promise((resolve) => { nova.workspace.showActionPanel( message, { buttons: [buttonTitle, "Cancel"] }, (index) => resolve(index === 0) ); }); } // Asks for a single line of text. Resolves null when cancelled, and the // trimmed text otherwise -- which may be an empty string. function input(label, options = {}) { return new Promise((resolve) => { nova.workspace.showInputPanel(label, options, (value) => { resolve(value === null || value === undefined ? null : value.trim()); }); }); } // Asks the user to pick from a list. Resolves null when cancelled. function choose(choices, options = {}) { return new Promise((resolve) => { nova.workspace.showChoicePalette(choices, options, (choice) => resolve(choice || null)); }); } module.exports = { confirm, input, choose };