feat: almost completely finish ansikit

pull/24/head
TorchedSammy 2021-04-06 09:40:50 -04:00
parent 0f01d077a4
commit b266c31bb8
1 changed files with 52 additions and 11 deletions

View File

@ -61,17 +61,6 @@ ansikit.cursorUp = function(y)
return ansikit.printCSI(y, 'A') return ansikit.printCSI(y, 'A')
end end
ansikit.getCode = function(code, terminate)
endc = (endc and endc or 'm')
return string.char(0x001b) .. code ..
(terminate and string.char(0x001b) .. '\\' or '')
end
ansikit.getCSI = function(code, endc)
endc = (endc and endc or 'm')
return string.char(0x001b) .. '[' .. code .. endc
end
ansikit.format = function(text) ansikit.format = function(text)
local colors = { local colors = {
-- TODO: write codes manually instead of using functions -- TODO: write codes manually instead of using functions
@ -115,6 +104,22 @@ ansikit.format = function(text)
return text return text
end end
ansikit.getCode = function(code, terminate)
return string.char 0x001b .. code ..
(terminate and string.char 0x001b .. '\\' or '')
end
ansikit.getCSI = function(code, endc)
endc = (endc and endc or 'm')
code = (code and code or '')
return string.char 0x001b .. '[' .. code .. endc
end
ansikit.hideCursor = function()
return ansikit.printCSI('?25', 'l')
end
ansikit.print = function(text) ansikit.print = function(text)
io.write(ansikit.format(text)) io.write(ansikit.format(text))
return ansikit return ansikit
@ -135,5 +140,41 @@ ansikit.println = function(text)
return ansikit return ansikit
end end
ansikit.reset = function()
return ansikit.printCode 'c'
end
ansikit.restoreCursor = function()
return ansikit.printCSI(nil, 'u')
end
ansikit.restoreState = function()
return ansikit.printCode 8
end
ansikit.rgb = function(r, g, b)
r = (r and r or 0)
g = (g and g or 0)
b = (b and b or 0)
return ansikit.printCSI '38;2;' .. r .. ';' .. g .. ';' .. b
end
ansikit.saveCursor = function()
return ansikit.printCSI(nil, 's')
end
ansikit.saveState = function()
return ansikit.printCode 7
end
ansikit.setTitle = function(text)
ansikit.printCode (']2;' .. text, true)
end
ansikit.showCursor = function()
return ansikit.printCSI('?25', 'h')
end
return ansikit return ansikit