Compare commits

..

1 Commits

Author SHA1 Message Date
sammyette ee65a4f84b
Merge f3eac9f1c3 into a0513c0a05 2023-12-18 02:21:30 +00:00
2 changed files with 10 additions and 39 deletions

View File

@ -4,7 +4,6 @@ local fs = require 'fs'
local lunacolors = require 'lunacolors' local lunacolors = require 'lunacolors'
local Greenhouse = require 'nature.greenhouse' local Greenhouse = require 'nature.greenhouse'
local Page = require 'nature.greenhouse.page' local Page = require 'nature.greenhouse.page'
local docfuncs = require 'nature.doc'
commander.register('doc', function(args, sinks) commander.register('doc', function(args, sinks)
local moddocPath = hilbish.dataDir .. '/docs/' local moddocPath = hilbish.dataDir .. '/docs/'
@ -90,7 +89,7 @@ Available sections: ]] .. table.concat(modules, ', ')
local size = terminal.size() local size = terminal.size()
self.region = { self.region = {
width = size.width, width = size.width,
height = size.height - 1 height = size.height - 2
} }
end end
gh:resize() gh:resize()
@ -102,13 +101,12 @@ Available sections: ]] .. table.concat(modules, ', ')
offset = self.specialOffset offset = self.specialOffset
workingPage = self.specialPage workingPage = self.specialPage
end end
local size = terminal.size()
self.sink:write(ansikit.getCSI(size.height - 1 .. ';1', 'H')) self.sink:write(ansikit.getCSI(self.region.height + 1 .. ';1', 'H'))
self.sink:write(ansikit.getCSI(0, 'J')) self.sink:write(ansikit.getCSI(0, 'J'))
if not self.isSpecial then if not self.isSpecial then
if args[1] == 'api' then if args[1] == 'api' then
self.sink:writeln(workingPage.title) self.sink:writeln(lunacolors.reset(string.format('%s', workingPage.title)))
self.sink:write(lunacolors.format(string.format('{grayBg} ↳ {white}{italic}%s {reset}', workingPage.description or 'No description.'))) self.sink:write(lunacolors.format(string.format('{grayBg} ↳ {white}{italic}%s {reset}', workingPage.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)))
@ -117,17 +115,17 @@ Available sections: ]] .. table.concat(modules, ', ')
end end
local backtickOccurence = 0 local backtickOccurence = 0
local function formatDocText(d) local function formatDocText(d)
return d:gsub('```(%w+)\n(.-)```', function(lang, text) return lunacolors.format(d:gsub('`', function()
return docfuncs.renderCodeBlock(text) backtickOccurence = backtickOccurence + 1
end) if backtickOccurence % 2 == 0 then
--[[ return '{reset}'
return lunacolors.format(d:gsub('`(.-)`', function(t) else
return docfuncs.renderCodeBlock(t) return '{underline}{green}'
end
end):gsub('\n#+.-\n', function(t) end):gsub('\n#+.-\n', function(t)
local signature = t:gsub('<.->(.-)</.->', '{underline}%1'):gsub('\\', '<') local signature = t:gsub('<.->(.-)</.->', '{underline}%1'):gsub('\\', '<')
return '{bold}{yellow}' .. signature .. '{reset}' return '{bold}{yellow}' .. signature .. '{reset}'
end)) end))
]]--
end end

View File

@ -1,27 +0,0 @@
local lunacolors = require 'lunacolors'
local M = {}
function M.highlight(text)
return text:gsub('\'.-\'', lunacolors.yellow)
--:gsub('%-%- .-', lunacolors.black)
end
function M.renderCodeBlock(text)
local longest = 0
local lines = string.split(text:gsub('\t', ' '), '\n')
for i, line in ipairs(lines) do
local len = line:len()
if len > longest then longest = len end
end
for i, line in ipairs(lines) do
lines[i] = M.highlight(line:sub(0, longest))
.. string.rep(' ', longest - line:len())
end
return '\n' .. lunacolors.format('{greyBg}' .. table.concat(lines, '\n')) .. '\n'
end
return M