2015-12-19 6:55 GMT+01:00 Pavel Stehule <[email protected]>:
>
>
> 2015-12-18 21:21 GMT+01:00 Daniel Verite <[email protected]>:
>
>> Pavel Stehule wrote:
>>
>> > The symbol 'X' in two column mode should be centred - now it is aligned
>> to
>> > left, what is not nice
>>
>> Currently print.c does not support centered alignment, only left and
>> right.
>> Should we add it, it would have to work for all output formats
>> (except obviously for "unaligned"):
>> - aligned
>> - wrapped
>> - html
>> - latex
>> - latex-longtable
>> - troff-ms
>> - asciidoc
>>
>> Because of this, I believe that adding support for a 'c' alignment
>> might be a significant patch by itself, and that it should be considered
>> separately.
>>
>
> ok
>
>
>>
>> I agree that if it existed, the crosstabview command should use it
>> as you mention, but I'm not volunteering to implement it myself, at
>> least not in the short term.
>>
>
> I'll look how much work it is
>
attached patch allows align to center.
everywhere where left/right align was allowed, the center align is allowed
Regards
Pavel
>
> Regards
>
> Pavel
>
>
>>
>> Best regards,
>> --
>> Daniel Vérité
>> PostgreSQL-powered mailer: http://www.manitou-mail.org
>> Twitter: @DanielVerite
>>
>
>
diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c
new file mode 100644
index 6d13b57..c9e11c2
*** a/src/bin/psql/crosstabview.c
--- b/src/bin/psql/crosstabview.c
*************** printCrosstab(const PGresult *results,
*** 203,209 ****
* alignment is determined by PQftype(). Otherwise the contents are
* made-up strings, so the alignment is 'l'
*/
! if (PQnfields(results) == 3)
{
int colnum; /* column placed inside
the grid */
/*
--- 203,213 ----
* alignment is determined by PQftype(). Otherwise the contents are
* made-up strings, so the alignment is 'l'
*/
! if (PQnfields(results) == 2)
! {
! col_align = 'c';
! }
! else if (PQnfields(results) == 3)
{
int colnum; /* column placed inside
the grid */
/*
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
new file mode 100644
index b2f8c2b..6e2cc6e
*** a/src/bin/psql/print.c
--- b/src/bin/psql/print.c
*************** print_aligned_text(const printTableConte
*** 1042,1059 ****
{
/* spaces first */
fprintf(fout, "%*s",
width_wrap[j] - chars_to_output, "");
- fputnbytes(fout,
- (char *)
(this_line->ptr + bytes_output[j]),
-
bytes_to_output);
}
! else /* Left aligned cell */
{
! /* spaces second */
! fputnbytes(fout,
! (char *)
(this_line->ptr + bytes_output[j]),
!
bytes_to_output);
}
bytes_output[j] += bytes_to_output;
/* Do we have more text to wrap? */
--- 1042,1059 ----
{
/* spaces first */
fprintf(fout, "%*s",
width_wrap[j] - chars_to_output, "");
}
! else if (cont->aligns[j] == 'c') /*
Center aligned cell */
{
! /* spaces first */
! fprintf(fout, "%*s",
! (width_wrap[j] -
chars_to_output) / 2, "");
}
+ fputnbytes(fout,
+ (char *)
(this_line->ptr + bytes_output[j]),
+ bytes_to_output);
+
bytes_output[j] += bytes_to_output;
/* Do we have more text to wrap? */
*************** print_aligned_text(const printTableConte
*** 1083,1095 ****
* If left-aligned, pad out remaining space if
needed (not
* last column, and/or wrap marks required).
*/
! if (cont->aligns[j] != 'r') /* Left
aligned cell */
{
! if (finalspaces ||
! wrap[j] == PRINT_LINE_WRAP_WRAP
||
! wrap[j] ==
PRINT_LINE_WRAP_NEWLINE)
fprintf(fout, "%*s",
! width_wrap[j] -
chars_to_output, "");
}
/* Print right-hand wrap or newline mark */
--- 1083,1104 ----
* If left-aligned, pad out remaining space if
needed (not
* last column, and/or wrap marks required).
*/
! if (finalspaces ||
! wrap[j] == PRINT_LINE_WRAP_WRAP ||
! wrap[j] == PRINT_LINE_WRAP_NEWLINE)
{
! if (cont->aligns[j] == 'c')
! {
! /* last spaces */
fprintf(fout, "%*s",
!
width_wrap[j] - chars_to_output
! -
((width_wrap[j] - chars_to_output) / 2 ), "");
! }
! else if (cont->aligns[j] == 'l')
! {
! /* last spaces */
! fprintf(fout, "%*s",
width_wrap[j] - chars_to_output, "");
! }
}
/* Print right-hand wrap or newline mark */
*************** html_escaped_print(const char *in, FILE
*** 1778,1783 ****
--- 1787,1805 ----
}
}
+ /*
+ * Returns align value in html format
+ */
+ static const char *
+ format_html_align_attr(char align)
+ {
+ if (align == 'r')
+ return "right";
+ else if (align == 'c')
+ return "center";
+ else
+ return "left";
+ }
static void
print_html_text(const printTableContent *cont, FILE *fout)
*************** print_html_text(const printTableContent
*** 1830,1836 ****
fputs(" <tr valign=\"top\">\n", fout);
}
! fprintf(fout, " <td align=\"%s\">", cont->aligns[(i) %
cont->ncolumns] == 'r' ? "right" : "left");
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
--- 1852,1860 ----
fputs(" <tr valign=\"top\">\n", fout);
}
! fprintf(fout, " <td align=\"%s\">",
! format_html_align_attr(cont->aligns[(i) %
cont->ncolumns]));
!
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
*************** print_html_vertical(const printTableCont
*** 1916,1922 ****
html_escaped_print(cont->headers[i % cont->ncolumns], fout);
fputs("</th>\n", fout);
! fprintf(fout, " <td align=\"%s\">", cont->aligns[i %
cont->ncolumns] == 'r' ? "right" : "left");
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
--- 1940,1950 ----
html_escaped_print(cont->headers[i % cont->ncolumns], fout);
fputs("</th>\n", fout);
!
!
! fprintf(fout, " <td align=\"%s\">",
! format_html_align_attr(cont->aligns[i %
cont->ncolumns]));
!
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
*************** asciidoc_escaped_print(const char *in, F
*** 1971,1976 ****
--- 1999,2015 ----
}
}
+ static const char *
+ format_asciidoc_align_attr(char align)
+ {
+ if (align == 'r')
+ return ">l";
+ else if (align == 'c')
+ return "^l";
+ else
+ return "<l";
+ }
+
static void
print_asciidoc_text(const printTableContent *cont, FILE *fout)
{
*************** print_asciidoc_text(const printTableCont
*** 2001,2007 ****
{
if (i != 0)
fputs(",", fout);
! fprintf(fout, "%s", cont->aligns[(i) % cont->ncolumns]
== 'r' ? ">l" : "<l");
}
fputs("\"", fout);
switch (opt_border)
--- 2040,2047 ----
{
if (i != 0)
fputs(",", fout);
! fprintf(fout, "%s",
! format_asciidoc_align_attr(cont->aligns[(i)
% cont->ncolumns]));
}
fputs("\"", fout);
switch (opt_border)
*************** print_asciidoc_vertical(const printTable
*** 2142,2148 ****
fputs("<l|", fout);
asciidoc_escaped_print(cont->headers[i % cont->ncolumns], fout);
! fprintf(fout, " %s|", cont->aligns[i % cont->ncolumns] == 'r' ?
">l" : "<l");
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
--- 2182,2190 ----
fputs("<l|", fout);
asciidoc_escaped_print(cont->headers[i % cont->ncolumns], fout);
! fprintf(fout, " %s|",
! format_asciidoc_align_attr(cont->aligns[(i)
% cont->ncolumns]));
!
/* is string only whitespace? */
if ((*ptr)[strspn(*ptr, " \t")] == '\0')
fputs(" ", fout);
*************** print_latex_longtable_text(const printTa
*** 2343,2349 ****
for (i = 0; i < cont->ncolumns; i++)
{
! /* longtable supports either a width (p) or an
alignment (l/r) */
/* Are we left-justified and was a proportional width
specified? */
if (*(cont->aligns + i) == 'l' && opt_table_attr)
{
--- 2385,2391 ----
for (i = 0; i < cont->ncolumns; i++)
{
! /* longtable supports either a width (p) or an
alignment (l/c/r) */
/* Are we left-justified and was a proportional width
specified? */
if (*(cont->aligns + i) == 'l' && opt_table_attr)
{
*************** printTableInit(printTableContent *const
*** 2950,2957 ****
* If translate is true, the function will pass the header through gettext.
* Otherwise, the header will not be translated.
*
! * align is either 'l' or 'r', and specifies the alignment for cells in this
! * column.
*/
void
printTableAddHeader(printTableContent *const content, char *header,
--- 2992,2999 ----
* If translate is true, the function will pass the header through gettext.
* Otherwise, the header will not be translated.
*
! * align is either 'l' or 'c' or'r', and specifies the alignment for cells
! * in this column.
*/
void
printTableAddHeader(printTableContent *const content, char *header,
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers