This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
FREAX/boot/freax/kerneldraw.boot
2022-07-18 19:33:40 +02:00

286 lines
7.1 KiB
Clojure

termw,termh = term.getSize()
function clearScreen(color)
term.setBackgroundColor(color or colors.black)
term.setCursorPos(1,1)
term.clear()
end
function button(text, x1, x2, y)
term.setCursorPos(x1, y)
print(text)
local a, b, xx, yy = os.pullEvent("mouse_click")
if (xx >= x1 and xx <= x2 and yy == y) then
return true
else
return false
end
end
function counter(text, y)
for i=1,100 do
sleep(0.1)
term.setCursorPos(1, y)
print(text.." ["..tostring(i).."%]")
end
end
function drawProgress(txt, y)
term.setCursorPos(4, 4)
print(txt)
term.setCursorPos(1, y)
print("[ ]")
term.setCursorPos(2, y)
textutils.slowPrint("==============================]", 10)
end
function drawProgressAlt(color)
term.setCursorPos(4, 10)
print("#-------------------------------------------#")
term.setCursorPos(4, 11)
print("| |")
term.setCursorPos(4, 12)
print("#-------------------------------------------#")
term.setBackgroundColor(color or colors.yellow)
term.setCursorPos(5, 11)
textutils.slowWrite(" ", 10)
term.setBackgroundColor(colors.black)
end
function printColoredTextLine(y, txt, centered,bg, fg)
term.setCursorPos(1, y)
term.setBackgroundColor(bg or colors.lightGray)
term.write(" ")
if centered then
term.setCursorPos(termw/2-(string.len(txt)/2-1),y)
else
term.setCursorPos(1, y)
end
term.setTextColor(fg or colors.black)
print(txt)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
end
function printColoredProgressTextLine(y, txt, progress, bgn, fgn, bgp, fgp)
if progress >= 101 then
kernel.panic("progress can't be over 100 (printColoredProgressTextLine in kerneldraw)")
return
end
local progress_max = termw
local progress_cur
if progress >= 2 then
if progress_max == 51 then
progress_cur = kernel.numRound(progress/1.96078431357)
else
kernel.panic("monitor has a invalid width that hasn't been programmed in (printColoredProgressTextLine in kerneldraw)")
return
end
else
progress_cur = progress
end
local txt_progress = nil
local txt_normal = nil
local progresstxt_tmp = nil
if progress_cur >= 1 then
if progress_cur >= string.len(txt)+1 then
txt_progress = txt
progresstxttmp = progress_cur-string.len(txt)
repeat
txt_progress = txt_progress .. " "
until progresstxttmp <= 0
else
txt_progress = string.sub(txt,1,progress_cur)
txt_normal = string.sub(txt,progress_cur,string.len(txt))
end
else
txt_progress = ""
txt_normal = txt
end
term.setCursorPos(1,1)
term.setBackgroundColor(colors.gray)
term.setTextColor(colors.white)
print("progress:" .. progress)
print("progress_max:" .. progress_max)
print("progress_cur:" .. progress_cur)
print("txt_progress:" .. txt_progress)
print("txt_normal:" .. txt_normal)
term.setCursorPos(1, y)
term.setBackgroundColor(bgn or colors.purple)
term.write(" ")
term.setCursorPos(1, y)
term.setTextColor(fgp or colors.black)
term.setBackgroundColor(bgp or colors.white)
print(txt_progress)
if not txt_progress == "" then
term.setCursorPos(string.len(txt_progress)+1,y)
end
term.setTextColor(fgn or colors.white)
term.setBackgroundColor(bgn or colors.purple)
print(txt_normal)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
end
function printBootInfo(i)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.lightGray)
write("")
term.setTextColor(colors.cyan)
write("*")
term.setTextColor(colors.lightGray)
write(" ")
print(" "..i)
term.setTextColor(colors.white)
if log then
log.writeBootLog(i)
end
end
function printBootWarning(w)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.lightGray)
write("")
term.setTextColor(colors.orange)
write("!")
term.setTextColor(colors.lightGray)
write(" ")
print(" "..w)
term.setTextColor(colors.white)
if log then
log.writeBootLog(w)
end
end
function printBootSuccess(wa)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.lightGray)
write("")
term.setTextColor(colors.lime)
write("v")
term.setTextColor(colors.lightGray)
write(" ")
print(" "..wa)
term.setTextColor(colors.white)
if log then
log.writeBootLog(wa)
end
end
function printAppInfo(header, msg)
term.setTextColor(colors.cyan)
write(header..": ")
term.setTextColor(colors.lightGray)
print(msg)
term.setTextColor(colors.white)
end
function printAppWarning(header, msg)
term.setTextColor(colors.red)
write(header..": ")
term.setTextColor(colors.orange)
print(msg)
term.setTextColor(colors.white)
end
function printAppSuccess(header, msg)
term.setTextColor(colors.lime)
write(header..": ")
term.setTextColor(colors.green)
print(msg)
term.setTextColor(colors.white)
end
function printKernelMessage(msg)
if kernel.printLog then
term.setTextColor(colors.blue)
write("freax: ")
term.setTextColor(colors.lightBlue)
print(msg)
term.setTextColor(colors.white)
end
end
function printKernelAsking(msg)
if kernel.printLog then
term.setTextColor(colors.blue)
write("freax: ")
term.setTextColor(colors.lightBlue)
write(msg)
term.setTextColor(colors.white)
end
end
function request(req)
while true do
term.setTextColor(colors.cyan)
write(req .. "? ")
term.setTextColor(colors.lightGray)
write("(")
term.setTextColor(colors.lime)
write("Y")
term.setTextColor(colors.lightGray)
write("/")
term.setTextColor(colors.red)
write("N")
term.setTextColor(colors.lightGray)
write(") ")
local presel=read()
if presel=="Y" or presel=="y" then
return true
elseif presel=="N" or presel=="n" then
return false
end
end
end
function drawImg(path, x, y)
if fs.exists(path) and not fs.isDir(path) then
local img = paintutils.loadImage(path)
paintutils.drawImage(img, x, y)
else
printAppWarning("gui", "Image not found")
end
end
function drawImgArg(img, x, y)
paintutils.drawImage(img, x, y)
end
function printColored(text, color)
local tmp = term.getTextColor()
term.setTextColor(color)
print(text)
term.setTextColor(tmp)
end
function bootScreen(enable,progress,logo,logo_small,txt)
if enable then
clearScreen(colors.black)
local check_size = termw
local logo_size = 38
local logo_small_size = 20
if check_size == logo_size then
drawImgArg(logo, 1,5)
elseif check_size >= logo_size then
drawImgArg(logo, (termw/2)-(logo_size/2)+1, 5)
elseif check_size == logo_small_size then
drawImgArg(logo_small, 1,5)
elseif check_size >= logo_small_size then
drawImgArg(logo_small, (termw/2)-(logo_small_size/2)+1, 5)
end
printColoredTextLine(termh-1, txt, true, colors.black, colors.white)
--printColoredProgressTextLine(termh-1, txt, progress, colors.black, colors.white, colors.purple, colors.white)
--printColoredProgressTextLine(termh-1, txt, progress)
end
end
function bootDelay(delay)
local enableSleeps = true -- Disabled sleeps
local enableDisabledSleep = false -- Disables 0.1 sleep when disabled
if enableSleeps then
sleep(delay)
elseif enableDisabledSleep then
sleep(0.1)
end
end