-
Notifications
You must be signed in to change notification settings - Fork 292
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
View data in CLI #319
Comments
That's weird - are you running them both in the same terminal? In either case - your terminal doesn't seem to support unicode and/or color codes. On windows? |
Yes, on windows ) |
Could you |
I am find solution
|
Yeah that turns off the colors, but it's not supposed to look like that to begin with:
I'd like your help to fix this, but I have no idea when I'll get around to it |
never code on windows 🙈 😂 |
Now that Windows 11 & Microsoft Terminal support VT100 colors and UTF-8 table characters, I'm looking for a way to enable it back on CLI! ConfigKint config// enable cli colors (only works on *nix environment)
Kint\Renderer\CliRenderer::$cli_colors = true;
// force utf-8 output on windows
Kint\Renderer\CliRenderer::$force_utf8 = true; VT100 processing
Console Emulator
General Advice & Conclusions
I have to agree with you, but just a minor correction: never code on (old, non-modern versions of) windows! Off-topic rantsMicrosoft did a very good overhaul of the outdated console host and related console stuff in recent years, I can confidently say that the new stuff is on par with macOS and Linux-level CLI development. Also, PHP on CLI for the win! I don't like any of the "Python" cli development, personally. IMHO, the syntax of PHP is far superior! :) |
@DRSDavidSoft That's great! I don't code on windows here, so I'd have to set up a VM to test this stuff myself. I know about WSL but I didn't know it'd work like this with just normal cmd nowadays (Or are these screenshots with WSL?) Does this basically mean that in normal circumstances you can run kint from a windows terminal and colors and utf will work out of the box? If that's the case I may just change the defaults, remove the windows-specific code there, and close this issue. |
@jnvsor Thanks for all your work! I mainly code on Windows at the office, and for a project, I'm developing a CLI script with PHP. Note: I haven't used WSL, it's just native The screenshots you see are native Sidenote (off-topic): I've been using Cygwin since long before WSL/1 was a thing, so I don't have much experience with WSL either -- although, in my tests, mingw/Cygwin build of PHP behave the same.
Considering Windows 11 and PHP 8.x, yes! But since Kint is still supporting the older PHP versions on Windows, the time hasn't come yet to do this. I'm sad to say, until you bump the minimum supported PHP version by Kint from For now, I'd suggest to consider something like this:
Here's a code for that: Kint\Renderer\CliRenderer::$force_utf8 = false;
if ( substr(PHP_OS, 0, 3) === 'WIN' )
Kint\Renderer\CliRenderer::$force_utf8 = checkWindowsVT100();
function checkWindowsVT100()
{
if ( !function_exists('sapi_windows_vt100_support') )
return false; // note: no need to check for PHP 5.x as this function only exist on PHP 7.2.0
if ( sapi_windows_vt100_support(STDOUT) )
return true;
return false;
} A bit of history: After I upgraded to PHP/7.4, I modified my existing logging utilities to output in color. A couple of days ago, I needed to dump a variable, and I remembered to use Kint, so I checked to see if it would work in my project. It did, however, the color was turned off by default! So I dig into the code to see if I could make the colors for Kint output correctly, and it does! Since PHP/7.x is EOL now, and the versions of Windows 10 (and older) that does not support VT100 correctly are also EOL, I think it's a good time to implement the code I suggested, so Kint would output in all its glory, with the unicode tables, and the colors! After PHP 5 and 7 support is dropped from Kint (maybe in 4-5 years, when Windows 10 is also EOL), then it would be possible to treat a Windows/PHP environment the same as on Linux and macOS (and thus removed all Windows-specific code for CLI). Anyways, sorry for the long comment! I'll be glad to help, if any. Especially, with testing, if needed. |
@DRSDavidSoft That's great!
I was worried about that too: I'd have to postpone this until v5. But since we have a function to check for support I can slap this in a minor release instead. The only thing I'm worried about is this:
What kind of overlap do we have between buggy windows versions that won't show utf8 and/or color control codes correctly that Or should I just ignore that edge case entirely and just check with the function? (I'll take your word for it since you're half the userbase of this feature hehe) Here's my WIP diff, if you want to give it a whirl: @@ -69,8 +76,8 @@ class CliRenderer extends TextRenderer
{
parent::__construct();
- if (!self::$force_utf8) {
- $this->windows_output = KINT_WIN;
+ if (!self::$force_utf8 && KINT_WIN && (!KINT_PHP72 || !\sapi_windows_vt100_support(STDOUT))) {
+ $this->windows_output = true;
}
if (!self::$terminal_width) { |
@jnvsor Awesome, I did some research in order to answer confidently.
That would be a good idea, I'll be glad to test Kint 4.1. Also, I figure there could be other kinds of PHP-5.6 related code that might get dropped in Kint 5, when backwards compatibility for PHP-5.6 is no longer needed.
I did some tests to be sure, and also looked at the PHP source code. This function will not return true, if the host console doesn't support VT100. According to the PHP source code, it's calling the In short, you can be assured that the terminal will support VT100 for certain, if this functions returns true.
The thing is, if you check with On the other hand, what if it returns For the false negative, I'd say you can safely ignore it, as the worst case scenario is that the user would be missing the color/utf-8, but the results would render correctly (same as the current Kint 4.0 behavior). In this unlikely scenario, the users can either a) force-enable color output for Kint themselves, b) don't care and ignore not having the colors, c) upgrade their OS to a supported one. Honestly, the Windows 7 and the buggy Windows 10 releases are all EOL (the same way all PHP 5.x and PHP 7.x are EOL now), so I wouldn't stress on that much. You can also test for other terminal emulator (such as ConEmu) specifically like this, but that's a whole another matter entirely. if ( filter_var(getenv('ConEmuANSI'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) === true )
Kint\Renderer\CliRenderer::$force_utf8 = true; Pros: Better support for ConEmu, which is an awesome terminal emulator
So clean and efficient! I didn't know there were macros like I tested it out, and the logic also seems to make sense. The only issue I'd see with this is the false negatives, which as I mentioned, I don't consider to be a top priority. In fact, it's up to the terminal emulator to announce to PHP and Kint that it supports VT100! I'm not sure if you're doing this, but you need to also check for the All Linux-based terminal emulators will set this environment variable properly, which means that the terminal emulator is announing to the application that it will support the VT100 escape codes. If it's missing, you can still output the VT100 color codes, but there is NO guarantee that what will the terminal emulator do with this. In fact, that's part of the problem on Windows: the As always, I'm super sorry for the really long comment, hopefully it wasn't entirely off-topic or useless. Looking forward for the changes to Kint |
@michabbb Hey Micheal, may I ask why the downvote? Is it something that I said? |
Yeah but they're undocumented and only used internally so you shouldn't rely on them in your own code :) It's actually giving me trouble with psalm because psalm gets their type wrong and won't let me fix it with annotations because they're constants...
I remember using kint in CLI on windows with the git shell installation (Though I avoided windows as much as possible) and it worked with colors just fine, though that might have been because I was running it from a linux server through SSH...
I plan on replacing the current windows output with plain ascii anyway since it's clearly not working correctly. That should improve things for basically everyone.
That's a good point. I know some programs ( I'll dig into it, but I doubt I'll add checks for colors in linux. (At least in 4.x) I personally use |
I believe that's exactly it, the raw output is passed from Windows to Linux in this scenario, and the Windows-side doesn't care what's that being passed, escape code, or some other binary data. Then, in the Linux side, the GUI Terminal emulator (like GNOME Terminal or Konsole) actually parse and render the received escape code data. The reverse can also work correctly, e.g. if I ssh into my Linux box from Windows, I can run
That's a good idea, although I suggest mostly focusing on the general color/utf-8 based rendering, as it's more cross-platform, and Microsoft is finally getting their act together to fix these annoying bugs, so the In the future (especially on Windows 11), I expect the VT100-based codes to work 100% correctly out of the box, like how it does now on macOS, and Linux.
That's also a great idea! I'd suggest having a general That way, the user can set If it's on Windows, check for This can allow the codebase to be simplified in this regard, while also becoming more logically understandable. In any case, if the either Once again, sorry for the long comment, thanks for your development, I really appreciate it! :D |
Yeah it's mostly just because we still support < 7.2. I'd love to get rid of the edge cases, but not just yet
Well that already exists it's Edit: Anyway it's 4am here so I should sleep. Try 0aa8437 and see if that does the job, then I'll push it to master |
Confirmed that this works correctly
Thanks again, and good night! n/b 7.2-7.4 also works in place of 8.1, May I also suggest the following flags:
reason: in this case, or:
reason: I believe the term However, the term Also, instead of this: [' ', '=', ' ', '|', ' ', '-', ' '], I suggest the following: ['.', '=', '.', '|', '\'', '-', '\''], |
Great!
The
My first thought would be that the
I tried extending the top/bottom and sides and it didn't look right either:
In the end I don't want to put much time into something hopefully no users will ever have to see, so I'll leave it like that. If anyone prefers the � they can always go back hehe
|
Never thought I'd be closing this one without a mountain of work. Glad to get it off the docket :) |
I have file tst.php
run this file in cli with php-kint v3
and with php-kint v1
Why data displaying is not correct in php-kint v3?
The text was updated successfully, but these errors were encountered: