hoaproject / Console

The Hoa\Console library.
https://hoa-project.net/
366 stars 32 forks source link

Window::getSize() => tput: unknown terminfo capability 'cols\nlines' #21

Closed SebastienElet closed 10 years ago

SebastienElet commented 10 years ago

Hello,

I have the error :

tput: unknown terminfo capability 'cols\nlines'

Here is the code to reproduce the error :

<?php
require 'vendor/autoload.php';
var_dump(Hoa\Console\Window::getSize());

I use the package php5-cli on debian 7.5. The PHP Version => 5.4.4-14+deb7u9

I use a local tmux -> ssh -> zsh 4.3.17

The fallowing command is working :

$ echo "cols\nlines" | tput -S
272
91
Hywan commented 10 years ago

Hello :-),

Can you print the $_SERVER variable in a PHP script running in CLI please? I would like to know if the TERM variable is available. Also, is PHP running with a specific user that has a shell?

When you say that echo "cols\nlines" | tput -S is working, is it inside a tmux instance?

SebastienElet commented 10 years ago

var_dump of $_SERVER :

array(29) {
  ["LANG"]=>
  string(11) "fr_FR.UTF-8"
  ["USER"]=>
  string(4) "root"
  ["LOGNAME"]=>
  string(4) "root"
  ["HOME"]=>
  string(5) "/root"
  ["PATH"]=>
  string(155) "/usr/local/freeswitch/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/npm/bin:/usr/local/sbin:/usr/local/bin:/usr/sb
in:/usr/bin:/sbin:/bin:/usr/bin/X11"
  ["MAIL"]=>
  string(14) "/var/mail/root"
  ["SHELL"]=>
  string(8) "/bin/zsh"
  ["SSH_CLIENT"]=>
  string(23) "XX.XX.XX.XX 55551 22"
  ["SSH_CONNECTION"]=>
  string(37) "XX.XX.XX.XX 55551 XX.XX.XX.XX 22"
  ["SSH_TTY"]=>
  string(10) "/dev/pts/3"
  ["TERM"]=>
  string(15) "screen-256color"
  ["LANGUAGE"]=>
  string(8) "fr_FR:fr"
  ["SHLVL"]=>
  string(1) "1"
  ["PWD"]=>
  string(10) "/root/test"
  ["OLDPWD"]=>
  string(5) "/root"
  ["HISTSIZE"]=>
  string(4) "4096"
  ["HISTFILE"]=>
  string(17) "/root/.zsh_istory"
  ["PROMPT"]=>
  string(78) "%(?.%{%}✔.%{%}✖) %{%}%{%} %20<… <%/%<< %{%}❯ "
  ["RPROMPT"]=>
  string(26) "%{%}%n@%m%{%}"
  ["_"]=>
  string(12) "/usr/bin/php"
  ["PHP_SELF"]=>
  string(8) "test.php"
  ["SCRIPT_NAME"]=>
  string(8) "test.php"
  ["SCRIPT_FILENAME"]=>
  string(8) "test.php"
  ["PATH_TRANSLATED"]=>
  string(8) "test.php"
  ["DOCUMENT_ROOT"]=>
  string(0) ""
  ["REQUEST_TIME_FLOAT"]=>
  float(1401038003.974)
  ["REQUEST_TIME"]=>
  int(1401038003)
  ["argv"]=>
  array(1) {
    [0]=>
    string(8) "test.php"
  }
  ["argc"]=>
  int(1)
}

echo "cols\nlines" | tput -S is working with or without tmux.

Hywan commented 10 years ago

What about executing:

<?php

var_dump(shell_exec('echo "cols\nlines" | tput -S'));

(without Hoa actually) If it fails, it is an issue related to PHP. What the user of PHP? Has this user a shell?

Edit: it seems that your run the script in root. Is it normal?

Hywan commented 10 years ago

I am summarizing the yesterday IRC discussion. The command works in a regular shell, including as a root. The command does not work in PHP. This is not related to Hoa but to PHP. However, it would be great to detect the issue and prevent the user.

@Nasga: Are you agree with my summary?

SebastienElet commented 10 years ago

I have the same issue with the var_dump. I'm able to reproduce the issue from cli.

$ sh --version
# GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
$ sh
$ echo "cols\nlines" | tput -S
# tput: unknown terminfo capability 'cols\nlines'

This issue seems to be related to my term.

SebastienElet commented 10 years ago

echo -e is working in php/cli.

Hywan commented 10 years ago

Your problem were partly based on #23, which is fixed. I consider this issue as closed :-).