View difference between Paste ID: jNycudqz and Yg8sZceZ
SHOW: | | - or go back to the newest paste.
1-
-- FILE MANAGER (C) lego11 2020 - An ATARI GEM Product
1+
-- CLAYMORE FILE MANAGER (C) lego11 2020 - An ATARI GEM Product
2-
local basedir = "/data"
2+
basedir = "/data"
3
local register = {}
4
5
function clear()
6
    term.clear()
7
    term.setCursorPos(1, 1)
8
end
9-
function colore(colore)
9+
10-
    term.setTextColor(colore)
10+
function colore(colore) term.setTextColor(colore) end
11
function sfondo(colore) term.setBackgroundColor(colore) end
12-
function sfondo(colore)
12+
13-
    term.setBackgroundColor(colore)
13+
local function drawPixelInternal(xPos, yPos)
14
    term.setCursorPos(xPos, yPos)
15
    term.write(" ")
16
end
17
 
18
local tColourLookup = {}
19
for n = 1,16 do
20
    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2^(n-1)
21-
    if dir ~= "/" then
21+
22
23
function drawFilledBox(startX, startY, endX, endY, nColour)
24
    if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
25
        "number" or type(endY) ~= "number" or
26
        (nColour ~= nil and type(nColour) ~= "number") then
27-
        
27+
        error("Expected startX, startY, endX, endY, colour", 2)
28
    end
29-
    for key, value in ipairs(tab_f) do
29+
30-
        if fs.isDir(value) == true then
30+
    startX = math.floor(startX)
31
    startY = math.floor(startY)
32-
            sfondo(colors.yellow)
32+
    endX = math.floor(endX)
33-
            colore(colors.green)
33+
    endY = math.floor(endY)
34
35
    if nColour then term.setBackgroundColor(nColour) end
36
    if startX == endX and startY == endY then
37-
            sfondo(colors.black)
37+
        drawPixelInternal(startX, startY)
38
        return
39
    end
40-
            sfondo(colors.yellow)
40+
41-
            colore(colors.blue)
41+
    local minX = math.min(startX, endX)
42
    if minX == startX then
43
        minY = startY
44
        maxX = endX
45-
            sfondo(colors.black)
45+
        maxY = endY
46
    else
47-
        if y > 10 then
47+
        minY = endY
48-
            x = 13
48+
        maxX = startX
49-
            y = 3
49+
        maxY = startY
50
    end
51
52
    for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
53-
clear()
53+
54-
sfondo(colors.gray)
54+
55-
colore(colors.white)
55+
e_livsup = false
56-
print("Menu               FILE MANAGER                Esci")
56+
57-
lista_dir("/data/")
57+
58-
term.setCursorPos(20, 20)
58+
    e_livsup = false
59
    sfondo(colors.lightGray)
60
    clear()
61
    sfondo(colors.gray)
62
    colore(colors.white)
63
    print("                                                    ")
64
    term.setCursorPos(1, 1)
65
    term.write(dir .. " - Claymore")
66
    term.setCursorPos(49, 1)
67
    sfondo(colors.lightBlue)
68
    term.write("?")
69
    term.setCursorPos(51, 1)
70
    sfondo(colors.red)
71
    term.write("X")
72
73
74
    local tab_f = fs.list(dir)
75
    sfondo(colors.black)
76
    local x = 2
77
    local y = 3
78
    if dir ~= basedir then
79
        e_livsup = true
80
        term.setCursorPos(x, y)
81
        sfondo(colors.yellow)
82
        colore(colors.red)
83
        term.write("Liv. sup.")
84
        x = x + 17
85
    end
86
    for key, value in pairs(tab_f) do
87
        for i=x, x+#value do
88
            register[tostring(i).." "..tostring(y)] = dir .. "/" .. value
89
        end
90
        if fs.isDir(dir .. "/" .. value .. "/") == true then
91
            term.setCursorPos(x, y)
92
            sfondo(colors.lime)
93
            colore(colors.black)
94
            x = x + 17
95
            term.write(value)
96
        else
97
            term.setCursorPos(x, y)
98
            sfondo(colors.lightBlue)
99
            colore(colors.black)
100
            x = x + 17
101
            term.write(value)
102
        end
103
        if x > 45 then
104
            x = 2
105
            y = y + 2
106
        end
107
    end
108
end
109
110
local dir = basedir
111
local prevdir = basedir
112
113
while true do
114
    lista_dir(dir)
115
    local event, par1, par2, par3 = os.pullEvent()
116
    if event == "mouse_click" then
117
      if par3 == 1 and par2 == 51 then
118
        sfondo(colors.black)
119
        colore(colors.white)
120
        clear()
121
        break
122
      elseif par3 == 1 and par2 == 49 then
123
        drawFilledBox(12, 5, 39, 15, colors.white)
124
        term.setCursorPos(12, 5)
125
        sfondo(colors.gray)
126
        colore(colors.white)
127
        term.write("A proposito di Claymore    ")
128
        sfondo(colors.red)
129
        term.setCursorPos(39, 5)
130
        term.write("X")
131
        colore(colors.black)
132
        sfondo(colors.white)
133
        term.setCursorPos(13, 7)
134
        term.write("Copyright (C) 2020 lego11")
135
        term.setCursorPos(13, 8)
136
        term.write("Sole Microsistemi S.p.A.")
137
        term.setCursorPos(13, 9)
138
        term.write("Tutti i diritti riservati")
139
        colore(colors.red)
140
        term.setCursorPos(13, 10)
141
        term.write("Alba gu bràth!")
142
        colore(colors.black)
143
        term.setCursorPos(13, 12)
144
        term.write("      [")
145
        term.setCursorPos(13, 13)
146
        term.write("@====[{::::::::::::::::::>")
147
        term.setCursorPos(13, 14)
148
        term.write("      [")
149
        while true do
150
            local event, par1, par2, par3 = os.pullEvent()
151
            if event == "key" and par1 == 28 then
152
                break
153
            elseif event == "mouse_click" and par3 == 5 and par2 == 39 then
154
                break
155
            end
156
        end
157
      elseif e_livsup == true and par3 == 3 and par2 < 17 and par2 > 2 then
158
        dir = string.match(dir, "^(.*)/")
159
      else
160
        if register[tostring(par2).." "..tostring(par3)] ~= nil then
161
          if fs.isDir(dir .. "/" .. register[tostring(par2).." "..tostring(par3)]) == true then
162
            print(dir .. "/" .. register[tostring(par2).." "..tostring(par3)])
163
            sleep(0.1)
164
            dir = register[tostring(par2).." "..tostring(par3)]
165
          end
166
        end
167
      end
168
    end
169
end