WUN Formatting Tricks (en)

From Conky PitStop

Jump to: navigation, search

WUN Formatting Tricks

 Language   English   Français   

From the words of mrpeachy seen here in post #428.

Because WUN weather templates are written in lua code you can do a lot of other things to the output of data options.

If i were to try and cover ALL the bases in the data options there would be thousands of them!

Example: using an option in the out function like so


For mrpeachy that outputs:

Saint Louis, MO

But, if you wanted all lowercase letters:


The output:

saint louis, mo

Or if you wanted all caps:


Again the output:


It also works for long multi-part text strings like this:

txt=string.lower("Updated: "..now.observation_time_rfc822.." from data at: "..now.observation_location_city.."      "..os.date("%T"))

That line would output something like:

updated: Mon, 06 jan 2014 20:10:34 -0600 from data at saint louis, mo      22:15:41

NOTE the use of () with this added feature:


out({txt="Updated: "..now.observation_time_rfc822.." from data at: "..now.observation_location_city.."      "..os.date("%T")})
out({txt=string.lower("Updated: "..now.observation_time_rfc822.." from data at: "..now.observation_location_city.."      "..os.date("%T")})

To reiterate: Make sure you surround all your output with brackets (), when using string.upper or string.lower

Another example is "gsub"

Say you have set in the config that makes imperial units for temperature display: "°F" However if there is a single part of the output that you think it would look better if it was just "°", you could remove the F in the template like this


NOTE: again, surround the output with brackets () then add :gsub("find","replace") at the end

Between the first set of quotes goes the text to find, between the second set of quotes goes the text to display in its place

In the example above, gsub finds "°F" and replaces it with "°"

EDIT by mrpeachy - This is probably a bad example because it would be much easier to just hard code the "°" into the output instead of using the units data options, but the same principal can be applied to lots of other things.

This is why I added the single

Since my config is set to use "°" here's a reverse example where I commented out the feels_like temp line to show it in action:

out({a=1,x=15,y=ypos,txt=("Temp : "..now.temp_imperial..now.temp_imperial_unit):gsub("°","FF°°")})
--out({a=1,c=0xFFD700,x=115,y=ypos,txt="    ±: "..now.feelslike_imperial..now.feelslike_imperial_unit})
out({a=1,c=0xFFD700,x=115,y=ypos,txt="    ±: "..now.temp_imperial..now.temp_imperial_unit}) -- NO FF°° HERE

Gsub.jpg ← Temp: shows the FF°° but ± doesn't.

Now if you use it in a "repeat table" section of the template it will affect every instance that is repeated, which would make mrpeachy's original statement:

in the example above, gsub finds every instance of "°F" and replaces it with "°" 

absolutely correct.

Using things like this it should be possible to achieve any desired format for your output

One more: Capitalize first letter of every word in Lua

Go To:

Some editorial modifications by Sestor11

Personal tools