Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7655f4c

Browse files
committed
Add a pager_min_lines setting to psql
If set, the pager will not be used unless this many lines are to bedisplayed, even if that is more than the screen depth. Default is zero,meaning it's disabled.There is probably more work to be done in giving the user control overwhen the pager is used, particularly when wide output forces use of thepager regardless of how many lines there are, but this is a start.
1 parentcfe1276 commit7655f4c

File tree

9 files changed

+55
-16
lines changed

9 files changed

+55
-16
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,18 @@ lo_import 152801
22352235
</listitem>
22362236
</varlistentry>
22372237

2238+
<varlistentry>
2239+
<term><literal>pager_min_lines</literal></term>
2240+
<listitem>
2241+
<para>
2242+
If <literal>pager_min_lines</> is set to a number greater than the
2243+
page height, the pager program will not be called unless there are
2244+
at least this many lines of output to show. The default setting
2245+
is 0.
2246+
</para>
2247+
</listitem>
2248+
</varlistentry>
2249+
22382250
<varlistentry>
22392251
<term><literal>recordsep</literal></term>
22402252
<listitem>

‎src/bin/psql/command.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,8 @@ exec_command(const char *cmd,
10711071
staticconstchar*constmy_list[]= {
10721072
"border","columns","expanded","fieldsep","fieldsep_zero",
10731073
"footer","format","linestyle","null",
1074-
"numericlocale","pager","recordsep","recordsep_zero",
1074+
"numericlocale","pager","pager_min_lines",
1075+
"recordsep","recordsep_zero",
10751076
"tableattr","title","tuples_only",
10761077
"unicode_border_linestyle",
10771078
"unicode_column_linestyle",
@@ -1265,7 +1266,7 @@ exec_command(const char *cmd,
12651266
lines++;
12661267
}
12671268

1268-
output=PageOutput(lineno,pset.popt.topt.pager);
1269+
output=PageOutput(lineno,&(pset.popt.topt));
12691270
is_pager= true;
12701271
}
12711272
else
@@ -2519,6 +2520,13 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
25192520
popt->topt.pager=1;
25202521
}
25212522

2523+
/* set minimum lines for pager use */
2524+
elseif (strcmp(param,"pager_min_lines")==0)
2525+
{
2526+
if (value)
2527+
popt->topt.pager_min_lines=atoi(value);
2528+
}
2529+
25222530
/* disable "(x rows)" footer */
25232531
elseif (strcmp(param,"footer")==0)
25242532
{
@@ -2640,6 +2648,13 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
26402648
printf(_("Pager usage is off.\n"));
26412649
}
26422650

2651+
/* show minimum lines for pager use */
2652+
elseif (strcmp(param,"pager_min_lines")==0)
2653+
{
2654+
printf(_("Pager won't be used for less than %d lines\n"),
2655+
popt->topt.pager_min_lines);
2656+
}
2657+
26432658
/* show record separator for unaligned text */
26442659
elseif (strcmp(param,"recordsep")==0)
26452660
{
@@ -2792,6 +2807,8 @@ pset_value_string(const char *param, struct printQueryOpt *popt)
27922807
returnpstrdup(pset_bool_string(popt->topt.numericLocale));
27932808
elseif (strcmp(param,"pager")==0)
27942809
returnpsprintf("%d",popt->topt.pager);
2810+
elseif (strcmp(param,"pager_min_lines")==0)
2811+
returnpsprintf("%d",popt->topt.pager_min_lines);
27952812
elseif (strcmp(param,"recordsep")==0)
27962813
returnpset_quoted_string(popt->topt.recordSep.separator
27972814
?popt->topt.recordSep.separator

‎src/bin/psql/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
13371337
* If query requires multiple result sets, hack to ensure that
13381338
* only one pager instance is used for the whole mess
13391339
*/
1340-
pset.queryFout=PageOutput(100000,my_popt.topt.pager);
1340+
pset.queryFout=PageOutput(100000,&(my_popt.topt));
13411341
did_pager= true;
13421342
}
13431343

‎src/bin/psql/help.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ usage(unsigned short int pager)
6565
}
6666
}
6767

68-
output=PageOutput(59,pager);
68+
output=PageOutput(59,pager ?&(pset.popt.topt) :NULL);
6969

7070
fprintf(output,_("psql is the PostgreSQL interactive terminal.\n\n"));
7171
fprintf(output,_("Usage:\n"));
@@ -158,7 +158,7 @@ slashUsage(unsigned short int pager)
158158

159159
currdb=PQdb(pset.db);
160160

161-
output=PageOutput(103,pager);
161+
output=PageOutput(103,pager ?&(pset.popt.topt) :NULL);
162162

163163
/* if you add/remove a line here, change the row count above */
164164

