View difference between Paste ID: KYE79f0X and fAuZALuJ
SHOW: | | - or go back to the newest paste.
1
local function writepos(x,y,text)
2
    term.setCursorPos(x,y)
3
    write(text)
4
end
5
local function writecol(x,y,text,bg,fg)
6
    term.setBackgroundColor(bg)
7
    term.setTextColor(fg)
8
    writepos(x,y,text)
9
    term.setBackgroundColor(colors.black)
10
    term.setTextColor(colors.white)
11
end
12
local function multchar(char,n)
13
    local text = ""
14
    for i=1, n do
15
        text = text..char
16
    end
17
    return text
18
end
19
local function max(a,b)
20
    return a>b and a or b  -- weirdest ternary syntax ever
21
end
22
local function min(a,b)
23
    return a>b and b or a
24
end
25
local function compare_coord(a,b)
26
    return a[1] == b[1] and a[2] == b[2]
27
end
28
local function fill_color(x1,y1,x2,y2,clr)
29
    paintutils.drawLine(x1,y1,x2,y2,clr)
30
    term.setBackgroundColor(colors.black)
31
end
32
33
local function render_folder(folder,shift)
34
    local contents = fs.list(folder)
35
    local w,h = term.getSize()
36
    --shift = #contents>h and shift or 1
37
    if shift+h-3>#contents then shift = max(#contents-h+3,1) end
38
    fill_color(1,1,w,1,colors.gray)
39
    if w>30 then
40
        writecol(1,1,"Contents of "..(folder == "" and "root" or folder).." ("..#contents.." objects)",colors.gray,colors.white)
41
    else
42
        writecol(1,1,(folder == "" and "root" or folder).." ("..#contents.." obj.)",colors.gray,colors.white)
43
    end
44
    
45
    for i=shift,min(#contents,h+shift-1) do
46
        --paintutils.drawLine(1,i-shift+2,w-1,i-shift+2,colors.black) -- failed attempt at optimisation
47
        local index = multchar("0",math.floor(math.log10(#contents))-math.floor(math.log10(i)))..i..". "
48
        local clear_noise = multchar(" ",max(#contents[i>1 and i-1 or 1],#contents[i<#contents and i+1 or 1]))
49
        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)
50
    end
51
    
52
    fill_color(w,1,w,h,colors.blue)
53
    fill_color(1,h,w,h,colors.red)
54
    writecol(w,1,"^",colors.blue,colors.white)
55
    writecol(w,2,"-",colors.blue,colors.white)
56
    writecol(w,math.floor(h/2),"\a",colors.blue,colors.white)
57
    writecol(w,math.floor(h/2)-1,"/",colors.blue,colors.white)
58
    writecol(w,h-1,"-",colors.blue,colors.white)
59
    writecol(w,h,"v",colors.blue,colors.white)
60
    render_time()
61
    writecol(1,h,"$",colors.red,colors.white)
62
    writecol(w,h-2,"+",colors.blue,colors.white)
63
64
    --writecol(w-10,h,shift,colors.red,colors.white)
65
    if term.isColour() then writecol(w,3,">",colors.blue,colors.white) end
66
end
67
68
local function render_popup(lines,title,cross)
69
    local w,h = term.getSize()
70
    local start_y = math.floor((h-lines-2)/2)
71
    local start_x = math.floor(w/4)
72
    local end_y = math.floor((h+lines+2)/2)
73
    local end_x = w-math.floor(w/4)
74
    
75
    paintutils.drawBox(start_x,start_y,end_x,end_y,colors.gray)
76
    term.setCursorPos(w/2-#title/2,start_y)
77
    write(title)
78
    term.setBackgroundColor(colors.black)
79
    paintutils.drawFilledBox(start_x+1,start_y+1,end_x-1,end_y-1)
80
    if cross then writecol(end_x,start_y,"x",colors.red,colors.white) end
81
    
82
    return start_x+1,start_y+1
83
end
84
local function render_time()
85
	local w,h = term.getSize()
86
	paintutils.drawLine(w-6,h,w-1,h,colors.red)
87
	writecol(w-6,h,textutils.formatTime(os.time("local"),true),colors.red,colors.white)
88
	os.startTimer(60 - os.date("%S"))
89
end
90
91
return {writepos, writecol, multchar, max, min, compare_coord, fill_color, render_folder, render_popup, render_time}