{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/15552","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/15552/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/15552/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/15552/events","html_url":"https://github.com/yiisoft/yii2/issues/15552","id":291201959,"number":15552,"title":"\\yii\\console\\widgets\\Table::widget problem with screenwidth","user":{"login":"vinpel","id":1699839,"avatar_url":"https://avatars0.githubusercontent.com/u/1699839?v=4","gravatar_id":"","url":"https://api.github.com/users/vinpel","html_url":"https://github.com/vinpel","followers_url":"https://api.github.com/users/vinpel/followers","following_url":"https://api.github.com/users/vinpel/following{/other_user}","gists_url":"https://api.github.com/users/vinpel/gists{/gist_id}","starred_url":"https://api.github.com/users/vinpel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinpel/subscriptions","organizations_url":"https://api.github.com/users/vinpel/orgs","repos_url":"https://api.github.com/users/vinpel/repos","events_url":"https://api.github.com/users/vinpel/events{/privacy}","received_events_url":"https://api.github.com/users/vinpel/received_events","type":"User","site_admin":false},"labels":[{"id":33330247,"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:ready%20for%20adoption","name":"status:ready for adoption","color":"02e10c","default":false},{"id":33208443,"url":"https://api.github.com/repos/yiisoft/yii2/labels/type:bug","name":"type:bug","color":"e102d8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/yiisoft/yii2/milestones/25","html_url":"https://github.com/yiisoft/yii2/milestone/25","labels_url":"https://api.github.com/repos/yiisoft/yii2/milestones/25/labels","id":2562828,"number":25,"title":"2.0.16","description":"","creator":{"login":"cebe","id":189796,"avatar_url":"https://avatars0.githubusercontent.com/u/189796?v=4","gravatar_id":"","url":"https://api.github.com/users/cebe","html_url":"https://github.com/cebe","followers_url":"https://api.github.com/users/cebe/followers","following_url":"https://api.github.com/users/cebe/following{/other_user}","gists_url":"https://api.github.com/users/cebe/gists{/gist_id}","starred_url":"https://api.github.com/users/cebe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cebe/subscriptions","organizations_url":"https://api.github.com/users/cebe/orgs","repos_url":"https://api.github.com/users/cebe/repos","events_url":"https://api.github.com/users/cebe/events{/privacy}","received_events_url":"https://api.github.com/users/cebe/received_events","type":"User","site_admin":false},"open_issues":163,"closed_issues":88,"state":"open","created_at":"2017-06-05T18:03:36Z","updated_at":"2018-05-14T10:44:34Z","due_on":"2018-04-20T07:00:00Z","closed_at":null},"comments":1,"created_at":"2018-01-24T13:07:16Z","updated_at":"2018-05-14T18:31:24Z","closed_at":null,"author_association":"NONE","body":"### What steps will reproduce the problem?\r\nuse console widget table when screen size __can't__ be determined\r\n```php\r\nprint '<pre>';\r\nprint \\yii\\console\\widgets\\Table::widget([\r\n          'headers' => ['a','b'],\r\n          'rows'    => [['a','b']]\r\n        ]);\r\n```\r\n### What is the expected result?\r\n\r\n![image](https://user-images.githubusercontent.com/1699839/35333582-86c2d78a-010f-11e8-925d-c80b99955529.png)\r\n\r\n### What do you get instead?\r\n![image](https://user-images.githubusercontent.com/1699839/35333153-fa34a088-010d-11e8-93b2-5737823ed1d9.png)\r\n\r\n\r\n### Additional info\r\nyii2\\console\\widgets\\Table.php::getScreenWidth() doesn't assign <b>$this->_screenWidth</b> when __Console::getScreenSize()__ return false.\r\nfor you'r information on my system : \r\n```bash\r\nstty -a 2>&1\r\n```\r\nproduce :\r\n```bash\r\nspeed 38400 baud; rows 55; columns 207; line = 0;\r\nintr = ^C; quit = ^\\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;\r\n-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts\r\n-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8\r\nopost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0\r\nisig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke\r\n```\r\n\r\nso when __yii2\\console\\widgets\\Table.php: calculateRowsSize()__  do :\r\n```php\r\n      $screenWidth = $this->getScreenWidth() - 3;\r\n```\r\nit give a negative value for __$screenWidth__ and produce the php error.\r\n\r\n\r\n### Proposed fix\r\n\r\n#### Set a default value for screenWidth:\r\n```php\r\n    /**\r\n     * Getting screen width.\r\n     *\r\n     * @return int screen width\r\n     */\r\n    protected function getScreenWidth()\r\n    {\r\n        if (!$this->_screenWidth) {\r\n            $size = Console::getScreenSize();\r\n            if (isset($size[0])) {\r\n                $this->_screenWidth = $size[0];\r\n            }else{\r\n              $this->_screenWidth=1000;\r\n            }\r\n        }\r\n\r\n        return $this->_screenWidth;\r\n    }\r\n```\r\nWill produce :\r\n![image](https://user-images.githubusercontent.com/1699839/35333514-4c00c6c0-010f-11e8-9776-c41da1b1b26e.png)\r\n\r\n#### Only Fix the php error\r\n```php\r\n    /**\r\n     * Calculate the size of rows to draw anchor of columns in console.\r\n     *\r\n     * @see \\yii\\console\\widgets\\Table::render()\r\n     */\r\n    protected function calculateRowsSize()\r\n    {\r\n        $this->_columnWidths = $columns = [];\r\n        $totalWidth = 0;\r\n        $screenWidth = $this->getScreenWidth() - 3;\r\n        if ($screenWidth < 0){\r\n          $screenWidth=0;\r\n        }\r\n\r\n```\r\nwill produce : \r\n![image](https://user-images.githubusercontent.com/1699839/35333542-6207dc92-010f-11e8-9932-c81a5874d25c.png)\r\n\r\nugly but no error\r\n\r\n| Q                | A\r\n| ---------------- | ---\r\n| Yii version      | 2.0.13\r\n| PHP version      | 7.1\r\n| Operating system | Alpine Linux\r\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/388917534","html_url":"https://github.com/yiisoft/yii2/issues/15552#issuecomment-388917534","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/15552","id":388917534,"user":{"login":"nadar","id":3417221,"avatar_url":"https://avatars0.githubusercontent.com/u/3417221?v=4","gravatar_id":"","url":"https://api.github.com/users/nadar","html_url":"https://github.com/nadar","followers_url":"https://api.github.com/users/nadar/followers","following_url":"https://api.github.com/users/nadar/following{/other_user}","gists_url":"https://api.github.com/users/nadar/gists{/gist_id}","starred_url":"https://api.github.com/users/nadar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nadar/subscriptions","organizations_url":"https://api.github.com/users/nadar/orgs","repos_url":"https://api.github.com/users/nadar/repos","events_url":"https://api.github.com/users/nadar/events{/privacy}","received_events_url":"https://api.github.com/users/nadar/received_events","type":"User","site_admin":false},"created_at":"2018-05-14T18:31:24Z","updated_at":"2018-05-14T18:31:24Z","author_association":"CONTRIBUTOR","body":"Maybe also something which could be related:\r\n\r\n```php\r\nPHP Warning 'yii\\base\\ErrorException' with message 'str_repeat(): Second argument has to be greater than or equal to 0'\r\n\r\nin /app/vendor/yiisoft/yii2/console/widgets/Table.php:289\r\n\r\nStack trace:\r\n#0 [internal function]: yii\\base\\ErrorHandler->handleError(2, 'str_repeat(): S...', '/app/vendor/yii...', 289, Array)\r\n#1 /app/vendor/yiisoft/yii2/console/widgets/Table.php(289): str_repeat('\\xE2\\x95\\x90', -2)\r\n#2 /app/vendor/yiisoft/yii2/console/widgets/Table.php(181): yii\\console\\widgets\\Table->renderSeparator('\\xE2\\x95\\x94', '\\xE2\\x95\\xA4', '\\xE2\\x95\\x90', '\\xE2\\x95\\x97')\r\n#3 /app/vendor/luyadev/luya-core/console/commands/ImportController.php(218): yii\\console\\widgets\\Table->run()\r\n```"}}
{"actor":{"display_login":"nadar"}}