Prompt message isn't displayed on first line
kamranpoladov opened this issue · 6 comments
Expected Behavior
The prompt message should appear once the shell is bootstrapped
Current Behavior
The prompt message appears only after either newline or backspace is hit.
Note that there is no red arrow on the first line (before .screenfetch
) but only upcoming ones
Possible Solution
Add
rl.emit('line');
after
nestjs-shell/lib/shell.bootstraper.ts
Line 33 in f55d81f
in order to emit 'line' immediately after bootstrap
Steps to Reproduce
Run the application as intended since this issue literally appears in README.md meaning that it exists as is
Environment
Node.js version 14.17.0
Possible Implementation
I can submit a PR with suggested changes if this is accepted as a valid issue
Hi!
I was aware of this issue but didn't know how and didn't have time to fix it, so PR would be extremely helpful and appreciated :D
Hi @kamranpoladov. Thanks again for contributing 😃. I merged the PR, all tests are passing
but it doesn't seem to change much on MacOS. The prompt still doesn't appear after the bootstrap 🤔 I am fine with that, just wondering if it's an OS-related issue or something with the code
@bmstefanski so I have built the package locally (from the fork on https://github.com/kamranpoladov/nestjs-shell) and for now, I'm using it with $ yarn link
command. It seems to work as expected (I am just using >
for prompt instead of arrow symbol)
Can you maybe check if the build was successful and the changes indeed applied?
By the way, I am running Ubuntu but I don't think it's OS-related issue to be honest
@kamranpoladov ahhh yes! 😆 I forgot to build the project before running npm publish. Sorry for the confusion.
It is now published in version 1.4.1
. But the prompt appears in the same line as the last log message. I think this is because the log is printed after the bootstrap event and it overlaps, but not sure honestly :D
Indeed, the last log is printed after onApplicationBootstrap
is executed. One workaround could be to set a slight delay on shell bootstrap
public onApplicationBootstrap(): void {
setTimeout(() => this.shellFacade.bootstrap({
prompt: chalk.red('⤳'),
messages: {
notFound: chalk.bgGreen.black.bold(' Sorry, there is no such command as $input '),
wrongUsage: chalk.yellow.bold(`Wrong usage: $command ${chalk.red('$pattern')}`),
},
shellPrinter: (value) => console.log(value),
}), 1);
this.shellFacade.registerComponents(new HelpCommandComponent(this.shellFacade))
}
It looks mildly ugly but gets the job done
Perhaps this delay should rather be handled by the library (e.g. use setTimeout
to emit the line
event). But there's probably a better way of fixing this issue 🤔