2

So I've been configuring my AwesomeWM theme on Linux and I came across this issue. Now I'm not an expert programmer of course so I thought I'd come here to ask for help. I've been trying to check if the day of the month is a number from 1 to 9, which will then change the padding of the focused number on the calendar, but it doesn't seem to work..

if (os.time(%d)>= 1) and (os.time(%d) <= 9) then
    theme.calendar_focus_padding = dpi(5)
else
    theme.calendar_focus_padding = dpi(10)
end

I'm getting errors on a whole different file (my rc.lua) which I don't really understand why. Here's the screenshot if anyone understands.

1

All I can understand from this is that it has an issue with the following lines of code (from my rc.lua file):

client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)

I know this is very specific to ask on stack overflow, but if anyone could help, I'd really appreciate that.

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
xorg
  • 137
  • 1
  • 1
  • 11

2 Answers2

1

Right so this version seems to work:

if (os.date("%d") >= "1") and (os.date("%d") <= "9") then
    theme.calendar_focus_padding = dpi(5)
else
    theme.calendar_focus_padding = dpi(10)
end

however the code doesn't act the way it should be. What I mean is, despite this being the 2nd day of July(which should switch the if statement to true and execute everything under the if and before the else statement, right?). Instead, it executes everything under the else statement (theme.calendar_focus_padding = dpi(10)). What's up with that now?

EDIT: So I figured out that I had to convert os.date(etc) to an int. I did so using the tonumber() function and now I have this, which seems to work:

day = tonumber(os.date("%d"))

if (day >= 1) and (day <= 9) then
    theme.calendar_focus_padding = dpi(20)
else
    theme.calendar_focus_padding = dpi(10)
end
xorg
  • 137
  • 1
  • 1
  • 11
0

As @lhf mentioned, your code is not valid lua code. Lua arguments can either be strings, tables, numbers, or null--there is no special handling for patterns (which are usually enclosed in strings for that reason)

This code should work:

if (os.date("%d")>= 1) and (os.date("%d") <= 9) then
    theme.calendar_focus_padding = dpi(5)
else
    theme.calendar_focus_padding = dpi(10)
end

Enclosing the pattern in a string allows the lua lexer to parse it, meaning the code will at least execute. os.time should then parse %d on the function call to provide the relevant value, in this case, the day of the month.

Mooshua
  • 526
  • 2
  • 16
  • 1
    `os.time("%d")` is no good either: `bad argument #1 to 'time' (table expected, got string)`. Now `os.date("%d")` works. – lhf Jul 02 '21 at 00:41