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

Windows – Color not working #28

Open
agung-wete opened this issue Apr 19, 2014 · 8 comments
Open

Windows – Color not working #28

agung-wete opened this issue Apr 19, 2014 · 8 comments

Comments

@agung-wete
Copy link

Hi

Using windows environment
try to use --help, got this errors, just right before filename appeared=

The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.

Yes, 3 in a row.

Thanks

@nategood
Copy link
Owner

Does this happen with the examples in /examples?

@agung-wete
Copy link
Author

yes

@stratease
Copy link

Does this lib support windows env? I imagine that would be quite difficult to create parallel feature support

@nategood
Copy link
Owner

nategood commented Aug 5, 2014

I don't have a windows machine or VM handy to debug. Might have something to do with the Colors.php library. Have you tried running examples directly from the Colors.php library?

@nategood nategood changed the title Color not working Windows – Color not working Aug 5, 2014
@taishar
Copy link

taishar commented Sep 22, 2014

Hi,
This is happening to me as well. It looks like its coming from Terminal::tput().

@morganprecision
Copy link

Specifically I think the issue is that /dev/null cannot be found in the Windows environment (the Terminal::tput() method redirects to /dev/null).

I created a C:\dev\null folder on the Windows box I am working with to see what would happen. I then started getting "Access is denied" messages instead of "The system cannot find the path specified."

@cpalm1974
Copy link

cpalm1974 commented Dec 1, 2016

This happens when executing "tput" to get the width of the terminal in Terminal.php line 51 ff.

    private static function tput($default, $param = 'cols')
    {
        $test = exec('tput ' . $param . ' 2>/dev/null');
        if (empty($test))
            return $default;
        $result = intval(exec('tput ' . $param));
        return empty($result) ? $default : $result;
    }

It would be more optimal if at first the os is detected with the PHP_OS constant and check for the first 3 characters = "WIN".
Even for Linux environments it could be optimal to execute "which tput" at first to see if it's there and accessible.
For Win Environments I think there is not an optimal way to get the width. I think it's best to execute "MODE CON:" as this is available in every Windows installation (I think even since MS-DOS 3.3 :) )
The returned string gives console parameters like the width, lines and so on. But the output is language dependent. So in my German installation something like:

Status von Gerät CON:
---------------------
    Zeilen:          300
    Spalten:         99
    Wiederholrate:   31
    Verzögerungszeit:1
    Codepage:        850

So you'd have to maybe regex to get the second line after "-----".

@cpalm1974
Copy link

I think the tput function could be optimized like the following. It's working good in my environment.

    private static function tput($default, $param = 'cols')
    {
    	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
    		return $default;
    	$path = trim(shell_exec('which tput'));
    	if (empty($path))
    		return $default;
        $test = exec('tput ' . $param . ' 2>/dev/null');
        if (empty($test))
            return $default;
        $result = intval(exec('tput ' . $param));
        return empty($result) ? $default : $result;
    }

Maybe you can import the changes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants