lcpz / lain

Awesome WM complements
GNU General Public License v2.0
1.06k stars 212 forks source link

fix cal day alignment for short day names #540

Closed hp-pepster closed 1 year ago

hp-pepster commented 1 year ago

If the day names do not consist of three characters, the alignment is off (see https://github.com/lcpz/lain/issues/522)

lcpz commented 1 year ago

Hi, thank you for your interest. I think it could be done just by using string.format. Something like this:

for x = 0, 6 do
    notifytable[#notifytable + 1] = string.format("%-3s ", os.date("%a",
    os.time { year = 2006, month = 1, day = x + cal.week_star }):sub(1, utf8.offset(1, 3))
end

Can you please test it? Plus, I admit that the code is a bit too compressed, so any reformatting is welcome.

EDIT: Also, if you can get rid of the utf8 dependency, that would solve #503 too.

hp-pepster commented 1 year ago

I'll look into it after work. Seems like string.format() does not support right alignment, which leads to a strange format grafik

hp-pepster commented 1 year ago

I tested it on my system and also tested for this bug https://github.com/lcpz/lain/issues/476 which I assume was the reason for the utf-8 fix.

Maybe @Czarnodziej or @arielnmz can test if my commits don't break it again.

Czarnodziej commented 1 year ago

Looks good to me. Utf-8 names working properly with this commit on Lua 5.4.4