nunomaduro / termwind

🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.
MIT License
2.29k stars 78 forks source link

Color is not applied on windows terminal with wsl. #109

Closed opuu closed 2 years ago

opuu commented 2 years ago

Default colors are not being applied to html element on windows terminal (using windows sub system for linux). Also the parser trying to parse special characters as html, in this case <== gives an warning.

require __DIR__ . '/vendor/autoload.php';

use function Termwind\{render};

// single line html...
render('<div class="p-1 bg-green-300">Termwind</div><span class="text-red-200"><== this was supposed to be green.<span>');

Output

image

nunomaduro commented 2 years ago

@opuu Can you try to pull request a fix for those two issues?

opuu commented 2 years ago

@nunomaduro I'll try. Have you tested this on windows? I am getting the same result on CMD, PowerShell and Windows Terminal. But on Linux and Visual Studio Code integrated terminal it seems to work as expected.

And adding libxml_use_internal_errors(true); after constructing the DOMDocument class fixes the parser issue but this may omit other errors and warnings as well, which needs to be manually handled.

CMD

cmd

PowerShell

powershell

PowerShell (Windows Terminal)

ps-terminal

Visual Studio Code

vscode

nunomaduro commented 2 years ago

cc @xiCO2k

xiCO2k commented 2 years ago

@opuu thanks for the report, we did not spent anytime checking it on Windows, but we need too. Thanks for bringing that to the table.

xiCO2k commented 2 years ago

@opuu We will probably need to have the LIBXML_NOERROR added to have support for the HTML5 tags like <header> so that could be a solution for this issue

opuu commented 2 years ago

@xiCO2k Yes adding LIBXML_NOERROR to loadHTML will fix the issue.

It will also stop showing errors for invalid html. But this should not be a problem as the ending tag is automatically generated from the starting tag, and termwind is replacing unsupported tags with div.

<?php

$dom = new DOMDocument();

$dom->loadHTML('<header data-attribute="foo">bar<', LIBXML_NOERROR | LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);

echo $dom->saveHTML();

?>

And here is the official documentation from Microsoft about text formatting on console.

xiCO2k commented 2 years ago

Yes if you to contribute with that change I will be happy to review!

opuu commented 2 years ago

@xiCO2k After spending hours debugging the code, I found nothing wrong that can cause the color issue, reading symphony console documentation I found that windows command console does not support ANSI by default. You have to enable it, and the process is very dirty.

By default, the Windows command console doesn't support output coloring. The Console component disables output coloring for Windows systems, but if your commands invoke other scripts which emit color sequences, they will be wrongly displayed as raw escape characters. Install the Cmder, ConEmu, ANSICON, Mintty (used by default in GitBash and Cygwin) or Hyper free applications to add coloring support to your Windows command console.

I am creating a PR for the HTML5 compatibility issue.

xiCO2k commented 2 years ago

Thanks @opuu. Really appreciate your time. Looking forward to the PR.