Added randomization option
This commit is contained in:
parent
6dde7b420d
commit
8cf905cd2c
12
nowopen
12
nowopen
@ -26,10 +26,14 @@ local place_text = f:read("*a")
|
|||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
local raw_print = false
|
local raw_print = false
|
||||||
|
local randomize = false
|
||||||
for i=#arg,1,-1 do
|
for i=#arg,1,-1 do
|
||||||
if arg[i] == "-p" then
|
if arg[i] == "-p" then
|
||||||
raw_print = true
|
raw_print = true
|
||||||
table.remove(arg, i)
|
table.remove(arg, i)
|
||||||
|
elseif arg[i] == "-r" or arg[i] == "--randomize" then
|
||||||
|
randomize = true
|
||||||
|
table.remove(arg, i)
|
||||||
elseif arg[i] == "-h" or arg[i] == "--help" then
|
elseif arg[i] == "-h" or arg[i] == "--help" then
|
||||||
print([[
|
print([[
|
||||||
nowopen: show which businesses are now open.
|
nowopen: show which businesses are now open.
|
||||||
@ -160,7 +164,11 @@ if #options == 0 and not raw_print then
|
|||||||
table.insert(lines, "")
|
table.insert(lines, "")
|
||||||
table.insert(lines, center("¯\\_(ツ)_/¯", cols))
|
table.insert(lines, center("¯\\_(ツ)_/¯", cols))
|
||||||
else
|
else
|
||||||
|
if randomize then
|
||||||
|
options = {options[math.random(#options)]}
|
||||||
|
else
|
||||||
table.sort(options, function(o1, o2) return o1.until_close < o2.until_close end)
|
table.sort(options, function(o1, o2) return o1.until_close < o2.until_close end)
|
||||||
|
end
|
||||||
local max_line = 0
|
local max_line = 0
|
||||||
for _,option in ipairs(options) do
|
for _,option in ipairs(options) do
|
||||||
local line = ("%s: %2s:%02d left"):format(
|
local line = ("%s: %2s:%02d left"):format(
|
||||||
@ -171,7 +179,11 @@ else
|
|||||||
end
|
end
|
||||||
if not raw_print then
|
if not raw_print then
|
||||||
for i, line in ipairs(lines) do lines[i] = center(lpad(line, max_line), cols) end
|
for i, line in ipairs(lines) do lines[i] = center(lpad(line, max_line), cols) end
|
||||||
|
if randomize then
|
||||||
|
table.insert(lines, 1, center("\x1b[7m"..center("Your Random Selection", max_line).."\x1b[0m", cols))
|
||||||
|
else
|
||||||
table.insert(lines, 1, center("\x1b[7m"..center("Open Now", max_line).."\x1b[0m", cols))
|
table.insert(lines, 1, center("\x1b[7m"..center("Open Now", max_line).."\x1b[0m", cols))
|
||||||
|
end
|
||||||
table.insert(lines, 2, "")
|
table.insert(lines, 2, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user