Skip to content
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

Better handling of line rewriting (such as using carriage return \r) #168

Open
hexpunk opened this issue Oct 10, 2018 · 0 comments
Open

Comments

@hexpunk
Copy link

hexpunk commented Oct 10, 2018

My particular use case for concurrently is that I'm creating a Web Extension browser add-on in Typescript. I'm using concurrently to run the Typescript compiler and Mozilla's web-ext tool at the same time.

The web-ext utility has a weird little quirk in its logging (by design). To solve the request that repeated "reloaded" messages be rewritten rather than fill the console, mozilla/web-ext#617 added these lines:

    process.stdout.write(
      `\rLast extension reload: ${(new Date()).toTimeString()}`);

This uses the \r carriage return to reset the cursor to the beginning of the line before the next log message is written. But this causes issues when using concurrently.

[web-ext] Applying config file: ./package.json
[web-ext] Running web extension from /home/user/code/project/extension
[web-ext] Use --verbose or open Tools > Web Developer > Browser Console to see logging
[web-ext] Installed /home/user/code/project/extension as a temporary add-on
[web-ext] The extension will reload if any source file changes
Last extension reload: 01:24:15 GMT-0500 (CDT)^C
user@machine:~/code/project$ yarn watch exited with code SIGINT
--> Sending SIGTERM to other processes..
[web-ext] yarn start exited with code SIGINT

user@machine:~/code/project$

First, I tried moving the \r to the ending of the string in the web-ext code. That worked...

[web-ext] Applying config file: ./package.json
[web-ext] Running web extension from /home/user/code/project/extension
[web-ext] Use --verbose or open Tools > Web Developer > Browser Console to see logging
[web-ext] Installed /home/user/code/project/extension as a temporary add-on
[web-ext] The extension will reload if any source file changes
[web-ext] Last extension reload: 02:12:56 GMT-0500 (CDT)

...but only the first time. As soon as tries to rewrite the line, we end up with a similar problem.

[web-ext] Applying config file: ./package.json
[web-ext] Running web extension from /home/user/code/project/extension
[web-ext] Use --verbose or open Tools > Web Developer > Browser Console to see logging
[web-ext] Installed /home/user/code/project/extension as a temporary add-on
[web-ext] The extension will reload if any source file changes
^Cst extension reload: 02:14:45 GMT-0500 (CDT)0500 (CDT)
user@machine:~/code/project$ yarn watch exited with code SIGINT
--> Sending SIGTERM to other processes..
[web-ext] yarn start exited with code SIGINT

user@machine:~/code/project$

Next, I tried adding the carriage return to the blacklist of characters in concurrently's logger.

// #70 - replace some ANSI code that would impact clearing lines
text = text.replace(/\u2026/g, '...');

I changed it to:

text = text.replace(/(\u2026|\r)/g, '...'); 

This attempt got a little closer. It again works as desired the first time...

[web-ext] Applying config file: ./package.json
[web-ext] Running web extension from /home/user/code/project/extension
[web-ext] Use --verbose or open Tools > Web Developer > Browser Console to see logging
[web-ext] Installed /home/user/code/project/extension as a temporary add-on
[web-ext] The extension will reload if any source file changes
[web-ext] ...Last extension reload: 02:25:09 GMT-0500 (CDT)

...but once again doesn't exactly work as desired once it prints the reload message multiple times.

[web-ext] Applying config file: ./package.json
[web-ext] Running web extension from /home/user/code/project/extension
[web-ext] Use --verbose or open Tools > Web Developer > Browser Console to see logging
[web-ext] Installed /home/user/code/project/extension as a temporary add-on
[web-ext] The extension will reload if any source file changes
[web-ext] ...Last extension reload: 02:25:09 GMT-0500 (CDT)...Last extension reload: 02:26:08 GMT-0500 (CDT)...Last extension reload: 02:26:10 GMT-0500 (CDT)...Last extension reload: 02:26:12 GMT-0500 (CDT)...Last extension reload: 02:26:13 GMT-0500 (CDT)...Last extension reload: 02:26:16 GMT-0500 (CDT)^C
user@machine:~/code/project$ yarn watch exited with code SIGINT
--> Sending SIGTERM to other processes..
[web-ext] yarn start exited with code SIGINT

user@machine:~/code/project$

I thought of specifically detecting strings beginning with \r and ending without a newline, but that seems too specific to my use case and would probably fail in other people's use cases. I'm not even entirely sure that concurrently should be the one that changes to handle this or if web-ext should change, but I'd be willing to bet there are other NodeJS command line apps out there that do similar line rewriting tricks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant