diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 9750a5b..3241d27 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3020,7 +3020,8 @@ static bool do_watch(PQExpBuffer query_buf, long sleep) { printQueryOpt myopt = pset.popt; - char title[50]; + char *title; + bool *head_title = NULL; if (!query_buf || query_buf->len <= 0) { @@ -3034,6 +3035,18 @@ do_watch(PQExpBuffer query_buf, long sleep) */ myopt.topt.pager = 0; + /* + * Take into account any title present in the user setup as a part of + * what is printed for each iteration by using it as a header. + */ + if (myopt.title) + { + title = pg_malloc(strlen(myopt.title) + 50); + head_title = pg_strdup(myopt.title); + } + else + title = pg_malloc(50); + for (;;) { int res; @@ -3045,8 +3058,13 @@ do_watch(PQExpBuffer query_buf, long sleep) * of completion of the command? */ timer = time(NULL); - snprintf(title, sizeof(title), _("Watch every %lds\t%s"), - sleep, asctime(localtime(&timer))); + if (head_title) + snprintf(title, strlen(myopt.title) + 50, + _("Watch every %lds\t%s\n%s"), + sleep, asctime(localtime(&timer)), head_title); + else + snprintf(title, 50, _("Watch every %lds\t%s"), + sleep, asctime(localtime(&timer))); myopt.title = title; /* Run the query and print out the results */ @@ -3059,7 +3077,11 @@ do_watch(PQExpBuffer query_buf, long sleep) if (res == 0) break; if (res == -1) + { + pg_free(title); + pg_free(head_title); return false; + } /* * Set up cancellation of 'watch' via SIGINT. We redo this each time @@ -3084,6 +3106,8 @@ do_watch(PQExpBuffer query_buf, long sleep) sigint_interrupt_enabled = false; } + pg_free(title); + pg_free(head_title); return true; }