change color of readline_callback_handler_install

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jun 03, 2021 4:44 am

Thu Jun 03, 2021 5:39 am

Hello guys! I try to set a two different colors - blue color for "command>" and magenta for inputed text, but it not work, because readline_callback_handler_install not allow a color codes.
Somebody know a simple solution?
php-forum Fan User
php-forum Fan User
Posts: 137
Joined: Mon Jun 08, 2020 2:00 am

Sun Jun 06, 2021 4:49 am

There's no way to do it directly. You could spoof it by echoing your prompt manually then having a blank "prompt" in your readline handler. The example below shows how it works with readline().

Code: Select all

echo "\e[0m\e[34m Wacky coloured prompt: \e[0m";
$foo = readline('');
Post Reply