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

Console with emoji mess up the formatting #37904

Closed
HarasimowiczKamil opened this issue Aug 21, 2020 · 4 comments · Fixed by #40524
Closed

Console with emoji mess up the formatting #37904

HarasimowiczKamil opened this issue Aug 21, 2020 · 4 comments · Fixed by #40524

Comments

@HarasimowiczKamil
Copy link

Symfony version(s) affected: 5.1.3

Description

Emoji mess up the formatting. The border is not even.

How to reproduce

protected function execute(InputInterface $input, OutputInterface $output)
{
    $io = new SymfonyStyle($input, $output);
    $io->error("Some error message \u{1F625}");
    return Command::FAILURE;
}

Screen shot 2020-08-21 09-02-27

Possible Solution

Something with string length count and encoding

Additional context

@someniatko
Copy link

I think if you somehow add a font with monospace emojies to your system, and let your terminal use this font, it will fix itself.
My guess it's not a Symfony's, but your OS / fonts / terminal combination's issue.

@ogizanagi
Copy link
Member

ogizanagi commented Aug 21, 2020

I think it's actually an issue on how the block length is computed by SymfonyStyle. Actually updating \Symfony\Component\Console\Helper\Helper::strlen to use the String component width method would solve this (at least for this simple case. Also how could it work with emojis like 👨‍👩‍👧 ("👨\U+200D👩\U+200D👧")?).

Since the String component is required by symfony/console since 5.1, perhaps we should update the component to use it more extensively.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@chalasr
Copy link
Member

chalasr commented Mar 22, 2021

Not stale.

@carsonbot carsonbot removed the Stalled label Mar 22, 2021
nicolas-grekas added a commit that referenced this issue Mar 23, 2021
…risson)

This PR was submitted for the 5.x branch but it was merged into the 5.2 branch instead.

Discussion
----------

[Console] fix emojis messing up the line width

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37904
| License       | MIT

Description
========

The emojis, because they take as much space as two characters, would cause the console to display too many spaces to complete a line, which made it uneven, as described in the issue.

The fix uses the `width` function instead of `strlen`. To answer @ogizanagi's comment, yes it does work with "composed" emojis.

Before :

![image](https://user-images.githubusercontent.com/11477247/111832081-9d72b100-88f0-11eb-8eda-65ee480c898d.png)

After :

![image](https://user-images.githubusercontent.com/11477247/111832103-a6638280-88f0-11eb-802e-838d97f61c81.png)

Other changes
==========

Removed two unused lines of code, the value of `$messageLineLength` was never used.

Note
====
I'd like to add some tests, but I don't know how since I think this depends on console client width ?

Thanks for your reviews 🙏

Commits
-------

36b36dc [Command] fix emojis messing up the line width
OndraM added a commit to OndraM/steward that referenced this issue Apr 1, 2021
OndraM added a commit to lmc-eu/steward that referenced this issue Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants