Format Strings

From Konversation

Jump to: navigation, search


On #konversation today we had the realization that we need format strings to control a wide range of konvi's behaviour.

[18:13] <argonel> consider the nicklist as it is now.. there is a narrow space between the edge of the control and the status icon and a wider space between the status icon and the nick

Contents

Variation One - Python's original string % operator

This one based on Python's original string formatting with operator %.

%{en_space}%{status_icon}%{em_space}%{photo} %{nickname} (%{realname})

Variation Two - Python's string.Template

This one is similar to many programming languages, now even Python does it with the string.Template module.

$en_space$status_icon$em_space$photo $nickname ($realname)

This can also be written using braces for clarity and to disambiguate strings like "${foo}bar" from "$foobar". This style is supported by Bourne-style shells and Perl as well, so many people will be familiar with it. For example, the preceding example could also be written thus:

${en_space}${status_icon}${em_space}${photo} $nickname ($realname)

Variation Three - Bash without whitespace?

I find that the second variation is too difficult to read, with the $ as the only delimeter its really packed in tight. If we make whitespace insignificant, it then has to be:

$en_space $status_icon $em_space $photo $space $nickname ($realname)

...which is getting out of control.

Variation Four - BASIC with entities

Another possibility is going with basic-style string concatenation and using html entities:

"&ensp;" + status_icon" + "&emsp;" + photo + "&emsp;" + nickname + " (" + realname + ")"

...but html entities are a PITA unless you deal with them often, which I (for one) don't.


Variation Five - XML-like

Well, I wasn't going to do this but I know that it will be proposed. Here is XML:

&ensp;<status_icon/>&emsp;<photo/>&emsp;<nickname/> (<realname/>)

...pretty ugly imo.


Anyone have any other ideas? Add them here :-)

Personal tools