vadimdemedes / ink

🌈 React for interactive command-line apps
https://term.ink
MIT License
26.42k stars 594 forks source link

Unable to trim white spaces with `<Transform/>` #665

Open alexgorbatchev opened 2 months ago

alexgorbatchev commented 2 months ago

I'm trying to display multiple lines of text so that when they wrap, there's no leading white space. I don't fully understand why this doesn't work:

<Transform transform={(str) => str.trim()}>
  <Text color="white">{text}</Text>
</Transform>

If I add - in front of str.trim(), I see the dash. If I return hello from the transformer, I see hello for each line. But for whatever reason, removing leading white space doesn't have any effect. .trim() and .replace(/^\s*) don't have any effect.

As far as I understand, .trim() supposed to work with unicode white spaces as well, so I don't understand why this wouldn't work. What am I doing wrong?

image image