mirror of https://github.com/Hilbis/Hilbish
feat: make doc command use pager
parent
d196799abf
commit
076118d237
|
@ -1,6 +1,8 @@
|
|||
local commander = require 'commander'
|
||||
local fs = require 'fs'
|
||||
local lunacolors = require 'lunacolors'
|
||||
local Greenhouse = require 'nature.greenhouse'
|
||||
local Page = require 'nature.greenhouse.page'
|
||||
|
||||
commander.register('doc', function(args, sinks)
|
||||
local moddocPath = hilbish.dataDir .. '/docs/'
|
||||
|
@ -85,8 +87,9 @@ Available sections: ]] .. table.concat(modules, ', ')
|
|||
f:close()
|
||||
end
|
||||
|
||||
local gh = Greenhouse(sinks.out)
|
||||
local backtickOccurence = 0
|
||||
sinks.out:writeln(lunacolors.format(doc:gsub('`', function()
|
||||
local page = Page(lunacolors.format(doc:gsub('`', function()
|
||||
backtickOccurence = backtickOccurence + 1
|
||||
if backtickOccurence % 2 == 0 then
|
||||
return '{reset}'
|
||||
|
@ -97,4 +100,6 @@ Available sections: ]] .. table.concat(modules, ', ')
|
|||
local signature = t:gsub('<.->(.-)</.->', '{underline}%1'):gsub('\\', '<')
|
||||
return '{bold}{yellow}' .. signature .. '{reset}'
|
||||
end)))
|
||||
gh:addPage(page)
|
||||
gh:initUi()
|
||||
end)
|
||||
|
|
|
@ -8,7 +8,6 @@ local Page = require 'nature.greenhouse.page'
|
|||
|
||||
commander.register('greenhouse', function(args, sinks)
|
||||
local gh = Greenhouse(sinks.out)
|
||||
local done = false
|
||||
|
||||
if sinks['in'].pipe then
|
||||
local page = Page(sinks['in']:readAll())
|
||||
|
@ -25,71 +24,5 @@ commander.register('greenhouse', function(args, sinks)
|
|||
gh:addPage(page)
|
||||
end
|
||||
|
||||
bait.catch('signal.sigint', function()
|
||||
done = true
|
||||
end)
|
||||
|
||||
bait.catch('signal.resize', function()
|
||||
gh:update()
|
||||
end)
|
||||
|
||||
ansikit.screenAlt()
|
||||
ansikit.clear(true)
|
||||
gh:draw()
|
||||
|
||||
hilbish.goro(function()
|
||||
while not done do
|
||||
local c = read()
|
||||
if c == 3 then
|
||||
done = true
|
||||
end
|
||||
|
||||
if c == 27 then
|
||||
local c1 = read()
|
||||
if c1 == 91 then
|
||||
local c2 = read()
|
||||
if c2 == 66 then -- arrow down
|
||||
gh:scroll 'down'
|
||||
elseif c2 == 65 then -- arrow up
|
||||
gh:scroll 'up'
|
||||
end
|
||||
|
||||
if c2 == 49 then
|
||||
local c3 = read()
|
||||
if c3 == 59 then
|
||||
local c4 = read()
|
||||
if c4 == 53 then
|
||||
local c5 = read()
|
||||
if c5 == 67 then
|
||||
gh:next()
|
||||
elseif c5 == 68 then
|
||||
gh:previous()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
goto continue
|
||||
end
|
||||
print('\nchar:')
|
||||
print(c)
|
||||
|
||||
::continue::
|
||||
end
|
||||
end)
|
||||
|
||||
while not done do
|
||||
--
|
||||
end
|
||||
ansikit.clear()
|
||||
ansikit.screenMain()
|
||||
gh:initUi()
|
||||
end)
|
||||
|
||||
function read()
|
||||
terminal.saveState()
|
||||
terminal.setRaw()
|
||||
local c = io.read(1)
|
||||
|
||||
terminal.restoreState()
|
||||
return c:byte()
|
||||
end
|
||||
|
|
|
@ -44,7 +44,7 @@ function Greenhouse:draw()
|
|||
self.sink:write '\r'
|
||||
|
||||
self.sink:write(ansikit.getCSI(self.region.height - self.start.. ';1', 'H'))
|
||||
self.sink:writeln(string.format('Page %d', self.curPage))
|
||||
self.sink:writeln(string.format('\27[0mPage %d', self.curPage))
|
||||
end
|
||||
|
||||
function Greenhouse:scroll(direction)
|
||||
|
@ -85,4 +85,82 @@ function Greenhouse:previous()
|
|||
end
|
||||
end
|
||||
|
||||
function Greenhouse:initUi()
|
||||
local ansikit = require 'ansikit'
|
||||
local bait = require 'bait'
|
||||
local commander = require 'commander'
|
||||
local hilbish = require 'hilbish'
|
||||
local terminal = require 'terminal'
|
||||
local Page = require 'nature.greenhouse.page'
|
||||
local done = false
|
||||
|
||||
bait.catch('signal.sigint', function()
|
||||
ansikit.clear()
|
||||
done = true
|
||||
end)
|
||||
|
||||
bait.catch('signal.resize', function()
|
||||
self:update()
|
||||
end)
|
||||
|
||||
ansikit.screenAlt()
|
||||
ansikit.clear(true)
|
||||
self:draw()
|
||||
|
||||
hilbish.goro(function()
|
||||
while not done do
|
||||
local c = read()
|
||||
if c == 3 then
|
||||
done = true
|
||||
end
|
||||
|
||||
if c == 27 then
|
||||
local c1 = read()
|
||||
if c1 == 91 then
|
||||
local c2 = read()
|
||||
if c2 == 66 then -- arrow down
|
||||
self:scroll 'down'
|
||||
elseif c2 == 65 then -- arrow up
|
||||
self:scroll 'up'
|
||||
end
|
||||
|
||||
if c2 == 49 then
|
||||
local c3 = read()
|
||||
if c3 == 59 then
|
||||
local c4 = read()
|
||||
if c4 == 53 then
|
||||
local c5 = read()
|
||||
if c5 == 67 then
|
||||
self:next()
|
||||
elseif c5 == 68 then
|
||||
self:previous()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
goto continue
|
||||
end
|
||||
print('\nchar:')
|
||||
print(c)
|
||||
|
||||
::continue::
|
||||
end
|
||||
end)
|
||||
|
||||
while not done do
|
||||
--
|
||||
end
|
||||
ansikit.screenMain()
|
||||
end
|
||||
|
||||
function read()
|
||||
terminal.saveState()
|
||||
terminal.setRaw()
|
||||
local c = io.read(1)
|
||||
|
||||
terminal.restoreState()
|
||||
return c:byte()
|
||||
end
|
||||
|
||||
return Greenhouse
|
||||
|
|
Loading…
Reference in New Issue