fix: show usage when no args are passed to greenhouse

also niced up the display of the page title
pull/240/head
sammyette 2023-10-24 20:10:53 -04:00
parent 19bb05f001
commit 264043dc1e
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 19 additions and 16 deletions

View File

@ -103,7 +103,7 @@ Available sections: ]] .. table.concat(modules, ', ')
if not self.isSpecial then if not self.isSpecial then
if args[1] == 'api' then if args[1] == 'api' then
self.sink:writeln(lunacolors.reset(string.format('%s', vals.title))) self.sink:writeln(lunacolors.reset(string.format('%s', vals.title)))
self.sink:write(lunacolors.format(string.format('{grayBg} ↳ {white}{italic}%s {reset}', vals.description))) self.sink:write(lunacolors.format(string.format('{grayBg} ↳ {white}{italic}%s {reset}', vals.description or 'No description.')))
else else
self.sink:write(lunacolors.reset(string.format('Viewing doc page %s', moddocPath))) self.sink:write(lunacolors.reset(string.format('Viewing doc page %s', moddocPath)))
end end

View File

@ -2,6 +2,7 @@ local ansikit = require 'ansikit'
local bait = require 'bait' local bait = require 'bait'
local commander = require 'commander' local commander = require 'commander'
local hilbish = require 'hilbish' local hilbish = require 'hilbish'
local lunacolors = require 'lunacolors'
local terminal = require 'terminal' local terminal = require 'terminal'
local Greenhouse = require 'nature.greenhouse' local Greenhouse = require 'nature.greenhouse'
local Page = require 'nature.greenhouse.page' local Page = require 'nature.greenhouse.page'
@ -42,12 +43,7 @@ commander.register('greenhouse', function(args, sinks)
self.sink:write(ansikit.getCSI(self.region.height + 1 .. ';1', 'H')) self.sink:write(ansikit.getCSI(self.region.height + 1 .. ';1', 'H'))
if not self.isSpecial then if not self.isSpecial then
self.sink:write(string.format('\27[0mPage %d', self.curPage)) self.sink:writeln(lunacolors.format(string.format('{grayBg} ↳ Page %d %s{reset}', self.curPage, workingPage.title and '' .. workingPage.title .. ' ' or '')))
if workingPage.title ~= '' then
self.sink:writeln('' .. workingPage.title)
else
self.sink:writeln('')
end
end end
self.sink:write(buffer == '' and display or buffer) self.sink:write(buffer == '' and display or buffer)
end end
@ -106,16 +102,23 @@ commander.register('greenhouse', function(args, sinks)
gh:addPage(page) gh:addPage(page)
end end
for _, name in ipairs(args) do if #args ~= 0 then
local f <close> = io.open(name, 'r') for _, name in ipairs(args) do
if not f then local f <close> = io.open(name, 'r')
sinks.err:writeln(string.format('could not open file %s', name)) if not f then
end sinks.err:writeln(string.format('could not open file %s', name))
end
local page = Page(name, f:read '*a') local page = Page(name, f:read '*a')
gh:addPage(page) gh:addPage(page)
end
ansikit.hideCursor()
gh:initUi()
else
sinks.out:writeln [[greenhouse is the Hilbish pager library and command!
usage: greenhouse <file>...
example: greenhouse hello.md]]
end end
ansikit.hideCursor()
gh:initUi()
end) end)