Skip to content

Commit 626d1b3

Browse files
committed
Fix phpdbg prompt when building with libedit integration
1 parent 5ef0daf commit 626d1b3

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

bin/make-patches.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ patch-cmake-8.3-asm
1212
patch-cmake-8.3-aspell
1313
patch-cmake-8.3-dmalloc
1414
patch-cmake-8.3-php-config
15+
patch-cmake-8.3-phpdbg-prompt
1516
patch-cmake-8.4
1617
patch-cmake-8.4-asm
1718
patch-cmake-8.4-dmalloc
1819
patch-cmake-8.4-docs
1920
patch-cmake-8.4-php-config
21+
patch-cmake-8.4-phpdbg-prompt
2022
patch-cmake-8.4-timelib
2123
"
2224

patches/8.3/phpdbg-prompt.patch

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Subject: Fix phpdbg prompt with editline/readline integration
2+
3+
When building phpdbg SAPI with libedit/readline integration, also start
4+
and end ignore characters need to be added in the prompt pattern. This
5+
should work now for libedit, readline, and phpdbg without
6+
readline/libedit.
7+
8+
The RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE macros are checked
9+
there to ensure libedit has these available. Otherwise, this could be
10+
further improved by concatenating strings and literal strings into
11+
single argument or similar using these two symbols directly.
12+
13+
Autotools:
14+
15+
./configure --with-libedit --enable-phpdbg-readline
16+
make
17+
./sapi/phpdbg/phpdb
18+
19+
CMake:
20+
21+
cmake -DSAPI_PHPDBG_READLINE=ON .
22+
cmake --build .
23+
./sapi/phpdbg/phpdbg
24+
25+
In the phpdbg, the "prompt" should be colored (or bold) in some
26+
terminals.
27+
---
28+
sapi/phpdbg/phpdbg_utils.c | 10 +++++++---
29+
1 file changed, 7 insertions(+), 3 deletions(-)
30+
31+
diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c
32+
index 964d82ef6c..ae214c61fe 100644
33+
--- a/sapi/phpdbg/phpdbg_utils.c
34+
+++ b/sapi/phpdbg/phpdbg_utils.c
35+
@@ -318,10 +318,14 @@ PHPDBG_API const char *phpdbg_get_prompt(void) /* {{{ */
36+
}
37+
38+
/* create cached prompt */
39+
-#ifndef HAVE_LIBEDIT
40+
- /* TODO: libedit doesn't seems to support coloured prompt */
41+
+#if !defined(HAVE_LIBEDIT) || (defined(HAVE_LIBEDIT) && defined(RL_PROMPT_START_IGNORE) && defined(RL_PROMPT_END_IGNORE))
42+
if ((PHPDBG_G(flags) & PHPDBG_IS_COLOURED)) {
43+
- ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1], "\033[%sm%s\033[0m ",
44+
+ ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1],
45+
+# if defined(HAVE_LIBEDIT) && defined(RL_PROMPT_START_IGNORE) && defined(RL_PROMPT_END_IGNORE)
46+
+ "\1\033[%sm\2%s\1\033[0m\2 ",
47+
+# else
48+
+ "\033[%sm%s\033[0m ",
49+
+# endif
50+
PHPDBG_G(colors)[PHPDBG_COLOR_PROMPT]->code,
51+
PHPDBG_G(prompt)[0]));
52+
} else

patches/8.4/php-config.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ index e45b22b766..74f0e25b01 100644
5757
])
5858

5959
diff --git a/configure.ac b/configure.ac
60-
index c728970129..dd20f22534 100644
60+
index 198f04afd9..e4fd053bca 100644
6161
--- a/configure.ac
6262
+++ b/configure.ac
63-
@@ -1366,6 +1366,9 @@ exec_prefix=$old_exec_prefix
63+
@@ -1363,6 +1363,9 @@ exec_prefix=$old_exec_prefix
6464
libdir=$old_libdir
6565
datadir=$old_datadir
6666

@@ -70,7 +70,7 @@ index c728970129..dd20f22534 100644
7070
AC_SUBST([INCLUDE_PATH])
7171
AC_SUBST([EXPANDED_PEAR_INSTALLDIR])
7272
AC_SUBST([EXPANDED_EXTENSION_DIR])
73-
@@ -1384,6 +1387,9 @@ AC_SUBST([SAPI_LIBNAME_STATIC])
73+
@@ -1381,6 +1384,9 @@ AC_SUBST([SAPI_LIBNAME_STATIC])
7474
AC_SUBST([PHP_VERSION])
7575
AC_SUBST([PHP_VERSION_ID])
7676
AC_SUBST([PHP_LDFLAGS])

patches/8.4/phpdbg-prompt.patch

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Subject: Fix phpdbg prompt with editline/readline integration
2+
3+
When building phpdbg SAPI with libedit/readline integration, also start
4+
and end ignore characters need to be added in the prompt pattern. This
5+
should work now for libedit, readline, and phpdbg without
6+
readline/libedit.
7+
8+
The RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE macros are checked
9+
there to ensure libedit has these available. Otherwise, this could be
10+
further improved by concatenating strings and literal strings into
11+
single argument or similar using these two symbols directly.
12+
13+
Autotools:
14+
15+
./configure --with-libedit --enable-phpdbg-readline
16+
make
17+
./sapi/phpdbg/phpdb
18+
19+
CMake:
20+
21+
cmake -DSAPI_PHPDBG_READLINE=ON .
22+
cmake --build .
23+
./sapi/phpdbg/phpdbg
24+
25+
In the phpdbg, the "prompt" should be colored (or bold) in some
26+
terminals.
27+
---
28+
sapi/phpdbg/phpdbg_utils.c | 10 +++++++---
29+
1 file changed, 7 insertions(+), 3 deletions(-)
30+
31+
diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c
32+
index 329ee9a883..e72265ae8e 100644
33+
--- a/sapi/phpdbg/phpdbg_utils.c
34+
+++ b/sapi/phpdbg/phpdbg_utils.c
35+
@@ -318,10 +318,14 @@ PHPDBG_API const char *phpdbg_get_prompt(void) /* {{{ */
36+
}
37+
38+
/* create cached prompt */
39+
-#ifndef HAVE_LIBEDIT
40+
- /* TODO: libedit doesn't seems to support coloured prompt */
41+
+#if !defined(HAVE_LIBEDIT) || (defined(HAVE_LIBEDIT) && defined(RL_PROMPT_START_IGNORE) && defined(RL_PROMPT_END_IGNORE))
42+
if ((PHPDBG_G(flags) & PHPDBG_IS_COLOURED)) {
43+
- ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1], "\033[%sm%s\033[0m ",
44+
+ ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1],
45+
+# if defined(HAVE_LIBEDIT) && defined(RL_PROMPT_START_IGNORE) && defined(RL_PROMPT_END_IGNORE)
46+
+ "\1\033[%sm\2%s\1\033[0m\2 ",
47+
+# else
48+
+ "\033[%sm%s\033[0m ",
49+
+# endif
50+
PHPDBG_G(colors)[PHPDBG_COLOR_PROMPT]->code,
51+
PHPDBG_G(prompt)[0]));
52+
} else

0 commit comments

Comments
 (0)