2022年7月30日(土) 3:10 Robert E. Griffith<bobg@junga.com>:
Is it possible to prevent readline from echoing the text entered through
a macro?
It seems what you want to do is actually not to prevent the echoing
but just to print and clear the current commandline. In this case,
`bind -x' should be used rather than the readline string macros.
function rl_print_line_and_clear() {
printf '\e[34m<up>:\e[m%s\n' "$READLINE_LINE"
READLINE_LINE=
READLINE_POINT=0
READLINE_MARK=0
}
bind -x '"\eOP": rl_print_line_and_clear'
So I tried using the CSI conceal code like ...
$ bind '"\eOP": "\C-aecho \e34m'\''<up>'\'':\e0m\C-m"'
$ echo mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm'<up>':hello
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm<up>:hello
But the default ESC binding is to metafy the next character. Removing or
replacing the ESC binding had no affect so a related question is "Is is
possible to embed CSI codes in a macro?
ESC (\e) and CSI (\e[) are different. The ANSI control sequence should
be started with CSI \e[ but not with ESC \e. In addition, the macro
string is treated as if the user inputs it from the keyboard, so if
you want to embed \e in the commandline, you need to insert control
characters by C-v or C-q, i.e., \e needs to be input by \C-v\e in the
macro string:
bind '"\eOP": "\C-aecho \C-v\e[34m'\''<up>'\'':\C-v\e[0m\C-m"'