Skip to content

Fix colors in phpdbg prompt with libedit integration #15722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sapi/phpdbg/phpdbg_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,14 @@ PHPDBG_API const char *phpdbg_get_prompt(void) /* {{{ */
}

/* create cached prompt */
#ifndef HAVE_LIBEDIT
/* TODO: libedit doesn't seems to support coloured prompt */
#if !defined(HAVE_LIBEDIT) || (defined(HAVE_LIBEDIT) && defined(RL_PROMPT_START_IGNORE) && defined(RL_PROMPT_END_IGNORE))
# if defined(HAVE_LIBEDIT) && defined(RL_PROMPT_START_IGNORE) && defined(RL_PROMPT_END_IGNORE)
# define PHPDBG_PROMPT_FORMAT "\1\033[%sm\2%s\1\033[0m\2 "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to actually use the macros, i.e.

Suggested change
# define PHPDBG_PROMPT_FORMAT "\1\033[%sm\2%s\1\033[0m\2 "
# define PHPDBG_PROMPT_FORMAT RL_PROMPT_START_IGNORE "\033[%sm\2%s\1\033[0m" RL_PROMPT_END_IGNORE " "

Copy link
Member Author

@petk petk Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check. Last time I've tried this there were some errors and these strings should be then concatenated differently. The libraries define them as this (with single quotes):

/usr/include/readline/readline.h:#define RL_PROMPT_START_IGNORE	'\001'
/usr/include/editline/readline.h:#define RL_PROMPT_START_IGNORE	'\1'
/usr/include/readline/readline.h:#define RL_PROMPT_END_IGNORE	'\002'
/usr/include/editline/readline.h:#define RL_PROMPT_END_IGNORE	'\2'

# else
# define PHPDBG_PROMPT_FORMAT "\033[%sm%s\033[0m "
# endif
if ((PHPDBG_G(flags) & PHPDBG_IS_COLOURED)) {
ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1], "\033[%sm%s\033[0m ",
ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1], PHPDBG_PROMPT_FORMAT,
PHPDBG_G(colors)[PHPDBG_COLOR_PROMPT]->code,
PHPDBG_G(prompt)[0]));
} else
Expand Down
Loading