-
Notifications
You must be signed in to change notification settings - Fork 126
feat: add taskLog prompt #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adds a new taskLog prompt which renders messages then ultimately does one of the following: - If error, retain the output and render the error message - If success, clear the output and render the success message For example: ```ts const log = prompts.taskLog({ message: 'some message' }); log.message('a line of text'); log.message('another line of text'); log.message('multiple\nlines\nof\ntext'); // at this point, it will have rendered like so: // o some message // | a line of text // | another line of text // ... log.error('some error'); // if the line above runs, it will render like so: // x some error // | a line of text // | another line of text // ... log.success('some success'); // if the line above runs, it will clear and render like so: // o some success ```
🦋 Changeset detectedLatest commit: e41b36b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@example/basic • @example/changesets
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks perfect, although I'm having trouble integrating this into the svelte cli sv
. But maybe it's just too late for me.
This is how it's currently implemented:
https://github.com/sveltejs/cli/blob/ccb512d1bb48992dcff9cacadd063085789786fd/packages/cli/utils/package-manager.ts#L43-L69
Currently the following exception is printed:
TypeError: a.split is not a function
I'm assuming this is related to this pr, but from the code i don't understand exactly where that is happening.
message: 'Running npm install' | ||
}); | ||
|
||
for await (const line of npmInstall()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for await (const line of npmInstall()) { | |
for await (const line of npmInstall()) { |
Not sure if the npmInstall
makes it clear enough for the people, but I don't have any better idea
Ah I may have to tweak it a little I feel like I remember chunks from a stream not always being line based for stdout. So we probably need to join them up as a string and split again, rather than assuming each one is a line I'll take a look. That doesn't fix your problem but I noticed it when reading the usage you linked |
Actually, I think that could exactly be the problem I'm experiencing. |
We already export |
@manuel3108 (and maybe @natemoo-re review): I've added a log.message('line 0', {raw: true});
log.message('still line 0', {raw: true});
log.message('\nline 1', {raw: true}); // now we render another line because we have an explicit `\n` when it is |
Sound's logical, but sadly I'm still getting the same error. Here is a repro: https://stackblitz.com/edit/node-edenh16x?file=index.js |
that is most likely because the event handlers of if you call though the clearing seems a little buggy since some lines don't get cleared which i'd expect to have been |
@manuel3108 i fixed the bug which was causing leftover buffer lines your stackblitz works now if you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bug, it was meant to be |
two updates:
|
ok @AdrianGonz97 @manuel3108 here's where i ended up:
thoughts? i am still wondering if |
@43081j
i think the only issue i'm seeing now is that the text dimming is only partially working. it similarly fails during the normal process as well:
here's a small repro: import { setTimeout } from 'node:timers/promises';
import * as p from '@clack/prompts';
p.intro('some-app');
const t = p.taskLog({ title: 'some title', retainLog: true, limit: 3 });
t.message('foo\nbar\nbaz\nfoobar');
await setTimeout(2000); // small timeout to view it during the regular process
t.error('error!');
p.cancel('ahhh'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.message
ended up being the culprit of the partial coloring. more specifically, the coloring of the symbols of the gutter (│
).
as the symbols contained the same ansi escape codes as the message's content (e.g. \x1B[2m│\x1B[22m \x1B[2msome message goes here\x1B[22m
), the terminating end of the ansi code was not registering properly in multi-line messages.
for example:
\x1B[2m│\x1B[22m \x1B[2mfoo
\x1B[2m│\x1B[22m bar
\x1B[2m│\x1B[22m baz
\x1B[2m│\x1B[22m \x1B[22m
it thinks the sequence terminates on the \x1B[22m
in the second line. as a result, only the first line of the message is properly colored.
the solution was to have each line wrapped with the proper code:
\x1B[2m│\x1B[22m \x1B[2mfoo\x1B[22m
\x1B[2m│\x1B[22m \x1B[2mbar\x1B[22m
\x1B[2m│\x1B[22m \x1B[2mbaz\x1B[22m
its basically because in raw mode, a message can span multiple lines so what you're seeing is
from |
i had to modify what you had a little since we need the but this should all be good now. i've also renamed the |
@AdrianGonz97 @manuel3108 hows things looking on your end? if all is good, im happy to merge this once i get an approval |
For the The only thing left that we're missing is a replacement for our |
you could probably just but maybe it is worth us having some kind of option for this 🤔 though im not sure |
no worries i think this is just because we're hackily putting it into a ill open a separate PR to make that configurable some way |
Just tried this out in the draft PR for I think the new |
I already opened #284 for that FYI @natemoo-re could I get your review at some point? Once this is approved I will merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is pretty solid james, LGTM 🫡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome! My only comment is on naming—does taskLog
effectively communicate what this does? Has something like subtask()
, subprocess()
, or just pipe()
been considered?
Not going to block this on an imperfect name, though. Code looks great! Whatever you decide is great 😊
its not necessarily from a sub-process, keep in mind we may use it just for a windowed log from some arbitrary stream |
i pushed an update FYI i noticed in CI each so i've updated |
Adds a new taskLog prompt which renders messages then ultimately does one of the following:
For example:
part of bringing svelte CLI back to using clack instead of a fork