Conky: Variables with IEC units mis-aligned

Created on 27 Dec 2016  路  8Comments  路  Source: brndnmtthws/conky

Variables that return a value such as 0B have a trailing space.

Down:${alignr}${downspeed wlan0}
Up:${alignr}${upspeed wlan0}

There is no trailing space when the speed is "nnnKiB" but not but there is when it's "nnnB ". It seems to affect all speed related variables.

Most helpful comment

@su8 can you open a PR for that?

All 8 comments

In fact - download and upspeed are aligned for 3 digits - so if you have 'nnnB' you have no extra space while if you have 'nB ' you have 2 extra spaces. I never noticed this till you mentioned it - as perhaps the way I have configured my config - have a downspeedgraph and upspeedgraph after the values.

@brndnmtthws @su8 Can you fix this? Pretty please? :heart:

2018-07-28-164347

@lasers Look at

https://github.com/brndnmtthws/conky/blob/76f24cb626b7e46be9307c4f79360aee09533a1c/src/conky.cc#L761

Change it to "%.*f%-1s"

Dunno why there are 2 variants in there when one of them is problematic :D

The run mkdir build;cd build;cmake ../;make -j4, src/conky -c conky.conf

@su8 I saw that. I was lazy (and totally unfamiliar with C++) to try it. When I tried this, conky's behavior changes dramatically between 1.10.8-2 and 1.10.9_pre (git).

To clarify this, I meant conky itself and nothing to do with this issue so I will bisect this right now and file a bug report! Thanks to you for a fast response. :-)

@brndnmtthws Do you approve this PR to close this issue? I do not know C++. I tried to bisect the short_units=yes to see where it stopped working... but I can't compile anything more than 8 months ago due to version changes, deprecation, or such. Let me know. Thx.

diff --git a/src/conky.cc b/src/conky.cc
index d55bff54..e635b7a1 100644
--- a/src/conky.cc
+++ b/src/conky.cc
@@ -753,12 +753,14 @@ void human_readable(long long num, char *buf, int size) {
     spaced_print(buf, size, "%lld", 6, num);
     return;
   }
+
+  /* short_units might be broken for some time (2018-Jul-28) */
   if (short_units.get(*state)) {
     width = 5;
     format = "%.*f%.1s";
   } else {
     width = 7;
-    format = "%.*f%-3s";
+    format = "%.*f%-1s";
   }

   if (llabs(num) < 1000LL) {

A better approach is to use single variable to hold the format specifier like this:

diff --git a/src/conky.cc b/src/conky.cc
index d55bff5..80b5fbe 100644
--- a/src/conky.cc
+++ b/src/conky.cc
   float fnum;
   int precision;
   int width;
-  const char *format;
+  static const char *const format = "%.*f%.1s";

   /* Possibly just output as usual, for example for stdout usage */
   if (!format_human_readable.get(*state)) {
     spaced_print(buf, size, "%lld", 6, num);
     return;
   }
   if (short_units.get(*state)) {
     width = 5;
-    format = "%.*f%.1s";
   } else {
     width = 7;
-    format = "%.*f%-3s";
   }

@su8 can you open a PR for that?

Was this page helpful?
0 / 5 - 0 ratings