aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-05 15:34:14 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-05 15:34:14 -0800
commitd02ee056d1d1a39f583d41c6b6cb3b1f985e5878 (patch)
tree4641c8811f9982c595cde880de78140ebe6ff193
parent8e65fed76ab3ea2c1d7cee92c9272f939b231506 (diff)
Added readme/license and better -p flag
-rw-r--r--LICENSE20
-rw-r--r--README.md21
-rw-r--r--example_businesshours15
-rwxr-xr-xnowopen24
4 files changed, 69 insertions, 11 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..b692a92
--- /dev/null
+++ b/LICENSE
@@ -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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f4237ae
--- /dev/null
+++ b/README.md
@@ -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.
diff --git a/example_businesshours b/example_businesshours
new file mode 100644
index 0000000..7b36da3
--- /dev/null
+++ b/example_businesshours
@@ -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
diff --git a/nowopen b/nowopen
index f72ea8a..919be59 100755
--- a/nowopen
+++ b/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
- 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, "")
+ 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()