command-line-usage icon indicating copy to clipboard operation
command-line-usage copied to clipboard

Issue with "\" in content

Open Jakabi107 opened this issue 2 years ago • 2 comments

I've wanted to display my own logo (banner) in my project usage, yet it couldn't handle the "\"-characters properly.

Now I took the banner example from your Wiki and changed the previous logo with mine.

just removed const chalk = require('chalk') and replaced chalk.red( ... ) with header

code

Screenshot 2023-05-07 at 15 33 12

The problem is - when I execute it:

green is a normal console.log() and normal is the one generated.

result

Screenshot 2023-05-07 at 15 42 18

The banner is made with String.raw, so every "\" is replaced with "\\", that means it is written by eg. console.log(). Yet the libary does skip them anyway. I brute forced a little bit and found out it takes 4 or in String.raw 2 (2*2) "\" to write one into the usage. Maybe the formater refactors between strings and deletes some "\" or delets them by some replace functions?

EDIT:

Quick fix for users: use Straing.raw methode as explained above and append .replaceAll("\\","\\\\") at the End.

File: test.js.zip

Hope I could help, Jakabi

Jakabi107 avatar May 07 '23 13:05 Jakabi107

The code you supplied in the zip file works correctly for me in both iTerm2 and Terminal on the mac, I think the issue is with your terminal.. Please try it in a few different terminals then let me know which terminals fail on which operating systems - thanks.

Screenshot 2023-05-08 at 10 04 39

75lb avatar May 08 '23 09:05 75lb

Just realised send you the wrong file... I already fixed it in this one😕 I'm very sorry.

real file test.js.zip

Jakabi107 avatar May 08 '23 10:05 Jakabi107