From 033907b9a58f137443ab257a9f1f597df34dafc2 Mon Sep 17 00:00:00 2001 From: Tim Bazuin Date: Tue, 29 Aug 2017 10:43:04 +0200 Subject: [PATCH] Add support for rl_completion_suppress_append and rl_completion_append_character These options are only available with libreadline. --- NEWS | 4 ++++ UPGRADING | 5 +++++ ext/readline/readline.c | 19 +++++++++++++++++++ ext/readline/tests/readline_info_001.phpt | 14 +++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 680ef4ce82d..7ec00628270 100644 --- a/NEWS +++ b/NEWS @@ -146,6 +146,10 @@ PHP NEWS . Fixed bug #65414 (deal with leading slash when adding files correctly). (bishopb) +- readline: + . Added completion_append_character and completion_suppress_append options + to readline_info() if linked against libreadline. (krageon) + - Session: . Fixed bug #74941 (session fails to start after having headers sent). (morozov) diff --git a/UPGRADING b/UPGRADING index 6729b745f1e..0eec409b9cd 100644 --- a/UPGRADING +++ b/UPGRADING @@ -64,6 +64,11 @@ Core: BCMath: . bcscale() can now also be used as getter to retrieve the current scale in use. +readline: + . Support for the completion_append_character and completion_suppress_append + options has been added to readline_info(). These options are only available + if PHP is linked against libreadline (rather than libedit). + ======================================== 3. Changes in SAPI modules ======================================== diff --git a/ext/readline/readline.c b/ext/readline/readline.c index bd443ebcd6a..7026b020f68 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -262,6 +262,11 @@ PHP_FUNCTION(readline_info) add_assoc_long(return_value,"pending_input",rl_pending_input); add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt)); add_assoc_string(return_value,"terminal_name",(char *)SAFE_STRING(rl_terminal_name)); + add_assoc_str(return_value, "completion_append_character", + rl_completion_append_character == 0 + ? ZSTR_EMPTY_ALLOC() + : ZSTR_CHAR(rl_completion_append_character)); + add_assoc_bool(return_value,"completion_suppress_append",rl_completion_suppress_append); #endif #if HAVE_ERASE_EMPTY_LINE add_assoc_long(return_value,"erase_empty_line",rl_erase_empty_line); @@ -307,6 +312,20 @@ PHP_FUNCTION(readline_info) RETVAL_STRING(SAFE_STRING(rl_prompt)); } else if (!strcasecmp(what, "terminal_name")) { RETVAL_STRING((char *)SAFE_STRING(rl_terminal_name)); + } else if (!strcasecmp(what, "completion_suppress_append")) { + oldval = rl_completion_suppress_append; + if (value) { + rl_completion_suppress_append = zend_is_true(value); + } + RETVAL_BOOL(oldval); + } else if (!strcasecmp(what, "completion_append_character")) { + oldval = rl_completion_append_character; + if (value) { + convert_to_string_ex(value) + rl_completion_append_character = (int)Z_STRVAL_P(value)[0]; + } + RETVAL_INTERNED_STR( + oldval == 0 ? ZSTR_EMPTY_ALLOC() : ZSTR_CHAR(oldval)); #endif #if HAVE_ERASE_EMPTY_LINE } else if (!strcasecmp(what, "erase_empty_line")) { diff --git a/ext/readline/tests/readline_info_001.phpt b/ext/readline/tests/readline_info_001.phpt index 81b7806b439..68599c1d671 100644 --- a/ext/readline/tests/readline_info_001.phpt +++ b/ext/readline/tests/readline_info_001.phpt @@ -16,10 +16,14 @@ var_dump(readline_info('readline_name', 1)); var_dump(readline_info('readline_name')); var_dump(readline_info('attempted_completion_over',1)); var_dump(readline_info('attempted_completion_over')); +var_dump(readline_info('completion_append_character', "\0")); +var_dump(readline_info('completion_append_character')); +var_dump(readline_info('completion_suppress_append', true)); +var_dump(readline_info('completion_suppress_append')); ?> --EXPECTF-- -array(11) { +array(13) { ["line_buffer"]=> string(0) "" ["point"]=> @@ -36,6 +40,10 @@ array(11) { string(0) "" ["terminal_name"]=> string(0) "" + ["completion_append_character"]=> + string(1) " " + ["completion_suppress_append"]=> + bool(false) ["library_version"]=> string(%d) "%s" ["readline_name"]=> @@ -51,3 +59,7 @@ string(5) "other" string(1) "1" int(0) int(1) +string(1) " " +string(0) "" +bool(false) +bool(true) \ No newline at end of file