ashish-yadav11 / dwmblocks

Rewrite of dwmblocks with added features including clickability, cursor hinting and color.
ISC License
212 stars 30 forks source link

Extra characters being added in the first block #12

Closed mastopgunaf closed 4 years ago

mastopgunaf commented 4 years ago

I have this rather strange bug. In my first block I have a date module, this is the script that sets it (I do admit it's kind of weird, but whatever):

printf "    $(date +'%a')\x0c,\x0b $(date +'%b %-d')      $(date +'%-H')\x0c:\x0b$(date +'%M')"

And the issue is that unless I include some character at the end (\0 works fine), there will be an extra digit in the minutes section when the hour is a single digit number. So when it's 10 AM, for example, I'll get something like 10:24, but when it's 9 AM, I get something like this: https://i.imgur.com/nfObiNo.png

This particularly happens when clocks change from being a double digit hour to being a single digit hour. Last time I checked, I couldn't reproduce this issue with an extra \0 at the end of my date script's printf (any character works, actually). It also appears that the issue doesn't come up if using echo instead of printf (probably because echo adds a newline at the end?).

This also appears to happen only in the first defined block.

ashish-yadav11 commented 4 years ago

What happens is the output of the scripts is captured in a buffer. One decision could have been to add an extra null byte after the output is read. But it would be rarely the case that there isn't a new line character at the end of the output, so I decided not to add the extra byte. So you will have to use a null byte or a new line at the end of the printf. I should add this info to the readme. Also this shouldn't be specific to the first block.