Bar-text-bar (en)
From Conky PitStop
bar-text-bar
Language | English Français |
It works with #! Statler - Conky v1.8.0 Debian: Squeeze
OK so someone asked if it was possible to have:
-- text here --
in conky. Where the — was a solid line similar to the ${hr} command.
People started by saying, “No, not possible.” I thought about it for a bit and said to myself, “Yea I can do that!”. With another trick in conky that I have already showed you in "Bars with text inside".
So I set out and experimented and came up with the solution.
Step 1
Default text for this conky is: font Zekton:size=15. I’m actually using my “conkyemail” which is alignment tm so that is where the width comes from.
You have a title you want to use: System, Temperatures, Music, Weather, whatever. You used ${alignc} or a ${goto xx} command to get it where you want it. We’ll use CONKY for this example with the woodbadge font, as seen to the left.
${hr} ${goto 95}${font woodbadge:size=20}${color2}Conky${color}${font} ${hr}
Step 2
Now you want to “spruce” it up a bit, by adding lines before and after it. It’s easy with the same method used in "Bars with text" by using ${membar}
Now we need to add the code for those “lines” to appear. using the ${membar} command. You’ll need two of them:
${hr} ${goto 93}${font woodbadge:size=20}${color2}Conky${color}${font} ${membar 1,70}${alignr 2}${membar 1,70} ${hr}
Step 3
Set the “height” to 1 to create the “bar” and 70 for the length. Yours will vary (40, 60 100) depending of the width of your conky display, the text you use and the font. Seems like “spacing” is everywhere in conky. :) I also use (always) ${alignr 2) to bring the output 2 pixels back from the right edge. If it’s a calculated output that changes values it can cause flickering, if it’s “on the edge” and nobody likes a flickering conky, well, nobody I know.
OK, there’s the bars, now to add ${voffset -xx}, negative xx to move up, until it’s right where you want it.
${hr} ${goto 93}${font woodbadge:size=20}${color2}Conky${color}${font} ${voffset -25}${membar 1,70}${alignr 2}${membar 1,70} ${hr}
See, just like I said, “I can do that.” (I was using a conky version pre v1.8) Now lets go a bit further. Personalize it a bit.
Step 4
I chose yellow, to match close to the colour of CONKY. “NOT close.” you say. AHHH, but I’m not finished. We are going to “outline” those lines with RED
To do that copy the line you have producing the “lines” and change the color to “red”, and a ${voffset} to -0 for the moment and change the CPU numbers, I’m using 5 & 6.
${hr} ${goto 93}${font woodbadge:size=20}${color2}Conky${color}${font} ${color yellow}${voffset -25}${cpubar cpu3 1,70}${alignr 2}${cpubar cpu4 1,70}${color} ${color red}${voffset -0}${cpubar cpu5 1,70}${alignr 2}${cpubar cpu6 1,70}${color} ${hr}
Step 5
If you’ve done everything right it should look like the image in the left. Now we have to give RED lines height to outline the YELLOW lines. So change the height to: 4. If you think about it, the top of the CPUBAR is 1 and the bottom is 2, so to have something “around” it you need 2 empty spaces between the top and bottom and x-2=2 is 4-2=2. Simple math.
${hr} ${goto 93}${font woodbadge:size=20}${color2}Conky${color}${font} ${color yellow}${voffset -25}${cpubar cpu3 1,70}${alignr 2}${cpubar cpu4 1,70}${color} ${color red}${voffset -0}${cpubar cpu5 4,70}${alignr 2}${cpubar cpu6 4,70}${color} ${hr}
Step 6
It’s time to play with that ${voffset -0} value, your will vary obviously, mine comes it at ${voffset -27}
${hr} ${goto 93}${font woodbadge:size=20}${color2}Conky${color}${font} ${color yellow}${voffset -25}${cpubar cpu3 1,70}${alignr 2}${cpubar cpu4 1,70}${color} ${color red}${voffset -27}${cpubar cpu5 4,70}${alignr 2}${cpubar cpu6 4,70}${color} ${hr}
And that final code produces the broken ${hr} effect that the user asked about.
Something conky, earlier than v1.8+, can --not-- do!
Happy conkying Bruce
Step 7
Well, I assume that it depends on the OS used and maybe what is compiled into Conky because this works on my CrunchBang 10 Statler (based on Debian) with conky v1.8.0
Here is my section after-TEXT:
TEXT ${goto 80}${font woodbadge:size=20}${color5}Sector11${color}${font} ${voffset -23}${cpubar cpu2 5,70}${goto 210}${cpubar cpu2 5,70} ${voffset -17}${goto 2}${color9}${cpubar cpu2 1,66}${goto 212}${cpubar cpu2 1,66}${color}
or the full code, if you want it :
# To use #! in a conky use: ${exec echo '#!'} background no own_window yes own_window_type override #normal own_window_transparent yes #yes own_window_hints skip_taskbar,skip_pager own_window_title test use_xft yes #xftfont terminus:bold:size=8 xftfont DejaVu Sans Mono:size=10 xftalpha 1.0 #0.2 override_utf8_locale yes update_interval 5 total_run_times 0 double_buffer yes no_buffers yes cpu_avg_samples 2 net_avg_samples 2 use_spacer none draw_shades no draw_outline no draw_borders no draw_graph_borders no uppercase no imlib_cache_size 0 # Colors default_color DCDCDC color0 FFD700 color1 FFA07A color2 FF8C00 color3 7FFF00 color4 778899 color5 FFDEAD color6 00BFFF color7 48D1CC color8 FFFF00 color9 FF0000 text_buffer_size 256 # 256 is the minimum short_units yes pad_percents 2 #maximum_width 1280 #minimum_size 500 110 # width, height alignment tl gap_x 20 # left-right gap_y 20 # up-down border_inner_margin 0 border_outer_margin 0 TEXT ${goto 80}${font woodbadge:size=20}${color5}Sector11${color}${font} ${voffset -23}${cpubar cpu2 5,70}${goto 210}${cpubar cpu2 5,70} ${voffset -17}${goto 2}${color9}${cpubar cpu2 1,66}${goto 212}${cpubar cpu2 1,66}${color}