2017-03-05 14:02 GMT+01:00 Jan Michálek <[email protected]>:
>
>
> 2017-03-05 13:39 GMT+01:00 Pavel Stehule <[email protected]>:
>
>>
>>
>> 2017-03-05 13:22 GMT+01:00 Pavel Stehule <[email protected]>:
>>
>>>
>>>
>>> 2017-03-05 13:08 GMT+01:00 Jan Michálek <[email protected]>:
>>>
>>>> It is question if it is really new format, because formating is the
>>>> same as aligned/wrapped format, changed is only style of lines.
>>>>
>>>
>>> Please, don't do top posting https://en.wikipedia.org/wiki/
>>> Posting_style#Top-posting
>>>
>>>
>>>> 2017-03-05 12:36 GMT+01:00 Pavel Stehule <[email protected]>:
>>>>
>>>>>
>>>>>
>>>>> 2017-03-05 11:40 GMT+01:00 Jan Michálek <[email protected]>:
>>>>>
>>>>>> I know, but, both new linestyles are created literally by cloning
>>>>>> ascii linestyle and few lines in print_aligned_text. Both works with
>>>>>> "aligned" and "wrapped" format. In rst is wrapped format useful, in my
>>>>>> opinion, in markdown i can`t find how I can get newline in record (maybe
>>>>>> it
>>>>>> is not posiible in main markdown types). So it is why i add markdown and
>>>>>> rst as new linestyles. But it is not problem to change it in command to
>>>>>> use
>>>>>> "\pset format", but i mean, that this is cleaner.
>>>>>>
>>>>>
>>>>> Using a special linestyle for new format is possible probably. But new
>>>>> format should be switched with \pset format command.
>>>>>
>>>>
changed
>
>>>>> Not sure if wrapped or aligned behave is correct for markdown - it is
>>>>> task for markdown processing, not for psql.
>>>>>
>>>>
>>>
>>>
>>> In this case I am inclined to prefer setting via format setting - you
>>> can set a linestyle and border in one step, and then is easy to return back
>>> to previous format. I don't see a big benefit in enhancing set of ascii
>>> linestyles. The collecting new features in formatting is more intuitive
>>> (for me).
>>>
>>
>> This can be discussed what we prefer, and what we would to implement?
>>
>>
>>
>> 1. Nice formatted markdown tables
>>
>>
>> | Tables | Are | Cool |
>> | ------------- |:-------------:| -----:|
>> | col 3 is | right-aligned | $1600 |
>> | col 2 is | centered | $12 |
>> | zebra stripes | are neat | $1 |
>>
>> or 2. enough formatting
>>
>>
>> Markdown | Less | Pretty
>> --- | --- | ---
>> *Still* | `renders` | **nicely**
>> 1 | 2 | 3
>>
>> I personally prefer nice formated table, because more comfortable reading
> source of document and easier editing with blocks (deleting whole columns
> etc.).
> I will change \pset to format.
> I find, when adding <\br> for newline works in retext. I will try to add
> it to patch.
>
> | Tables | Are | Cool |
>
> | ------------- |:-------------:| -----:|
>
> | col 3 is | right-aligned | $1600 |
>
> | col 2 is | centere<br/>d | $12 |
>
> | zebra stripes | are neat | $1 |
>
>
> Jan
>
>
>
>> Pavel
>>
>>
>>
>>
>
>
> --
> Jelen
> Starší čeledín datovýho chlíva
>
--
Jelen
Starší čeledín datovýho chlíva
diff -ru a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
--- a/doc/src/sgml/ref/psql-ref.sgml 2017-02-06 22:45:25.000000000 +0100
+++ b/doc/src/sgml/ref/psql-ref.sgml 2017-03-06 01:35:46.000000000 +0100
@@ -2326,7 +2326,8 @@
<literal>aligned</literal>, <literal>wrapped</literal>,
<literal>html</literal>, <literal>asciidoc</literal>,
<literal>latex</literal> (uses <literal>tabular</literal>),
- <literal>latex-longtable</literal>, or
+ <literal>latex-longtable</literal>,
+ <literal>rst</literal>, <literal>markdown</literal>, or
<literal>troff-ms</literal>.
Unique abbreviations are allowed. (That would mean one letter
is enough.)
@@ -2354,7 +2355,8 @@
<para>
The <literal>html</>, <literal>asciidoc</>, <literal>latex</>,
- <literal>latex-longtable</literal>, and <literal>troff-ms</>
+ <literal>latex-longtable</literal>, <literal>troff-ms</>,
+ and <literal>markdown</> and <literal>rst</>
formats put out tables that are intended to
be included in documents using the respective mark-up
language. They are not complete documents! This might not be
diff -ru a/src/bin/psql/command.c b/src/bin/psql/command.c
--- a/src/bin/psql/command.c 2017-02-06 22:45:25.000000000 +0100
+++ b/src/bin/psql/command.c 2017-03-06 03:27:07.000000000 +0100
@@ -2494,6 +2494,12 @@
case PRINT_TROFF_MS:
return "troff-ms";
break;
+ case PRINT_MARKDOWN:
+ return "markdown";
+ break;
+ case PRINT_RST:
+ return "rst";
+ break;
}
return "unknown";
}
@@ -2565,9 +2571,13 @@
popt->topt.format = PRINT_LATEX_LONGTABLE;
else if (pg_strncasecmp("troff-ms", value, vallen) == 0)
popt->topt.format = PRINT_TROFF_MS;
+ else if (pg_strncasecmp("markdown", value, vallen) == 0)
/*markdown*/
+ popt->topt.format = PRINT_MARKDOWN;
+ else if (pg_strncasecmp("rst", value, vallen) == 0) /*rst*/
+ popt->topt.format = PRINT_RST;
else
{
- psql_error("\\pset: allowed formats are unaligned,
aligned, wrapped, html, asciidoc, latex, latex-longtable, troff-ms\n");
+ psql_error("\\pset: allowed formats are unaligned,
aligned, wrapped, html, asciidoc, latex, latex-longtable, troff-ms, markdown,
rst\n");
return false;
}
diff -ru a/src/bin/psql/help.c b/src/bin/psql/help.c
--- a/src/bin/psql/help.c 2017-02-06 22:45:25.000000000 +0100
+++ b/src/bin/psql/help.c 2017-03-06 01:46:41.000000000 +0100
@@ -373,7 +373,7 @@
fprintf(output, _(" fieldsep field separator for unaligned
output (default \"%s\")\n"), DEFAULT_FIELD_SEP);
fprintf(output, _(" fieldsep_zero set field separator for
unaligned output to zero byte\n"));
fprintf(output, _(" footer enable or disable display of
the table footer [on, off]\n"));
- fprintf(output, _(" format set output format [unaligned,
aligned, wrapped, html, asciidoc, ...]\n"));
+ fprintf(output, _(" format set output format [unaligned,
aligned, wrapped, html, asciidoc, rst, markdown ...]\n"));
fprintf(output, _(" linestyle set the border line drawing
style [ascii, old-ascii, unicode]\n"));
fprintf(output, _(" null set the string to be printed in
place of a null value\n"));
fprintf(output, _(" numericlocale enable or disable display of a
locale-specific character to separate\n"
diff -ru a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
--- a/src/bin/psql/tab-complete.c 2017-02-06 22:45:25.000000000 +0100
+++ b/src/bin/psql/tab-complete.c 2017-03-06 00:57:11.000000000 +0100
@@ -3070,7 +3070,7 @@
{
static const char *const my_list[] =
{"unaligned", "aligned", "wrapped", "html", "asciidoc",
- "latex", "latex-longtable", "troff-ms", NULL};
+ "latex", "latex-longtable", "troff-ms", "markdown",
"rst", NULL};
COMPLETE_WITH_LIST_CS(my_list);
}
diff -ru a/src/fe_utils/print.c b/src/fe_utils/print.c
--- a/src/fe_utils/print.c 2017-02-06 22:45:25.000000000 +0100
+++ b/src/fe_utils/print.c 2017-03-06 00:39:40.000000000 +0100
@@ -57,6 +57,48 @@
static printTableFooter default_footer_cell = {default_footer, NULL};
/* Line style control structures */
+const printTextFormat pg_markdown =
+{
+ "markdown",
+ {
+ {"", "", "", ""},
+ {"-", "|", "|", "|"},
+ {"", "", "", ""},
+ {"", "|", "|", "|"}
+ },
+ "|",
+ "|",
+ "|",
+ " ",
+ "+",
+ " ",
+ " ",
+ ".",
+ ".",
+ true
+};
+
+const printTextFormat pg_rst =
+{
+ "rst",
+ {
+ {"-", "+", "+", "+"},
+ {"=", "+", "+", "+"},
+ {"-", "+", "+", "+"},
+ {"", "|", "|", "|"}
+ },
+ "|",
+ "|",
+ "|",
+ " ",
+ "+",
+ " ",
+ " ",
+ ".",
+ ".",
+ true
+};
+
const printTextFormat pg_asciiformat =
{
"ascii",
@@ -623,6 +665,12 @@
if (opt_border > 2)
opt_border = 2;
+ if (format == &pg_markdown)
+ opt_border = 2;
+
+ if (format == &pg_rst)
+ opt_border = 2;
+
if (cont->ncolumns > 0)
{
col_count = cont->ncolumns;
@@ -1124,13 +1172,20 @@
fputc('\n', fout);
} while (more_lines);
+
+ /* add line after every record
*/
+ if (opt_border == 2 && format == &pg_rst)
+ _print_horizontal_line(col_count, width_wrap, opt_border,
+ PRINT_RULE_BOTTOM, format, fout);
}
if (cont->opt->stop_table)
{
printTableFooter *footers = footers_with_default(cont);
- if (opt_border == 2 && !cancel_pressed)
+ /* dont add line after last row, because line is added after
every row
+ **/
+ if ((opt_border == 2 && format != &pg_rst) && !cancel_pressed)
_print_horizontal_line(col_count, width_wrap,
opt_border,
PRINT_RULE_BOTTOM, format, fout);
@@ -1138,6 +1193,12 @@
if (footers && !opt_tuples_only && !cancel_pressed)
{
printTableFooter *f;
+ /*add newline after table because rst needs empty line
after table
+ */
+ if (format == &pg_rst || format == &pg_markdown)
+ {
+ fprintf(fout, "\n");
+ }
for (f = footers; f; f = f->next)
fprintf(fout, "%s\n", f->data);
@@ -3263,6 +3324,15 @@
else
print_troff_ms_text(cont, fout);
break;
+
+ case PRINT_RST:
+ print_aligned_text(cont, fout, false);
+ break;
+
+ case PRINT_MARKDOWN:
+ print_aligned_text(cont, fout, false);
+ break;
+
default:
fprintf(stderr, _("invalid output format (internal
error): %d"),
cont->opt->format);
@@ -3417,8 +3487,12 @@
* printTableOpt struct can be initialized to zeroes to get default
* behavior.
*/
- if (opt->line_style != NULL)
- return opt->line_style;
+ if (opt->format == PRINT_RST)
+ return &pg_rst;
+ else if (opt->format == PRINT_MARKDOWN)
+ return &pg_markdown;
+ else if (opt->line_style != NULL)
+ return opt->line_style;
else
return &pg_asciiformat;
}
diff -ru a/src/include/fe_utils/print.h b/src/include/fe_utils/print.h
--- a/src/include/fe_utils/print.h 2017-02-06 22:45:25.000000000 +0100
+++ b/src/include/fe_utils/print.h 2017-03-05 18:28:04.000000000 +0100
@@ -33,7 +33,9 @@
PRINT_ASCIIDOC,
PRINT_LATEX,
PRINT_LATEX_LONGTABLE,
- PRINT_TROFF_MS
+ PRINT_TROFF_MS,
+ PRINT_MARKDOWN,
+ PRINT_RST
/* add your favourite output format here ... */
};
@@ -176,6 +178,8 @@
extern volatile bool cancel_pressed;
extern const printTextFormat pg_asciiformat;
+extern const printTextFormat pg_markdown; /*linestyle markdown*/
+extern const printTextFormat pg_rst; /*linestyle rst*/
extern const printTextFormat pg_asciiformat_old;
extern printTextFormat pg_utf8format; /* ideally would be const, but... */
diff -ru a/src/test/regress/expected/psql.out
b/src/test/regress/expected/psql.out
--- a/src/test/regress/expected/psql.out 2017-02-06 22:45:25.000000000
+0100
+++ b/src/test/regress/expected/psql.out 2017-03-06 02:58:18.000000000
+0100
@@ -2714,3 +2714,53 @@
CONTEXT: PL/pgSQL function inline_code_block line 3 at RAISE
ERROR: bar
CONTEXT: PL/pgSQL function inline_code_block line 4 at RAISE
+prepare q AS VALUES(E'Elephant, kangaroo,\nsquirrel, gorilla', 121,
+(279./278.)::text, 0.1111, repeat('Hello ', 10))
+ , (E'goat, rhinoceros,\nmonkey, ape', 11121, (1279./1278.)::text, 5.1111,
+ repeat('xxxxxx ', 10))
+ , (E'donkey, cow, horse, tit,\neagle, whale,\naligator,
+ pelican,\ngrasshoper\npig\n\tbat', 14351, (12345./245.)::text, 345.11,
+ repeat('yyyyyy ', 10));
+\pset format rst
+execute q;
++--------------------------+---------+---------------------+---------+------------------------------------------------------------------------+
+| column1 | column2 | column3 | column4 |
column5 |
++==========================+=========+=====================+=========+========================================================================+
+| Elephant, kangaroo, | 121 | 1.0035971223021583 | 0.1111 | Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello |
+| squirrel, gorilla | | | |
|
++--------------------------+---------+---------------------+---------+------------------------------------------------------------------------+
+| goat, rhinoceros, | 11121 | 1.0007824726134585 | 5.1111 | xxxxxx
xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx |
+| monkey, ape | | | |
|
++--------------------------+---------+---------------------+---------+------------------------------------------------------------------------+
+| donkey, cow, horse, tit, | 14351 | 50.3877551020408163 | 345.11 | yyyyyy
yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy |
+| eagle, whale, | | | |
|
+| aligator, | | | |
|
+| pelican, | | | |
|
+| grasshoper | | | |
|
+| pig | | | |
|
+| bat | | | |
|
++--------------------------+---------+---------------------+---------+------------------------------------------------------------------------+
+
+(3 rows)
+
+\pset format markdown
+execute q;
+
+| column1 | column2 | column3 | column4 |
column5 |
+|--------------------------|---------|---------------------|---------|------------------------------------------------------------------------|
+| Elephant, kangaroo, | 121 | 1.0035971223021583 | 0.1111 | Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello |
+| squirrel, gorilla | | | |
|
+| goat, rhinoceros, | 11121 | 1.0007824726134585 | 5.1111 | xxxxxx
xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx |
+| monkey, ape | | | |
|
+| donkey, cow, horse, tit, | 14351 | 50.3877551020408163 | 345.11 | yyyyyy
yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy yyyyyy |
+| eagle, whale, | | | |
|
+| aligator, | | | |
|
+| pelican, | | | |
|
+| grasshoper | | | |
|
+| pig | | | |
|
+| bat | | | |
|
+
+
+(3 rows)
+
+deallocate q;
diff -ru a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
--- a/src/test/regress/sql/psql.sql 2017-02-06 22:45:25.000000000 +0100
+++ b/src/test/regress/sql/psql.sql 2017-03-06 02:15:15.000000000 +0100
@@ -379,3 +379,17 @@
raise notice 'foo';
raise exception 'bar';
end $$;
+
+prepare q AS VALUES(E'Elephant, kangaroo,\nsquirrel, gorilla', 121,
+(279./278.)::text, 0.1111, repeat('Hello ', 10))
+ , (E'goat, rhinoceros,\nmonkey, ape', 11121, (1279./1278.)::text, 5.1111,
+ repeat('xxxxxx ', 10))
+ , (E'donkey, cow, horse, tit,\neagle, whale,\naligator,
+ pelican,\ngrasshoper\npig\n\tbat', 14351, (12345./245.)::text, 345.11,
+ repeat('yyyyyy ', 10));
+
+\pset format rst
+execute q;
+\pset format markdown
+execute q;
+deallocate q;
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers