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

term.echo does not respect whitespace #738

Closed
Kingsy opened this issue Jan 13, 2022 · 5 comments
Closed

term.echo does not respect whitespace #738

Kingsy opened this issue Jan 13, 2022 · 5 comments
Labels
Bug resolved if issue is resolved, it will be open until merge with master

Comments

@Kingsy
Copy link

Kingsy commented Jan 13, 2022

Issue summary

When using echo() if you feed in a string on multiple lines when each line has whitespace at the beginning, and you use keepWords the resulting output trims the whitespace from the begginning of each line

  let test = `This
                is
                   a
                      test`
  term.echo(test, { keepWords: true });

Trims whitespace.

  let test = `This
                is
                   a
                      test`
  term.echo(test);

Echos normally

It is also worth mentioning that this happens on both echo and less.

Expected behavior

This
                    is
                       a
                          test

Actual behavior

Ouput

This
is
a
test

Steps to reproduce

  let test = `This
                is
                   a
                      test`
  term.echo(test, { keepWords: true });

vs

  let test = `This
                is
                   a
                      test`
  term.echo(test);

Browser and OS

This does not matter.

@jcubic
Copy link
Owner

jcubic commented Jan 14, 2022

This is expected behavior (at least this is how it was implemented). The whitespace needed to be trimmed from the beginning because the original code when wrapped sometimes had single whitespace that was at the end of the line.

foo bar baz
foo bar
 baz

This is was the reason for trimming in the code.

What is the use case when you need word wrapping and space in front?
Maybe I can do something with this, the trim was added to quickly fix the space in the front of the line issue, but it probably can be handled without the trim.

@jcubic jcubic added the Bug label Jan 21, 2022
jcubic added a commit that referenced this issue Feb 9, 2022
jcubic added a commit that referenced this issue Feb 9, 2022
@jcubic jcubic added the resolved if issue is resolved, it will be open until merge with master label Feb 9, 2022
@jcubic jcubic closed this as completed Feb 28, 2022
@jcubic
Copy link
Owner

jcubic commented Feb 28, 2022

Released in version 2.32

@Kingsy
Copy link
Author

Kingsy commented Feb 28, 2022

Hi Sorry, I just saw this.

The reason for needing this was I have code blocks inside the echo. Which obviously use whitespace as indentation.

I see a fix went live, what was it?

Thanks and apologies for the delay in the response.

@jcubic
Copy link
Owner

jcubic commented Feb 28, 2022

I'm not sure what you mean by "what was it?" the issue was because in the split_equal function sometimes there were trailing spaces when keepWords was used, so I've fixed this by using trim, but this also removed spaces in front of the lines which was your problem.

The fix is that it doesn't remove spaces in front.

I just realized that in the original issue I sometimes had one single space in front, I need to check it.

@jcubic
Copy link
Owner

jcubic commented Feb 28, 2022

I was right this introduced a bug https://codepen.io/jcubic/pen/oNoaGyv?editors=0010 there are leading spaces that should not be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug resolved if issue is resolved, it will be open until merge with master
Projects
None yet
Development

No branches or pull requests

2 participants