]> granicus.if.org Git - postgresql/blob - src/bin/psql/print.h
Add a pager_min_lines setting to psql
[postgresql] / src / bin / psql / print.h
1 /*
2  * psql - the PostgreSQL interactive terminal
3  *
4  * Copyright (c) 2000-2015, PostgreSQL Global Development Group
5  *
6  * src/bin/psql/print.h
7  */
8 #ifndef PRINT_H
9 #define PRINT_H
10
11 #include "libpq-fe.h"
12
13
14 enum printFormat
15 {
16         PRINT_NOTHING = 0,                      /* to make sure someone initializes this */
17         PRINT_UNALIGNED,
18         PRINT_ALIGNED,
19         PRINT_WRAPPED,
20         PRINT_HTML,
21         PRINT_LATEX,
22         PRINT_LATEX_LONGTABLE,
23         PRINT_TROFF_MS
24         /* add your favourite output format here ... */
25 };
26
27 typedef struct printTextLineFormat
28 {
29         /* Line drawing characters to be used in various contexts */
30         const char *hrule;                      /* horizontal line character */
31         const char *leftvrule;          /* left vertical line (+horizontal) */
32         const char *midvrule;           /* intra-column vertical line (+horizontal) */
33         const char *rightvrule;         /* right vertical line (+horizontal) */
34 } printTextLineFormat;
35
36 typedef enum printTextRule
37 {
38         /* Additional context for selecting line drawing characters */
39         PRINT_RULE_TOP,                         /* top horizontal line */
40         PRINT_RULE_MIDDLE,                      /* intra-data horizontal line */
41         PRINT_RULE_BOTTOM,                      /* bottom horizontal line */
42         PRINT_RULE_DATA                         /* data line (hrule is unused here) */
43 } printTextRule;
44
45 typedef enum printTextLineWrap
46 {
47         /* Line wrapping conditions */
48         PRINT_LINE_WRAP_NONE,           /* No wrapping */
49         PRINT_LINE_WRAP_WRAP,           /* Wraparound due to overlength line */
50         PRINT_LINE_WRAP_NEWLINE         /* Newline in data */
51 } printTextLineWrap;
52
53 typedef struct printTextFormat
54 {
55         /* A complete line style */
56         const char *name;                       /* for display purposes */
57         printTextLineFormat lrule[4];           /* indexed by enum printTextRule */
58         const char *midvrule_nl;        /* vertical line for continue after newline */
59         const char *midvrule_wrap;      /* vertical line for wrapped data */
60         const char *midvrule_blank; /* vertical line for blank data */
61         const char *header_nl_left; /* left mark after newline */
62         const char *header_nl_right;    /* right mark for newline */
63         const char *nl_left;            /* left mark after newline */
64         const char *nl_right;           /* right mark for newline */
65         const char *wrap_left;          /* left mark after wrapped data */
66         const char *wrap_right;         /* right mark for wrapped data */
67         bool            wrap_right_border;              /* use right-hand border for wrap
68                                                                                  * marks when border=0? */
69 } printTextFormat;
70
71 typedef enum unicode_linestyle
72 {
73         UNICODE_LINESTYLE_SINGLE = 0,
74         UNICODE_LINESTYLE_DOUBLE
75 } unicode_linestyle;
76
77 struct separator
78 {
79         char       *separator;
80         bool            separator_zero;
81 };
82
83 typedef struct printTableOpt
84 {
85         enum printFormat format;        /* see enum above */
86         unsigned short int expanded;/* expanded/vertical output (if supported by
87                                                                  * output format); 0=no, 1=yes, 2=auto */
88         unsigned short int border;      /* Print a border around the table. 0=none,
89                                                                  * 1=dividing lines, 2=full */
90         unsigned short int pager;       /* use pager for output (if to stdout and
91                                                                  * stdout is a tty) 0=off 1=on 2=always */
92         int         pager_min_lines;/* don't use pager unless there are at least
93                                                                  * this many lines */
94         bool            tuples_only;    /* don't output headers, row counts, etc. */
95         bool            start_table;    /* print start decoration, eg <table> */
96         bool            stop_table;             /* print stop decoration, eg </table> */
97         bool            default_footer; /* allow "(xx rows)" default footer */
98         unsigned long prior_records;    /* start offset for record counters */
99         const printTextFormat *line_style;      /* line style (NULL for default) */
100         struct separator fieldSep;      /* field separator for unaligned text mode */
101         struct separator recordSep; /* record separator for unaligned text mode */
102         bool            numericLocale;  /* locale-aware numeric units separator and
103                                                                  * decimal marker */
104         char       *tableAttr;          /* attributes for HTML <table ...> */
105         int                     encoding;               /* character encoding */
106         int                     env_columns;    /* $COLUMNS on psql start, 0 is unset */
107         int                     columns;                /* target width for wrapped format */
108         unicode_linestyle       unicode_border_linestyle;
109         unicode_linestyle       unicode_column_linestyle;
110         unicode_linestyle       unicode_header_linestyle;
111 } printTableOpt;
112
113 /*
114  * Table footers are implemented as a singly-linked list.
115  *
116  * This is so that you don't need to know the number of footers in order to
117  * initialise the printTableContent struct, which is very convenient when
118  * preparing complex footers (as in describeOneTableDetails).
119  */
120 typedef struct printTableFooter
121 {
122         char       *data;
123         struct printTableFooter *next;
124 } printTableFooter;
125
126 /*
127  * The table content struct holds all the information which will be displayed
128  * by printTable().
129  */
130 typedef struct printTableContent
131 {
132         const printTableOpt *opt;
133         const char *title;                      /* May be NULL */
134         int                     ncolumns;               /* Specified in Init() */
135         int                     nrows;                  /* Specified in Init() */
136         const char **headers;           /* NULL-terminated array of header strings */
137         const char **header;            /* Pointer to the last added header */
138         const char **cells;                     /* NULL-terminated array of cell content
139                                                                  * strings */
140         const char **cell;                      /* Pointer to the last added cell */
141         long            cellsadded;             /* Number of cells added this far */
142         bool       *cellmustfree;       /* true for cells that need to be free()d */
143         printTableFooter *footers;      /* Pointer to the first footer */
144         printTableFooter *footer;       /* Pointer to the last added footer */
145         char       *aligns;                     /* Array of alignment specifiers; 'l' or 'r',
146                                                                  * one per column */
147         char       *align;                      /* Pointer to the last added alignment */
148 } printTableContent;
149
150 typedef struct printQueryOpt
151 {
152         printTableOpt topt;                     /* the options above */
153         char       *nullPrint;          /* how to print null entities */
154         bool            quote;                  /* quote all values as much as possible */
155         char       *title;                      /* override title */
156         char      **footers;            /* override footer (default is "(xx rows)") */
157         bool            translate_header;               /* do gettext on column headers */
158         const bool *translate_columns;          /* translate_columns[i-1] => do
159                                                                                  * gettext on col i */
160         int                     n_translate_columns;    /* length of translate_columns[] */
161 } printQueryOpt;
162
163
164 extern const printTextFormat pg_asciiformat;
165 extern const printTextFormat pg_asciiformat_old;
166 extern const printTextFormat pg_utf8format;
167
168
169 extern FILE *PageOutput(int lines, const printTableOpt *topt);
170 extern void ClosePager(FILE *pagerpipe);
171
172 extern void html_escaped_print(const char *in, FILE *fout);
173
174 extern void printTableInit(printTableContent *const content,
175                            const printTableOpt *opt, const char *title,
176                            const int ncolumns, const int nrows);
177 extern void printTableAddHeader(printTableContent *const content,
178                                         char *header, const bool translate, const char align);
179 extern void printTableAddCell(printTableContent *const content,
180                                   char *cell, const bool translate, const bool mustfree);
181 extern void printTableAddFooter(printTableContent *const content,
182                                         const char *footer);
183 extern void printTableSetFooter(printTableContent *const content,
184                                         const char *footer);
185 extern void printTableCleanup(printTableContent *const content);
186 extern void printTable(const printTableContent *cont, FILE *fout, FILE *flog);
187 extern void printQuery(const PGresult *result, const printQueryOpt *opt,
188                    FILE *fout, FILE *flog);
189
190 extern void setDecimalLocale(void);
191 extern const printTextFormat *get_line_style(const printTableOpt *opt);
192 extern void refresh_utf8format(const printTableOpt *opt);
193
194 #ifndef __CYGWIN__
195 #define DEFAULT_PAGER "more"
196 #else
197 #define DEFAULT_PAGER "less"
198 #endif
199
200 #endif   /* PRINT_H */