Files
HyperionOS/Src/Hyperion-kernel/lib/modules/Hyperion/50_tty.kmod
2026-01-29 20:29:06 -05:00

129 lines
3.0 KiB
Plaintext

--:Minify:--
local kernel=...
local tty={}
kernel.tty=tty
tty.inst={}
function tty.register(ttyn, ttyo)
tty.inst[ttyn]=ttyo
end
function tty.print(text)
local term=kernel.currentTask.term
if term and tty.inst[term] then
tty.inst[term].print(text)
end
end
function tty.printInline(text)
local term=kernel.currentTask.term
if term and tty.inst[term] then
tty.inst[term].printInline(text)
end
end
function tty.size()
local term=kernel.currentTask.term
if term and tty.inst[term] then
return tty.inst[term].size()
end
end
function tty.setCursorPos(x,y)
local term=kernel.currentTask.term
if term and tty.inst[term] then
return tty.inst[term].setCursorPos(x,y)
end
end
function tty.getCursorPos()
local term=kernel.currentTask.term
if term and tty.inst[term] then
return tty.inst[term].getCursorPos()
end
end
function tty.clear()
local term=kernel.currentTask.term
if term and tty.inst[term] then
return tty.inst[term].clear()
end
end
function tty.setTextColor(color)
local term=kernel.currentTask.term
if term and tty.inst[term] then
return tty.inst[term].setTextColor(color)
end
end
function tty.setBackgroundColor(color)
local term=kernel.currentTask.term
if term and tty.inst[term] then
return tty.inst[term].setBackgroundColor(color)
end
end
function tty.scroll(n)
local term=kernel.currentTask.term
if term and tty.inst[term] then
return tty.inst[term].scroll(n)
end
end
function tty.getTextColor()
local term=kernel.currentTask.term
if term and tty.inst[term] and tty.inst[term].getTextColor then
return tty.inst[term].getTextColor()
end
end
function tty.getBackgroundColor()
local term=kernel.currentTask.term
if term and tty.inst[term] and tty.inst[term].getBackgroundColor then
return tty.inst[term].getBackgroundColor()
end
end
function tty.bind(ttyid)
if not ttyid then
return false, "No TTY ID specified"
end
if not kernel.tty.inst[ttyid] then
return false, "TTY "..tostring(ttyid).." not registered"
end
kernel.currentTask.term=ttyid
return true
end
function tty.unbind()
kernel.currentTask.term=false
end
function tty.isBound()
return kernel.currentTask.term ~= nil
end
function tty.getBoundTTY()
return kernel.currentTask.term
end
local sys=kernel.syscalls
sys["TTY_print"]=tty.print
sys["TTY_printInline"]=tty.printInline
sys["TTY_size"]=tty.size
sys["TTY_setCursorPos"]=tty.setCursorPos
sys["TTY_getCursorPos"]=tty.getCursorPos
sys["TTY_clear"]=tty.clear
sys["TTY_setTextColor"]=tty.setTextColor
sys["TTY_setBackgroundColor"]=tty.setBackgroundColor
sys["TTY_scroll"]=tty.scroll
sys["TTY_getTextColor"]=tty.getTextColor
sys["TTY_getBackgroundColor"]=tty.getBackgroundColor
sys["TTY_bind"]=tty.bind
sys["TTY_unbind"]=tty.unbind
sys["TTY_isBound"]=tty.isBound
sys["TTY_getBoundTTY"]=tty.getBoundTTY
kernel.log("TTY module loaded attempting to register console tty")
kernel.status="init"