open-cli-tools / open-cli-tools/concurrently

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

Open
#168 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.9k
Forks
281
Avg merge
17h 12m
Merged PRs (30d)
1

Description

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, https://github.com/mozilla/web-ext/issues/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.
https://github.com/open-cli-tools/concurrently/blob/a96b9cf8f698ef6e291af595965f36d24c6bd083/src/logger.js#L90-L91

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the logger logic in src/logger.js around the character blacklist, then reproduce the web-ext output containing repeated carriage-return updates alongside normal lines. Done means carriage-return rewriting remains correct across repeated messages without corrupting subsequent concurrently output.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.