mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "19bb05f001b3315d6c15311b9a8a04e42036f615" and "5b4b055c6cbb9532f42901310db5ba26a93a1b3b" have entirely different histories.
19bb05f001
...
5b4b055c6c
|
@ -7,7 +7,6 @@
|
||||||
- `flush()` and `autoFlush()` related to flushing outputs
|
- `flush()` and `autoFlush()` related to flushing outputs
|
||||||
- `pipe` property to check if a sink with input is a pipe (like stdin)
|
- `pipe` property to check if a sink with input is a pipe (like stdin)
|
||||||
- Show indexes on cdr list
|
- Show indexes on cdr list
|
||||||
- Fix doc command not displaying correct subdocs when using shorthand api doc access (`doc api hilbish.jobs` as an example)
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Replaced `sed` in-place editing with `grep` and `mv` for compatibility with BSD utils
|
- Replaced `sed` in-place editing with `grep` and `mv` for compatibility with BSD utils
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
local ansikit = require 'ansikit'
|
|
||||||
local commander = require 'commander'
|
local commander = require 'commander'
|
||||||
local fs = require 'fs'
|
local fs = require 'fs'
|
||||||
local lunacolors = require 'lunacolors'
|
local lunacolors = require 'lunacolors'
|
||||||
|
@ -12,6 +11,11 @@ commander.register('doc', function(args, sinks)
|
||||||
-- hilbish git
|
-- hilbish git
|
||||||
moddocPath = './docs/'
|
moddocPath = './docs/'
|
||||||
end
|
end
|
||||||
|
local apidocHeader = [[
|
||||||
|
# %s
|
||||||
|
{grayBg} {white}{italic}%s {reset}
|
||||||
|
|
||||||
|
]]
|
||||||
|
|
||||||
local modules = table.map(fs.readdir(moddocPath), function(f)
|
local modules = table.map(fs.readdir(moddocPath), function(f)
|
||||||
return lunacolors.underline(lunacolors.blue(string.gsub(f, '.md', '')))
|
return lunacolors.underline(lunacolors.blue(string.gsub(f, '.md', '')))
|
||||||
|
@ -23,8 +27,6 @@ to Hilbish.
|
||||||
|
|
||||||
Usage: doc <section> [subdoc]
|
Usage: doc <section> [subdoc]
|
||||||
Available sections: ]] .. table.concat(modules, ', ')
|
Available sections: ]] .. table.concat(modules, ', ')
|
||||||
local vals = {}
|
|
||||||
|
|
||||||
if #args > 0 then
|
if #args > 0 then
|
||||||
local mod = args[1]
|
local mod = args[1]
|
||||||
|
|
||||||
|
@ -32,18 +34,18 @@ Available sections: ]] .. table.concat(modules, ', ')
|
||||||
local funcdocs = nil
|
local funcdocs = nil
|
||||||
local subdocName = args[2]
|
local subdocName = args[2]
|
||||||
if not f then
|
if not f then
|
||||||
|
-- assume subdir
|
||||||
|
-- dataDir/docs/<mod>/<mod>.md
|
||||||
moddocPath = moddocPath .. mod .. '/'
|
moddocPath = moddocPath .. mod .. '/'
|
||||||
if not subdocName then
|
if not subdocName then
|
||||||
subdocName = '_index'
|
subdocName = '_index'
|
||||||
end
|
end
|
||||||
f = io.open(moddocPath .. subdocName .. '.md', 'rb')
|
f = io.open(moddocPath .. subdocName .. '.md', 'rb')
|
||||||
local oldmoddocPath = moddocPath
|
|
||||||
if not f then
|
if not f then
|
||||||
moddocPath = moddocPath .. subdocName:match '%w+' .. '/'
|
f = io.open(moddocPath .. subdocName:match '%w+' .. '/' .. subdocName .. '.md', 'rb')
|
||||||
f = io.open(moddocPath .. subdocName .. '.md', 'rb')
|
|
||||||
end
|
end
|
||||||
if not f then
|
if not f then
|
||||||
moddocPath = oldmoddocPath .. subdocName .. '/'
|
moddocPath = moddocPath .. subdocName .. '/'
|
||||||
subdocName = args[3] or '_index'
|
subdocName = args[3] or '_index'
|
||||||
f = io.open(moddocPath .. subdocName .. '.md', 'rb')
|
f = io.open(moddocPath .. subdocName .. '.md', 'rb')
|
||||||
end
|
end
|
||||||
|
@ -58,10 +60,11 @@ Available sections: ]] .. table.concat(modules, ', ')
|
||||||
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.md', '')))
|
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.md', '')))
|
||||||
end)
|
end)
|
||||||
if #moddocs ~= 0 then
|
if #moddocs ~= 0 then
|
||||||
funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ') .. '\n\n'
|
funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
local valsStr = funcdocs:match '%-%-%-\n([^%-%-%-]+)\n'
|
local valsStr = funcdocs:match '%-%-%-\n([^%-%-%-]+)\n'
|
||||||
|
local vals = {}
|
||||||
if valsStr then
|
if valsStr then
|
||||||
local _, endpos = funcdocs:find('---\n' .. valsStr .. '\n---\n\n', 1, true)
|
local _, endpos = funcdocs:find('---\n' .. valsStr .. '\n---\n\n', 1, true)
|
||||||
funcdocs = funcdocs:sub(endpos + 1, #funcdocs)
|
funcdocs = funcdocs:sub(endpos + 1, #funcdocs)
|
||||||
|
@ -77,38 +80,14 @@ Available sections: ]] .. table.concat(modules, ', ')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if mod == 'api' then
|
||||||
|
funcdocs = string.format(apidocHeader, vals.title, vals.description or 'no description.') .. funcdocs
|
||||||
|
end
|
||||||
doc = funcdocs:sub(1, #funcdocs - 1)
|
doc = funcdocs:sub(1, #funcdocs - 1)
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local gh = Greenhouse(sinks.out)
|
local gh = Greenhouse(sinks.out)
|
||||||
function gh:resize()
|
|
||||||
local size = terminal.size()
|
|
||||||
self.region = {
|
|
||||||
width = size.width,
|
|
||||||
height = size.height - 3
|
|
||||||
}
|
|
||||||
end
|
|
||||||
gh:resize()
|
|
||||||
|
|
||||||
function gh:render()
|
|
||||||
local workingPage = self.pages[self.curPage]
|
|
||||||
local offset = self.offset
|
|
||||||
if self.isSpecial then
|
|
||||||
offset = self.specialOffset
|
|
||||||
workingPage = self.specialPage
|
|
||||||
end
|
|
||||||
|
|
||||||
self.sink:write(ansikit.getCSI(self.region.height + 2 .. ';1', 'H'))
|
|
||||||
if not self.isSpecial then
|
|
||||||
if args[1] == 'api' then
|
|
||||||
self.sink:writeln(lunacolors.reset(string.format('%s', vals.title)))
|
|
||||||
self.sink:write(lunacolors.format(string.format('{grayBg} ↳ {white}{italic}%s {reset}', vals.description)))
|
|
||||||
else
|
|
||||||
self.sink:write(lunacolors.reset(string.format('Viewing doc page %s', moddocPath)))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local backtickOccurence = 0
|
local backtickOccurence = 0
|
||||||
local page = Page(nil, lunacolors.format(doc:gsub('`', function()
|
local page = Page(nil, lunacolors.format(doc:gsub('`', function()
|
||||||
backtickOccurence = backtickOccurence + 1
|
backtickOccurence = backtickOccurence + 1
|
||||||
|
@ -122,6 +101,5 @@ Available sections: ]] .. table.concat(modules, ', ')
|
||||||
return '{bold}{yellow}' .. signature .. '{reset}'
|
return '{bold}{yellow}' .. signature .. '{reset}'
|
||||||
end)))
|
end)))
|
||||||
gh:addPage(page)
|
gh:addPage(page)
|
||||||
ansikit.hideCursor()
|
|
||||||
gh:initUi()
|
gh:initUi()
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -32,7 +32,9 @@ commander.register('greenhouse', function(args, sinks)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function gh:render()
|
local oldDraw = gh.draw
|
||||||
|
function gh:draw()
|
||||||
|
oldDraw(self)
|
||||||
local workingPage = self.pages[self.curPage]
|
local workingPage = self.pages[self.curPage]
|
||||||
local offset = self.offset
|
local offset = self.offset
|
||||||
if self.isSpecial then
|
if self.isSpecial then
|
||||||
|
@ -40,7 +42,7 @@ commander.register('greenhouse', function(args, sinks)
|
||||||
workingPage = self.specialPage
|
workingPage = self.specialPage
|
||||||
end
|
end
|
||||||
|
|
||||||
self.sink:write(ansikit.getCSI(self.region.height + 1 .. ';1', 'H'))
|
self.sink:write(ansikit.getCSI((self.region.height + 2) - self.start.. ';1', 'H'))
|
||||||
if not self.isSpecial then
|
if not self.isSpecial then
|
||||||
self.sink:write(string.format('\27[0mPage %d', self.curPage))
|
self.sink:write(string.format('\27[0mPage %d', self.curPage))
|
||||||
if workingPage.title ~= '' then
|
if workingPage.title ~= '' then
|
||||||
|
|
|
@ -15,8 +15,7 @@ local Greenhouse = Object:extend()
|
||||||
function Greenhouse:new(sink)
|
function Greenhouse:new(sink)
|
||||||
local size = terminal.size()
|
local size = terminal.size()
|
||||||
self.region = size
|
self.region = size
|
||||||
self.contents = nil -- or can be a table
|
self.start = 1
|
||||||
self.start = 1 -- where to start drawing from (should replace with self.region.y)
|
|
||||||
self.offset = 1 -- vertical text offset
|
self.offset = 1 -- vertical text offset
|
||||||
self.sink = sink
|
self.sink = sink
|
||||||
self.pages = {}
|
self.pages = {}
|
||||||
|
@ -72,14 +71,11 @@ function Greenhouse:draw()
|
||||||
self.sink:write(ansikit.getCSI(self.start .. ';1', 'H'))
|
self.sink:write(ansikit.getCSI(self.start .. ';1', 'H'))
|
||||||
self.sink:write(ansikit.getCSI(2, 'J'))
|
self.sink:write(ansikit.getCSI(2, 'J'))
|
||||||
|
|
||||||
for i = offset, offset + self.region.height - 1 do
|
for i = offset, offset + (self.region.height - 1) do
|
||||||
if i > #lines then break end
|
if i > #lines then break end
|
||||||
|
self.sink:writeln('\r' .. sub(lines[i]:gsub('\t', ' '), self.region.width - 2))
|
||||||
local writer = self.sink.writeln
|
|
||||||
if i == offset + self.region.height - 1 then writer = self.sink.write end
|
|
||||||
|
|
||||||
writer(self.sink, sub(lines[i]:gsub('\t', ' '), self.region.width))
|
|
||||||
end
|
end
|
||||||
|
self.sink:write '\r'
|
||||||
self:render()
|
self:render()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,7 +96,7 @@ function Greenhouse:scroll(direction)
|
||||||
|
|
||||||
local oldOffset = self.offset
|
local oldOffset = self.offset
|
||||||
if direction == 'down' then
|
if direction == 'down' then
|
||||||
self.offset = math.min(self.offset + 1, math.max(1, #lines - self.region.height))
|
self.offset = math.min(self.offset + 1, math.max(1, #lines - self.region.height + 1))
|
||||||
elseif direction == 'up' then
|
elseif direction == 'up' then
|
||||||
self.offset = math.max(self.offset - 1, 1)
|
self.offset = math.max(self.offset - 1, 1)
|
||||||
end
|
end
|
||||||
|
@ -132,9 +128,6 @@ end
|
||||||
function Greenhouse:updateSpecial()
|
function Greenhouse:updateSpecial()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Greenhouse:contents()
|
|
||||||
end
|
|
||||||
|
|
||||||
function Greenhouse:toc(toggle)
|
function Greenhouse:toc(toggle)
|
||||||
if not self.isSpecial then
|
if not self.isSpecial then
|
||||||
self.specialPageIdx = self.curPage
|
self.specialPageIdx = self.curPage
|
||||||
|
@ -147,17 +140,6 @@ function Greenhouse:toc(toggle)
|
||||||
]], lunacolors.cyan(lunacolors.bold '―― Table of Contents ――'))
|
]], lunacolors.cyan(lunacolors.bold '―― Table of Contents ――'))
|
||||||
|
|
||||||
local genericPageCount = 1
|
local genericPageCount = 1
|
||||||
local contents = self:contents()
|
|
||||||
if contents then
|
|
||||||
for i, c in ipairs(contents) do
|
|
||||||
local title = c.title
|
|
||||||
if c.active then
|
|
||||||
title = lunacolors.invert(title)
|
|
||||||
end
|
|
||||||
|
|
||||||
tocText = tocText .. title .. '\n'
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i, page in ipairs(self.pages) do
|
for i, page in ipairs(self.pages) do
|
||||||
local title = page.title
|
local title = page.title
|
||||||
if title == 'Page' then
|
if title == 'Page' then
|
||||||
|
@ -170,7 +152,6 @@ function Greenhouse:toc(toggle)
|
||||||
|
|
||||||
tocText = tocText .. title .. '\n'
|
tocText = tocText .. title .. '\n'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
self.specialPage = Page('TOC', tocText)
|
self.specialPage = Page('TOC', tocText)
|
||||||
function self:updateSpecial()
|
function self:updateSpecial()
|
||||||
self:toc()
|
self:toc()
|
||||||
|
|
Loading…
Reference in New Issue