Re: Ascii Elephant for text based protocols - Final function proposal

From: "Charles Clavadetscher" <clavadetscher(at)swisspug(dot)org>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Ascii Elephant for text based protocols - Final function proposal
Date: 2016-05-17 12:49:36
Message-ID: 009301d1b03a$9643ea00$c2cbbe00$@swisspug.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello all

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Karsten Hilbert
> Sent: Dienstag, 17. Mai 2016 09:23
> To: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] Ascii Elephant for text based protocols - Final
>
> On Tue, May 17, 2016 at 06:58:14AM +0200, Charles Clavadetscher wrote:
>
> > A question to the naming. I find pg_logo() also a good name, but is
> > the prefix pg_* not reserved for system functions? Of course I could
> > use the name I want, but was wondering if there is a policy or a best
> > practice in this area.
>
> pg_logo would only be suitable if it got blessing from "higher up".

Well. This question will be addressed when the body of the function is complete. Now I have a proposal which is in the attachment.

The function accepts a set of arguments, all having default values:

p_frame BOOLEAN DEFAULT false: values true or false.
p_text TEXT[] DEFAULT NULL: Free text as array of text. Each element of the array is a line of text. Maximum of 8 lines. What is
above is ignored.
p_position TEXT DEFAULT 'bottom': position of the text in relation to the pic. bottom or right.
p_align TEXT DEFAULT 'center': Alignment of pic AND text, when p_position is bottom, only of the text otherwise. Values: left,
center, right.
p_valign TEXT DEFAULT 'center': Vertical alignement of the text. Only applies if p_position is right. Values: top, center, bottom.

Below I add a set of sample outputs. Feel free to test it and all feedbacks are as usual very much appreciated.

Regards,
Charles

Sample outputs:

No arguments (all defaults):
select pg_logo();
pg_logo
-----------------------
____ ______ ___
/ )/ \/ \
( / __ _\ )
\ (/ o) ( o) )
\_ (_ ) \ ) _/
\ /\_/ \)/
\/ <//| |\\>
_| |
\|_/
(9 rows)

Add frame:
select pg_logo(true);
pg_logo
---------------------------
+-----------------------+
| ____ ______ ___ |
| / )/ \/ \ |
| ( / __ _\ ) |
| \ (/ o) ( o) ) |
| \_ (_ ) \ ) _/ |
| \ /\_/ \)/ |
| \/ <//| |\\> |
| _| | |
| \|_/ |
| |
+-----------------------+
(12 rows)

Add text using default positioning and alignments:
select pg_logo(true,ARRAY['Swiss PGDay 2016','24.06.2016 - HSR Rapperswil','Switzerland','http://www.pgday.ch']);
pg_logo
---------------------------------
+-----------------------------+
| ____ ______ ___ |
| / )/ \/ \ |
| ( / __ _\ ) |
| \ (/ o) ( o) ) |
| \_ (_ ) \ ) _/ |
| \ /\_/ \)/ |
| \/ <//| |\\> |
| _| | |
| \|_/ |
| |
| Swiss PGDay 2016 |
| 24.06.2016 - HSR Rapperswil |
| Switzerland |
| http://www.pgday.ch |
| |
+-----------------------------+
(17 rows)

Position text on the right hand side of the pic:
select pg_logo(true,ARRAY['Swiss PGDay 2016','24.06.2016 - HSR Rapperswil','Switzerland','http://www.pgday.ch'],'right');
pg_logo
-------------------------------------------------------
+---------------------------------------------------+
| ____ ______ ___ |
| / )/ \/ \ |
| ( / __ _\ ) Swiss PGDay 2016 |
| \ (/ o) ( o) ) 24.06.2016 - HSR Rapperswil |
| \_ (_ ) \ ) _/ Switzerland |
| \ /\_/ \)/ http://www.pgday.ch |
| \/ <//| |\\> |
| _| | |
| \|_/ |
| |
+---------------------------------------------------+
(12 rows)

Change text alignment to left:
select pg_logo(true,ARRAY['Swiss PGDay 2016','24.06.2016 - HSR Rapperswil','Switzerland','http://www.pgday.ch'],'right','left');
pg_logo
-------------------------------------------------------
+---------------------------------------------------+
| ____ ______ ___ |
| / )/ \/ \ |
| ( / __ _\ ) Swiss PGDay 2016 |
| \ (/ o) ( o) ) 24.06.2016 - HSR Rapperswil |
| \_ (_ ) \ ) _/ Switzerland |
| \ /\_/ \)/ http://www.pgday.ch |
| \/ <//| |\\> |
| _| | |
| \|_/ |
| |
+---------------------------------------------------+
(12 rows)

Change vertical alignment of text to bottom:
select pg_logo(true,ARRAY['Swiss PGDay 2016','24.06.2016 - HSR
Rapperswil','Switzerland','http://www.pgday.ch'],'right','left','bottom');
pg_logo
-------------------------------------------------------
+---------------------------------------------------+
| ____ ______ ___ |
| / )/ \/ \ |
| ( / __ _\ ) |
| \ (/ o) ( o) ) |
| \_ (_ ) \ ) _/ |
| \ /\_/ \)/ Swiss PGDay 2016 |
| \/ <//| |\\> 24.06.2016 - HSR Rapperswil |
| _| | Switzerland |
| \|_/ http://www.pgday.ch |
| |
+---------------------------------------------------+
(12 rows)

And all other combinations, e.g. Put text below the pic and left aligned without frame:
select pg_logo(false,ARRAY['Swiss PGDay 2016','24.06.2016 - HSR Rapperswil','Switzerland','http://www.pgday.ch'],'bottom','left');
pg_logo
-----------------------------
____ ______ ___
/ )/ \/ \
( / __ _\ )
\ (/ o) ( o) )
\_ (_ ) \ ) _/
\ /\_/ \)/
\/ <//| |\\>
_| |
\|_/

Swiss PGDay 2016
24.06.2016 - HSR Rapperswil
Switzerland
http://www.pgday.ch
(14 rows)

>
> Karsten
> --
> GPG key ID E4071346 @ eu.pool.sks-keyservers.net
> E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

Attachment Content-Type Size
pg_logo.sql text/plain 10.1 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2016-05-17 13:18:51 Re: FIRST_VALUE argument must appear in group by?
Previous Message Victor Yegorov 2016-05-17 12:25:15 Re: Ascii Elephant for text based protocols - Final