Added readme/license and better -p flag
This commit is contained in:
parent
8e65fed76a
commit
d02ee056d1
20
LICENSE
Normal file
20
LICENSE
Normal file
@ -0,0 +1,20 @@
|
||||
MIT License
|
||||
Copyright 2019 Bruce Hill <bruce@bruce-hill.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# nowopen
|
||||
|
||||
`nowopen` is a simple program to display which places are currently open.
|
||||
|
||||
## Usage
|
||||
|
||||
First, create a file with business hours in it at either `~/.local/share/nowopen/businesshours`
|
||||
(recommended) or `~/.businesshours`. An example businesshours file is provided.
|
||||
The format looks like:
|
||||
|
||||
```
|
||||
Mario Bros Plumbing (plumbers):
|
||||
7am-6:30pm
|
||||
sun: closed
|
||||
```
|
||||
|
||||
Once you have a businesshours file, run `nowopen [-p] [tag1 tag2...]`. Establishments
|
||||
matching any of the specified tags (prefix matching is used) and the amount of
|
||||
time till they close will be displayed. E.g. `nowopen plumber` will show how long
|
||||
"Mario Bros Plumbing" is open. The "-p" flag can be used to print plain text to
|
||||
stdout instead of displaying in a temporary display with colors.
|
15
example_businesshours
Normal file
15
example_businesshours
Normal file
@ -0,0 +1,15 @@
|
||||
# Line comments with "#"
|
||||
Jimmy Pesto's Pizzeria (restaurant, pizza, delivery):
|
||||
11am-midnight
|
||||
fri-sat: 11am-1am
|
||||
|
||||
Mario Bros Plumbing (plumbers):
|
||||
7am-6:30pm
|
||||
mon: closed
|
||||
|
||||
American Panascope (medical equipment):
|
||||
sun: noon-5pm
|
||||
mon: 10am-6pm
|
||||
tue-thu: 9am-8pm
|
||||
fri: noon-6pm
|
||||
sat: 10am-6pm
|
18
nowopen
18
nowopen
@ -123,8 +123,8 @@ local function center(str, n) return (" "):rep((n-displaylen(str))//2)..str..("
|
||||
local function lpad(str, n) return (" "):rep(n-displaylen(str))..str end
|
||||
|
||||
local lines = {}
|
||||
local colors = setmetatable({[0]=31,[1]=33}, {__index=function() return 32 end})
|
||||
if #options == 0 then
|
||||
local colors = setmetatable({[0]="\x1b[31;1m",[1]="\x1b[33;1m"}, {__index=function() return "\x1b[32;1m" end})
|
||||
if #options == 0 and not raw_print then
|
||||
table.insert(lines, center("\x1b[1mSorry, nothing's open\x1b[0m", cols))
|
||||
table.insert(lines, "")
|
||||
table.insert(lines, center("¯\\_(ツ)_/¯", cols))
|
||||
@ -132,18 +132,20 @@ else
|
||||
table.sort(options, function(o1, o2) return o1.until_close < o2.until_close end)
|
||||
local max_line = 0
|
||||
for _,option in ipairs(options) do
|
||||
local line = ("\027[%d;1m%23s: %2s:%02d left\027[0m "):format(
|
||||
colors[hours(option.until_close)], option.name,
|
||||
hours(option.until_close), mins(option.until_close))
|
||||
if #line > max_line then max_line = displaylen(line) end
|
||||
local line = ("%s: %2s:%02d left"):format(
|
||||
option.name, hours(option.until_close), mins(option.until_close))
|
||||
if not raw_print then line = " "..colors[hours(option.until_close)]..line.."\x1b[0m " end
|
||||
if displaylen(line) > max_line then max_line = displaylen(line) end
|
||||
table.insert(lines, line)
|
||||
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))
|
||||
table.insert(lines, 2, "")
|
||||
end
|
||||
end
|
||||
|
||||
output:write(("\n"):rep((rows-#lines)//2))
|
||||
if not raw_print then output:write(("\n"):rep((rows-#lines)//2)) end
|
||||
output:write(table.concat(lines, "\n"))
|
||||
output:write(("\n"):rep((rows-#lines)//2 - 2))
|
||||
if not raw_print then output:write(("\n"):rep((rows-#lines)//2)) end
|
||||
output:close()
|
||||
|
Loading…
Reference in New Issue
Block a user