diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-05-25 22:32:02 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-05-25 22:32:02 -0700 |
| commit | 8cf905cd2cd3113db87fcd172637cf9a7f677c69 (patch) | |
| tree | ca5b0b023f12d2724658e50ebe5564e4567ea492 | |
| parent | 6dde7b420d6e83726638232721b29257304b2967 (diff) | |
Added randomization option
| -rwxr-xr-x | nowopen | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -26,10 +26,14 @@ local place_text = f:read("*a") f:close() local raw_print = false +local randomize = false for i=#arg,1,-1 do if arg[i] == "-p" then raw_print = true 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 print([[ 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, center("¯\\_(ツ)_/¯", cols)) else - table.sort(options, function(o1, o2) return o1.until_close < o2.until_close end) + if randomize then + options = {options[math.random(#options)]} + else + table.sort(options, function(o1, o2) return o1.until_close < o2.until_close end) + end local max_line = 0 for _,option in ipairs(options) do local line = ("%s: %2s:%02d left"):format( @@ -171,7 +179,11 @@ else end if not raw_print then for i, line in ipairs(lines) do lines[i] = center(lpad(line, max_line), cols) end - table.insert(lines, 1, center("\x1b[7m"..center("Open Now", max_line).."\x1b[0m", cols)) + 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)) + end table.insert(lines, 2, "") end end |
