WUN Formatting Tricks (en)

From Conky PitStop

(Difference between revisions)
Jump to: navigation, search
Line 39: Line 39:
Say you have set in the config that makes imperial units for temperature display: "°F"
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 "°"
+
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
-
 
+
-
you could remove the F in the template like this
+
  out({txt=(now.temp_imperial..now.temp_imperial_unit):gsub("°F","°")})
  out({txt=(now.temp_imperial..now.temp_imperial_unit):gsub("°F","°")})
-
'''NOTE:''' again, surround the output with brackets ()
+
'''NOTE:''' again, surround the output with brackets () then add :gsub("find","replace") at the end
-
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 go in its place
+
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 "°"
In the example above, gsub finds "°F" and replaces it with "°"
Line 62: Line 59:
← Temp: shows the FF°° but ± doesn't.
← 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.
+
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
Using things like this it should be possible to achieve any desired format for your output

Revision as of 16:29, 22 February 2014

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

out({txt=now.location_full})

for mrpeachy that outputs:

Saint Louis, MO

but, if you wanted all lowercase letters:

out({txt=string.lower(now.location_full)})

the output:

saint louis, mo

or if you wanted all caps:

out({txt=string.upper(now.location_full)})

again the output:

SAINT LOUIS, MO

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=now.location_full})
out({txt=string.lower(now.location_full)})

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

out({txt=(now.temp_imperial..now.temp_imperial_unit):gsub("°F","°")})

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
Namespaces
Variants
Actions
Navigation
English
Français
Toolbox