@@ -122,9 +122,11 @@ const printTextFormat pg_utf8format =
122
122
123
123
/* Local functions */
124
124
static int strlen_max_width (unsigned char * str , int * target_width , int encoding );
125
- static void IsPagerNeeded (const printTableContent * cont , const int extra_lines ,
125
+ static void IsPagerNeeded (const printTableContent * cont , const int extra_lines , bool expanded ,
126
126
FILE * * fout , bool * is_pager );
127
127
128
+ static void print_aligned_vertical (const printTableContent * cont , FILE * fout );
129
+
128
130
129
131
static void *
130
132
pg_local_malloc (size_t size )
@@ -713,6 +715,17 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
713
715
}
714
716
}
715
717
718
+ /*
719
+ * If in expanded auto mode, we have now calculated the expected width, so
720
+ * we can now escape to vertical mode if necessary.
721
+ */
722
+ if (cont -> opt -> expanded == 2 && output_columns > 0 &&
723
+ (output_columns < total_header_width || output_columns < width_total ))
724
+ {
725
+ print_aligned_vertical (cont , fout );
726
+ return ;
727
+ }
728
+
716
729
/* If we wrapped beyond the display width, use the pager */
717
730
if (!is_pager && fout == stdout && output_columns > 0 &&
718
731
(output_columns < total_header_width || output_columns < width_total ))
@@ -756,7 +769,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
756
769
extra_row_output_lines = 0 ;
757
770
}
758
771
}
759
- IsPagerNeeded (cont , extra_output_lines , & fout , & is_pager );
772
+ IsPagerNeeded (cont , extra_output_lines , false, & fout , & is_pager );
760
773
}
761
774
762
775
/* time to output */
@@ -1125,6 +1138,7 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
1125
1138
dformatsize = 0 ;
1126
1139
struct lineptr * hlineptr ,
1127
1140
* dlineptr ;
1141
+ bool is_pager = false;
1128
1142
1129
1143
if (cancel_pressed )
1130
1144
return ;
@@ -1139,6 +1153,13 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
1139
1153
return ;
1140
1154
}
1141
1155
1156
+ /*
1157
+ * Deal with the pager here instead of in printTable(), because we could
1158
+ * get here via print_aligned_text() in expanded auto mode, and so we have
1159
+ * to recalcuate the pager requirement based on vertical output.
1160
+ */
1161
+ IsPagerNeeded (cont , 0 , true, & fout , & is_pager );
1162
+
1142
1163
/* Find the maximum dimensions for the headers */
1143
1164
for (i = 0 ; i < cont -> ncolumns ; i ++ )
1144
1165
{
@@ -1295,6 +1316,9 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
1295
1316
free (dlineptr -> ptr );
1296
1317
free (hlineptr );
1297
1318
free (dlineptr );
1319
+
1320
+ if (is_pager )
1321
+ ClosePager (fout );
1298
1322
}
1299
1323
1300
1324
@@ -2265,14 +2289,14 @@ printTableCleanup(printTableContent *const content)
2265
2289
* Setup pager if required
2266
2290
*/
2267
2291
static void
2268
- IsPagerNeeded (const printTableContent * cont , const int extra_lines , FILE * * fout ,
2292
+ IsPagerNeeded (const printTableContent * cont , const int extra_lines , bool expanded , FILE * * fout ,
2269
2293
bool * is_pager )
2270
2294
{
2271
2295
if (* fout == stdout )
2272
2296
{
2273
2297
int lines ;
2274
2298
2275
- if (cont -> opt -> expanded )
2299
+ if (expanded )
2276
2300
lines = (cont -> ncolumns + 1 ) * cont -> nrows ;
2277
2301
else
2278
2302
lines = cont -> nrows + 1 ;
@@ -2310,11 +2334,10 @@ printTable(const printTableContent *cont, FILE *fout, FILE *flog)
2310
2334
if (cont -> opt -> format == PRINT_NOTHING )
2311
2335
return ;
2312
2336
2313
- /* print_aligned_text() handles the pager itself */
2314
- if ((cont -> opt -> format != PRINT_ALIGNED &&
2315
- cont -> opt -> format != PRINT_WRAPPED ) ||
2316
- cont -> opt -> expanded )
2317
- IsPagerNeeded (cont , 0 , & fout , & is_pager );
2337
+ /* print_aligned_*() handles the pager themselves */
2338
+ if (cont -> opt -> format != PRINT_ALIGNED &&
2339
+ cont -> opt -> format != PRINT_WRAPPED )
2340
+ IsPagerNeeded (cont , 0 , (cont -> opt -> expanded == 1 ), & fout , & is_pager );
2318
2341
2319
2342
/* print the stuff */
2320
2343
@@ -2324,32 +2347,32 @@ printTable(const printTableContent *cont, FILE *fout, FILE *flog)
2324
2347
switch (cont -> opt -> format )
2325
2348
{
2326
2349
case PRINT_UNALIGNED :
2327
- if (cont -> opt -> expanded )
2350
+ if (cont -> opt -> expanded == 1 )
2328
2351
print_unaligned_vertical (cont , fout );
2329
2352
else
2330
2353
print_unaligned_text (cont , fout );
2331
2354
break ;
2332
2355
case PRINT_ALIGNED :
2333
2356
case PRINT_WRAPPED :
2334
- if (cont -> opt -> expanded )
2357
+ if (cont -> opt -> expanded == 1 )
2335
2358
print_aligned_vertical (cont , fout );
2336
2359
else
2337
2360
print_aligned_text (cont , fout );
2338
2361
break ;
2339
2362
case PRINT_HTML :
2340
- if (cont -> opt -> expanded )
2363
+ if (cont -> opt -> expanded == 1 )
2341
2364
print_html_vertical (cont , fout );
2342
2365
else
2343
2366
print_html_text (cont , fout );
2344
2367
break ;
2345
2368
case PRINT_LATEX :
2346
- if (cont -> opt -> expanded )
2369
+ if (cont -> opt -> expanded == 1 )
2347
2370
print_latex_vertical (cont , fout );
2348
2371
else
2349
2372
print_latex_text (cont , fout );
2350
2373
break ;
2351
2374
case PRINT_TROFF_MS :
2352
- if (cont -> opt -> expanded )
2375
+ if (cont -> opt -> expanded == 1 )
2353
2376
print_troff_ms_vertical (cont , fout );
2354
2377
else
2355
2378
print_troff_ms_text (cont , fout );
0 commit comments