@@ -305,7 +305,7 @@ helpVariables(unsigned short int pager)
305305
{
306306
FILE*output;
307307

308-
output=PageOutput(85,pager);
308+
output=PageOutput(85,pager ?&(pset.popt.topt) :NULL);
309309

310310
fprintf(output,_("List of specially treated variables.\n"));
311311

@@ -435,7 +435,7 @@ helpSQL(const char *topic, unsigned short int pager)
435435
ncolumns=Max(ncolumns,1);
436436
nrows= (QL_HELP_COUNT+ (ncolumns-1)) /ncolumns;
437437

438-
output=PageOutput(nrows+1,pager);
438+
output=PageOutput(nrows+1,pager ?&(pset.popt.topt) :NULL);
439439

440440
fputs(_("Available help:\n"),output);
441441

@@ -488,7 +488,7 @@ helpSQL(const char *topic, unsigned short int pager)
488488
if (wordlen >=len)/* Don't try again if the same word */
489489
{
490490
if (!output)
491-
output=PageOutput(nl_count,pager);
491+
output=PageOutput(nl_count,pager ?&(pset.popt.topt) :NULL);
492492
break;
493493
}
494494
len=wordlen;
@@ -509,7 +509,7 @@ helpSQL(const char *topic, unsigned short int pager)
509509
}
510510

511511
if (!output)
512-
output=PageOutput(nl_count,pager);
512+
output=PageOutput(nl_count,pager ?&(pset.popt.topt) :NULL);
513513

514514
for (i=0;QL_HELP[i].cmd;i++)
515515
{

‎src/bin/psql/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ printHistory(const char *fname, unsigned short int pager)
474474
if (fname==NULL)
475475
{
476476
/* use pager, if enabled, when printing to console */
477-
output=PageOutput(INT_MAX,pager);
477+
output=PageOutput(INT_MAX,pager ?&(pset.popt.topt) :NULL);
478478
is_pager= true;
479479
}
480480
else

‎src/bin/psql/print.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
811811
if (!is_pager&&fout==stdout&&output_columns>0&&
812812
(output_columns<total_header_width||output_columns<width_total))
813813
{
814-
fout=PageOutput(INT_MAX,cont->opt->pager);/* force pager */
814+
fout=PageOutput(INT_MAX,cont->opt);/* force pager */
815815
is_pager= true;
816816
}
817817

@@ -2497,15 +2497,19 @@ print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
24972497
* PageOutput
24982498
*
24992499
* Tests if pager is needed and returns appropriate FILE pointer.
2500+
*
2501+
* If the topt argument is NULL no pager is used.
25002502
*/
25012503
FILE*
2502-
PageOutput(intlines,unsigned shortintpager)
2504+
PageOutput(intlines,constprintTableOpt*topt)
25032505
{
25042506
/* check whether we need / can / are supposed to use pager */
2505-
if (pager&&isatty(fileno(stdin))&&isatty(fileno(stdout)))
2507+
if (topt&&topt->pager&&isatty(fileno(stdin))&&isatty(fileno(stdout)))
25062508
{
25072509
constchar*pagerprog;
25082510
FILE*pagerpipe;
2511+
unsigned shortintpager=topt->pager;
2512+
intmin_lines=topt->pager_min_lines;
25092513

25102514
#ifdefTIOCGWINSZ
25112515
intresult;
@@ -2514,7 +2518,9 @@ PageOutput(int lines, unsigned short int pager)
25142518
result=ioctl(fileno(stdout),TIOCGWINSZ,&screen_size);
25152519

25162520
/* >= accounts for a one-line prompt */
2517-
if (result==-1||lines >=screen_size.ws_row||pager>1)
2521+
if (result==-1
2522+
|| (lines >=screen_size.ws_row&&lines >=min_lines)
2523+
||pager>1)
25182524
{
25192525
#endif
25202526
pagerprog=getenv("PAGER");
@@ -2814,7 +2820,7 @@ IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expande
28142820
lines++;
28152821
}
28162822

2817-
*fout=PageOutput(lines+extra_lines,cont->opt->pager);
2823+
*fout=PageOutput(lines+extra_lines,cont->opt);
28182824
*is_pager= (*fout!=stdout);
28192825
}
28202826
else

‎src/bin/psql/print.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ typedef struct printTableOpt
8989
* 1=dividing lines, 2=full */
9090
unsigned shortintpager;/* use pager for output (if to stdout and
9191
* stdout is a tty) 0=off 1=on 2=always */
92+
intpager_min_lines;/* don't use pager unless there are at least
93+
* this many lines */
9294
booltuples_only;/* don't output headers, row counts, etc. */
9395
boolstart_table;/* print start decoration, eg <table> */
9496
boolstop_table;/* print stop decoration, eg </table> */
@@ -164,7 +166,7 @@ extern const printTextFormat pg_asciiformat_old;
164166
externconstprintTextFormatpg_utf8format;
165167

166168

167-
externFILE*PageOutput(intlines,unsigned shortintpager);
169+
externFILE*PageOutput(intlines,constprintTableOpt*topt);
168170
externvoidClosePager(FILE*pagerpipe);
169171

170172
externvoidhtml_escaped_print(constchar*in,FILE*fout);

‎src/bin/psql/startup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ main(int argc, char *argv[])
129129
pset.popt.topt.format=PRINT_ALIGNED;
130130
pset.popt.topt.border=1;
131131
pset.popt.topt.pager=1;
132+
pset.popt.topt.pager_min_lines=0;
132133
pset.popt.topt.start_table= true;
133134
pset.popt.topt.stop_table= true;
134135
pset.popt.topt.default_footer= true;

‎src/test/regress/expected/psql.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ linestyle ascii
6565
null ''
6666
numericlocale off
6767
pager 1
68+
pager_min_lines 0
6869
recordsep '\n'
6970
recordsep_zero off
7071
tableattr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp