On Thu, Jan 28, 2016 at 1:54 PM, David G. Johnston
<[email protected]> wrote:
> On Wed, Jan 27, 2016 at 9:13 PM, Michael Paquier <[email protected]>
> wrote:
>>
>> On Thu, Jan 28, 2016 at 9:34 AM, David G. Johnston
>> <[email protected]> wrote:
>> > So how about:
>> >
>> > + snprintf(title, strlen(myopt.title) + 50,
>> > + _("Watch every %lds\t%s\t%s"),
>> > + sleep, head_title, asctime(localtime(&timer)));
>>
>> I would just keep the timestamp and the title separated so what do you
>> think about that instead?
>> Watch every Xs $timestamp
>> $head_title
>
>
> That works. I like having the title immediately above the table.
>
> The other option that came to mind would be to place the time information
> after the table display while leaving the title before it. On an output
> that requires more vertical space than is available in the terminal one
> would no longer have to scroll up to confirm last execution time. If doing
> this I'd probably get rid of any logic that attempts to center the time
> information on the table and simply leave it left-aligned.
OK, attached is an updated patch. How does that look?
--
Michael
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;
}
--
Sent via pgsql-general mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general