Merge pull request #15910 from glacambre/silent_stdioopen

feat(--headless): do not print anything when stdioopen() has been used
This commit is contained in:
bfredl
2022-01-24 22:33:55 +01:00
committed by GitHub
5 changed files with 51 additions and 1 deletions

View File

@@ -96,6 +96,8 @@ struct Channel {
EXTERN PMap(uint64_t) channels INIT(= MAP_INIT);
EXTERN Callback on_print INIT(= CALLBACK_INIT);
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "channel.h.generated.h"
#endif

View File

@@ -10215,6 +10215,10 @@ static void f_stdioopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (!tv_dict_get_callback(opts, S_LEN("on_stdin"), &on_stdin.cb)) {
return;
}
if (!tv_dict_get_callback(opts, S_LEN("on_print"), &on_print)) {
return;
}
on_stdin.buffered = tv_dict_get_number(opts, "stdin_buffered");
if (on_stdin.buffered && on_stdin.cb.type == kCallbackNone) {
on_stdin.self = opts;

View File

@@ -81,7 +81,8 @@ typedef struct {
} data;
CallbackType type;
} Callback;
#define CALLBACK_NONE ((Callback){ .type = kCallbackNone })
#define CALLBACK_INIT { .type = kCallbackNone }
#define CALLBACK_NONE ((Callback)CALLBACK_INIT)
/// Structure holding dictionary watcher
typedef struct dict_watcher {

View File

@@ -2647,6 +2647,17 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen)
char buf[7];
char *p;
if (on_print.type != kCallbackNone) {
typval_T argv[1];
argv[0].v_type = VAR_STRING;
argv[0].v_lock = VAR_UNLOCKED;
argv[0].vval.v_string = (char_u *)str;
typval_T rettv = TV_INITIAL_VALUE;
callback_call(&on_print, 1, argv, &rettv);
tv_clear(&rettv);
return;
}
while ((maxlen < 0 || s - str < maxlen) && *s != NUL) {
int len = utf_ptr2len((const char_u *)s);
if (!(silent_mode && p_verbose == 0)) {