commando icon indicating copy to clipboard operation
commando copied to clipboard

Windows – Color not working

Open agung-wete opened this issue 10 years ago • 8 comments

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

agung-wete avatar Apr 19 '14 13:04 agung-wete

Does this happen with the examples in /examples?

nategood avatar Jun 11 '14 02:06 nategood

yes

agung-wete avatar Jun 11 '14 13:06 agung-wete

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

stratease avatar Jun 11 '14 17:06 stratease

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 avatar Aug 05 '14 02:08 nategood

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

taishar avatar Sep 22 '14 10:09 taishar

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."

morganprecision avatar Sep 30 '14 21:09 morganprecision

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 avatar Dec 01 '16 07:12 cpalm1974

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...

cpalm1974 avatar Dec 01 '16 22:12 cpalm1974