Add ability to allow custom enquirer editors
See original GitHub issueI’m currently using this function inspired by (copied from) the prompt method:
function createCustomPrompt(task, Prompt, options) {
task.prompt = true;
let buffer = Buffer.alloc(64);
const outputStream = through((data) => {
buffer += data;
// eslint-disable-next-line no-control-regex
const deleteMultiLineRegexp = new RegExp(/.*(\u001b\[[0-9]*G|\u0007).*/m); 12
if (deleteMultiLineRegexp.test(buffer.toString())) {
buffer = Buffer.alloc(64);
} else {
task.output = buffer.toString();
}
});
Object.assign(options, { stdout: outputStream });
return new Prompt(options);
}
With for example the enquirer-editor like this:
import EditorPrompt from 'enquirer-editor';
import { Manager } from 'listr2';
const manager = new Manager();
manager.add({
title: 'Editor',
task: async (_, task) => {
const prompt = createCustomPrompt(task, EditorPrompt, { type: 'editor', message: 'Please Fill' });
const message = await prompt.run();
}
})
manager.runAll();
This works quite well, I was just wondering, @cenk1cenk2 do you think there’s a way to incorporate this into listr2 somehow?
Or maybe make the prompt
method from TaskWrapper
more versatile to accept custom prompt classes?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Enquirer - GitHub
Extensible - Easily create and use custom prompts by extending Enquirer's built-in prompts. Pluggable - Add advanced features to Enquirer using plugins.
Read more >enquirer-editor - npm
A prompt built with enquirer that spawns a temporary editor using the preferred editor ( $VISUAL or $EDITOR ); it will default to...
Read more >Build a JavaScript Command Line Interface (CLI) with Node.js
Finally, let's utilize Inquirer's checkbox “widget” to list the files. Insert the following code in lib/inquirer.js : askIgnoreFiles: (filelist) ...
Read more >Who will emerge as the National Enquirer's editor after its sale?
Now that the National Enquirer, the troubled supermarket tabloid, has a deal to be sold for $100 million, the guessing game is on...
Read more >Ronan Farrow: National Enquirer shredded secret Trump ...
During the first week of November 2016, the book alleges, Dylan Howard, who was editor in chief of the National Enquirer at the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So this seems like a good enough solution for me what do you think?
You pass the class of the EditorPrompt directly to the type section and pass the options in the same way.
Unfortunately, there is no type checking for the options since it can be anything but that can be done manually I preassume with
as
.I merged it with v.1.3.7. But just tested basic functionality with the
example.ts
again, needs more testing.