php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72312 cli.prompt with \e colours breaks interactive shell wrapping
Submitted: 2016-06-02 03:29 UTC Modified: 2016-06-02 03:40 UTC
From: christopher dot jf dot hopper at gmail dot com Assigned:
Status: Open Package: CGI/CLI related
PHP Version: 7.0.7 OS: Ubuntu 14.04.4 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: christopher dot jf dot hopper at gmail dot com
New email:
PHP Version: OS:

 

 [2016-06-02 03:29 UTC] christopher dot jf dot hopper at gmail dot com
Description:
------------
When adding colours to cli.prompt with \e these non-printable characters cause incorrect wrapping behaviour by the interactive shell.

Steps to Reproduce
------------------

1. Open a terminal window.
2. Ensure the terminal window is not maximized and reduce its width to around 80 columns.
3. Run the php interactive shell with `php -a`
4. Type a single, long line of code that wraps to the next line.
5. Add colors to the cli.prompt with \e as per http://php.net/manual/en/features.commandline.interactive.php#example-430
6. Try typing another long line of code that should wrap to the next line. 



Configure
---------

This is my PHP 7 build configuration:

./configure \
  --prefix=/usr/local \
  --mandir=/usr/local/man \
  --with-config-file-path=/usr/local/etc \
  --with-config-file-scan-dir=/usr/local/etc/php.d \
  --disable-cgi \
  --enable-bcmath \
  --enable-cli \
  --enable-ftp \
  --enable-mbstring \
  --enable-pcntl \
  --enable-phar \
  --enable-shared \
  --enable-zip \
  --with-bz2 \
  --with-curl \
  --with-iconv \
  --with-mcrypt \
  --with-openssl \
  --with-pear \
  --with-readline \
  --with-zlib


Test script:
---------------
// Execute in Interactive Shell with php -a
ini_set('cli.prompt','\e[032m\v \e[031m\b \e[34m\> \e[0m');
print ini_get('cli.prompt');
echo "This is a long line that should wrap and it does when cli.prompt contains no non-printable characters";
ini_restore('cli.prompt');
ini_get('cli.prompt');
echo "This is a long line that should wrap and it does when cli.prompt contains no non-printable characters";

Expected result:
----------------
Last line typed wraps to newline. Terminal looks like this:

7.0.6 php > echo "This is a long line that should wrap and it does when cli.prompt contains no non-printable characters";
This is a long line that should wrap but it does not when the cli.prompt contains non-printable characters

Actual result:
--------------
last line typed wraps on itself. Terminal looks like this:

t does not when the cli.prompt contains non-printable characters";
This is a long line that should wrap but it does not when the cli.prompt contains non-printable characters

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-02 03:40 UTC] christopher dot jf dot hopper at gmail dot com
Test Script:
------------

Simplified test script.

// Execute in Interactive Shell with php -a
ini_set('cli.prompt','\e[032m\v \e[031m\b \e[34m\> \e[0m');
print ini_get('cli.prompt');
echo "This is a long line that should wrap and it does when cli.prompt contains no non-printable characters";
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC