Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Keeping question at the end of console

Open rafalmaksymiuk opened this issue 7 years ago • 10 comments

Hi,

Is there any way to make inquirer question persistently at the end of console output? I have script with multiple asynchronous operations outputting to console, but I would like to have inquirer question persistent at the end of console no matter what - so users won't miss it even if a lot of additional text is logged.

Alternatively can I force rerendering from code? It is done internally whenever there is some user interaction with console - I would like to simply have such hook from script.

Thanks, Rafal

rafalmaksymiuk avatar Jul 11 '18 17:07 rafalmaksymiuk

Hey @PaQ666,

This isn't something I've tried making work. You could get some inspiration from the BottomBar module in this repository - but it's not working out of the box with prompts.

SBoudrias avatar Jul 15 '18 02:07 SBoudrias

Would love to see this feature too, it's getting very messy when other console logs are displayed in the prompt.

adamreisnz avatar Aug 13 '18 03:08 adamreisnz

Any update on this issue?

adamreisnz avatar May 29 '19 10:05 adamreisnz

@adamreisnz it's not something I plan working on myself. I'm happy to help review the concept (before any PR) if someone wants to spend time working on such a feature.

SBoudrias avatar May 29 '19 10:05 SBoudrias

Would you be open to adding a new method to inquirer, e.g. something like .log() which could be used to log a simple line of text to the console, which would then push the current prompt down again? This log could then be used instead of regular console.log commands, which tend to log data all over (or under) the inquirer interface.

adamreisnz avatar May 29 '19 22:05 adamreisnz

Could you provide an example how an end-user would use inquirer.log()? I'm not sure I fully understand in which context this is necessary.

SBoudrias avatar May 30 '19 13:05 SBoudrias

Yes, I'll provide a use case demo in a minute

adamreisnz avatar May 30 '19 21:05 adamreisnz

Right, that minute took longer than anticipated.

Here's how I use inquirer:

image

We have a little diagnostics script which allows us to connect to our hardware via serial port and send a variety of commands, as per above.

Whenever we send a command, we output the JSON string that gets sent and anything that is received on the serial port, for debugging purposes and diagnostics:

image

Depending on the timing, these JSON logs can show up all throughout the inquirer interface, because a regular console.log doesn't know what inquirer is doing:

image

In this latter example, the moment I navigate commands, the green received JSON response is overwritten by inquirer, because it overwrites the line in the console.

So what I'm asking for, is a method on Inquirer to log a line to the console, and then have that line be logged above the last inquirer prompt, so that it persists i n the console and won't be erased by subsequent prompts.

Much like happened in my first example:

image

These two lines are persisted, but the green JSON from my second example has disappeared:

image

So what I'm asking for is a way to "safely" log generic contents to the console, while an inquirer prompt is active.

Hope this makes sense.

adamreisnz avatar Jun 04 '19 07:06 adamreisnz

Hey @SBoudrias, I have a somewhat similar issue. In my case, the previous prompt is shown again in terminal after console.log or this.log, hence the same question is printed twice -

  1. Once, when it is supposed to, when user has to answer it.
  2. Second, after user enters the answer, I validate it asynchronously and log something to terminal, the question is printed again WITH the answer and the subsequent question.

I don't want this, I want a prompt to be shown only once.

Screenshot 2019-06-13 at 3 36 30 PM

Nikhil-Vats avatar Jun 13 '19 10:06 Nikhil-Vats

Here is another example of this issue:

Untitled_ Jul 28, 2020 2_02 PM (1)

I have a inquirer prompt asking for a user selection, then returning a response from a database, then looping. The prompts are overwriting the response tables.

KeithBillings avatar Jul 29 '20 20:07 KeithBillings