Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function writepos(x,y,text)
- term.setCursorPos(x,y)
- write(text)
- end
- local function writecol(x,y,text,bg,fg)
- term.setBackgroundColor(bg)
- term.setTextColor(fg)
- writepos(x,y,text)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- local function multchar(char,n)
- local text = ""
- for i=1, n do
- text = text..char
- end
- return text
- end
- local function max(a,b)
- return a>b and a or b -- weirdest ternary syntax ever
- end
- local function min(a,b)
- return a>b and b or a
- end
- local function compare_coord(a,b)
- return a[1] == b[1] and a[2] == b[2]
- end
- local function fill_color(x1,y1,x2,y2,clr)
- paintutils.drawLine(x1,y1,x2,y2,clr)
- term.setBackgroundColor(colors.black)
- end
- local function render_folder(folder,shift)
- local contents = fs.list(folder)
- local w,h = term.getSize()
- --shift = #contents>h and shift or 1
- if shift+h-3>#contents then shift = max(#contents-h+3,1) end
- fill_color(1,1,w,1,colors.gray)
- if w>30 then
- writecol(1,1,"Contents of "..(folder == "" and "root" or folder).." ("..#contents.." objects)",colors.gray,colors.white)
- else
- writecol(1,1,(folder == "" and "root" or folder).." ("..#contents.." obj.)",colors.gray,colors.white)
- end
- for i=shift,min(#contents,h+shift-1) do
- --paintutils.drawLine(1,i-shift+2,w-1,i-shift+2,colors.black) -- failed attempt at optimisation
- local index = multchar("0",math.floor(math.log10(#contents))-math.floor(math.log10(i)))..i..". "
- local clear_noise = multchar(" ",max(#contents[i>1 and i-1 or 1],#contents[i<#contents and i+1 or 1]))
- writecol(1,i-shift+2,index..contents[i]..clear_noise,colors.black,fs.isDir(fs.combine(folder,contents[i])) and colors.lightBlue or colors.white)
- end
- fill_color(w,1,w,h,colors.blue)
- fill_color(1,h,w,h,colors.red)
- writecol(w,1,"^",colors.blue,colors.white)
- writecol(w,2,"-",colors.blue,colors.white)
- writecol(w,math.floor(h/2),"\a",colors.blue,colors.white)
- writecol(w,math.floor(h/2)-1,"/",colors.blue,colors.white)
- writecol(w,h-1,"-",colors.blue,colors.white)
- writecol(w,h,"v",colors.blue,colors.white)
- render_time()
- writecol(1,h,"$",colors.red,colors.white)
- writecol(w,h-2,"+",colors.blue,colors.white)
- --writecol(w-10,h,shift,colors.red,colors.white)
- if term.isColour() then writecol(w,3,">",colors.blue,colors.white) end
- end
- local function render_popup(lines,title,cross)
- local w,h = term.getSize()
- local start_y = math.floor((h-lines-2)/2)
- local start_x = math.floor(w/4)
- local end_y = math.floor((h+lines+2)/2)
- local end_x = w-math.floor(w/4)
- paintutils.drawBox(start_x,start_y,end_x,end_y,colors.gray)
- term.setCursorPos(w/2-#title/2,start_y)
- write(title)
- term.setBackgroundColor(colors.black)
- paintutils.drawFilledBox(start_x+1,start_y+1,end_x-1,end_y-1)
- if cross then writecol(end_x,start_y,"x",colors.red,colors.white) end
- return start_x+1,start_y+1
- end
- local function render_time()
- local w,h = term.getSize()
- paintutils.drawLine(w-6,h,w-1,h,colors.red)
- writecol(w-6,h,textutils.formatTime(os.time("local"),true),colors.red,colors.white)
- os.startTimer(60 - os.date("%S"))
- end
- return {writepos, writecol, multchar, max, min, compare_coord, fill_color, render_folder, render_popup, render_time}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement