View difference between Paste ID: mga8qSsW and j0X75ECG
SHOW: | | - or go back to the newest paste.
1
local isUsing = true
2
local maxX, maxY = term.getSize()
3
local color1 = colors.lime
4
local color2 = colors.white
5
if fs.exists("/.todocfg") then
6
  local opfile = fs.open("/.todocfg", "r")
7
  color1 = tonumber(opfile.readLine())
8
  color2 = tonumber(opfile.readLine())
9
  opfile.close()
10
end
11
12
local colnames = {[0] = "White",
13
                [1] = "Orange",
14
                [2] = "Magenta",
15
                [3] = "Light Blue",
16
                [4] = "Yellow",
17
                [5] = "Lime",
18
                [6] = "Pink",
19
                [7] = "Gray",
20
                [8] = "Light Gray",
21
                [9] = "Cyan",
22
                [10] = "Purple",
23
                [11] = "Blue",
24
                [12] = "Brown",
25
                [13] = "Green",
26
                [14] = "Red",
27
                [15] = "Black"}
28
               
29
local numconv = {[0] = colors.white,
30
                [1] = colors.orange,
31
                [2] = colors.magenta,
32
                [3] = colors.lightBlue,
33
                [4] = colors.yellow,
34
                [5] = colors.lime,
35
                [6] = colors.pink,
36
                [7] = colors.gray,
37
                [8] = colors.lightGray,
38
                [9] = colors.cyan,
39
                [10] = colors.purple,
40
                [11] = colors.blue,
41
                [12] = colors.brown,
42
                [13] = colors.green,
43
                [14] = colors.red,
44
                [15] = colors.black}
45
46
--Maybe need to rewrite this :P
47
local choice = 0
48
local choice2 = 0
49
while numconv[choice] ~= color1 do
50
    choice=choice+1
51
end 
52
while numconv[choice2] ~= color2 do
53
    choice2=choice2+1
54
end
55
local taskFile = "/.tasks"
56
local page = 1
57
local Options = false
58
59
local function getTasks()
60
 if not fs.exists(taskFile) then
61
  local A = fs.open(taskFile, "w")
62
  A.write("{}")
63
  A.close()
64
  return {}
65
 else
66
  local A = fs.open(taskFile, "r")
67
  local tmp = textutils.unserialize(A.readAll())
68
  A.close()
69
  return tmp
70
 end
71
end
72
73
local function redraw(page)
74
 if isUsing and not Options then
75
    local tasks = getTasks()
76
    local nMaxY = maxY - 2
77
 
78
    term.clear()
79
    term.setCursorPos(1,1)
80
    term.setBackgroundColour(color1)
81
    if color1 ~= color2 and color1 ~= colors.white then
82
        term.setTextColour(color2)
83
    elseif color1 == color2 and color1 ~= colors.white then
84
        term.setTextColor(colors.white)
85
    else
86
        term.setTextColor(colors.black)
87
    end
88
    term.clearLine()
89
    print(" + / -  |")
90
    term.setCursorPos(maxX-12,1)
91
    print("Options  Exit")
92
    
93
    for i=1, nMaxY do
94
        if i%2 == 1 and color1 ~= color2 then
95
            term.setBackgroundColour(color2)
96
            term.setTextColour(color1)
97
        elseif color1 ~= color2 then
98
            term.setBackgroundColour(color1)
99
            term.setTextColour(color2)
100
        elseif color1 == colors.white then
101
            term.setBackgroundColor(color1)
102
            term.setTextColor(colors.black)
103
        else
104
            term.setBackgroundColor(color1)
105
            term.setTextColor(colors.black)
106
        end
107
  
108
        term.setCursorPos(1,1+i)
109
        term.clearLine()
110
  
111
        local num = i+(nMaxY*(page-1))
112
  
113
        if tasks[num] ~= nil then
114
            write(num..": "..tasks[num])
115
        else
116
            write(num..": ")
117
        end
118
    end
119
 
120
 if maxY%2 == 0 and color1 ~= color2 then
121
  term.setBackgroundColour(color2)
122
  term.setTextColour(color1)
123
 elseif color1 ~= color2 then
124
  term.setBackgroundColour(color1)
125
  term.setTextColour(color2)
126
 elseif color1 == colors.white then
127
    term.setBackgroundColor(color1)
128
    term.setTextColor(colors.black)
129
 else
130
    term.setBackgroundColor(color1)
131
    term.setTextColor(colors.white)
132
 end 
133
term.setCursorPos(2,maxY)
134
 term.clearLine()
135
 write("<")
136
 term.setCursorPos((maxX/2-#tostring(page)/2)+1,maxY)
137
 write(page)
138
 term.setCursorPos(maxX-1,maxY)
139
 write(">")
140
 elseif not isUsing and not Options then --Exited program
141
    term.setBackgroundColor(colors.black)
142
    term.setTextColor(colors.white)
143
    term.clear()
144
    term.setCursorPos(1,1)
145
    print("Goodbye !")
146
 elseif isUsing and Options then
147
    term.setBackgroundColor(colors.gray)
148
    if color1 ~= colors.white then
149
        term.setTextColor(colors.white)
150
    else
151
        term.setTextColor(colors.black)
152
    end
153
    term.clear()
154
    color1 = numconv[choice]
155
    color2 = numconv[choice2]
156
    term.setCursorPos(1,1)
157
    term.setBackgroundColor(color1)
158
    term.clearLine()
159
    term.setCursorPos(maxX-(maxX-2),1)
160
    print("Options")
161
    term.setCursorPos(math.ceil(maxX/2)+1,1)
162
    print("|")
163
    term.setCursorPos(maxX-6,1)
164
    print("Return")
165
    term.setBackgroundColor(colors.gray)
166
    term.setTextColor(colors.white)
167
    term.setCursorPos(15,3)
168
    print("<->")
169
    paintutils.drawLine(14,4,14+string.len(colnames[choice]),4,numconv[choice])
170
    term.setCursorPos(3,4)
171
    if color1 ~= colors.white then
172
        term.setTextColor(colors.white)
173
    else
174
        term.setTextColor(colors.black)
175
    end
176
    print("1st color : " .. colnames[choice])
177
    term.setBackgroundColor(colors.gray)
178
    paintutils.drawLine(14,6,14+string.len(colnames[choice2]),6,numconv[choice2])
179
    if color2 ~= colors.white then
180
        term.setTextColor(colors.white)
181
    else
182
        term.setTextColor(colors.black)
183
    end
184
    term.setCursorPos(3,6)
185
    print("2nd color : " .. colnames[choice2])
186
    term.setBackgroundColor(colors.gray)
187
    term.setTextColor(colors.white)
188
    term.setCursorPos(15,7)
189
    print("<->")
190
    term.setCursorPos(5,10)
191
    print("About this program")
192
    term.setCursorPos(4,12)
193
    print("HD's Todo list V1.5")
194
    term.setCursorPos(1,14)
195
    print("-masterdisasterHD : Orignal program and idea")
196
    term.setCursorPos(1,17)
197
    print("-s0r00t : V1.5 enhancements")
198
    
199
 end
200
end
201
202
local function saveTasks(tbl)
203
 local A = fs.open(taskFile, "w")
204
 A.write(textutils.serialize(tbl))
205
 A.close()
206
end
207
208
local function addTask()
209
 local tasks = getTasks()
210
 term.setBackgroundColour(colors.black)
211
 term.setTextColour(colors.white)
212
 term.clear()
213
 term.setCursorPos(1,1)
214
 term.setCursorBlink(true)
215
 write("Task: ")
216
 local tsk = read()
217
 table.insert(tasks, tsk)
218
 saveTasks(tasks)
219
end
220
221
local function delTask()
222
 local tasks = getTasks()
223
 term.setBackgroundColour(colors.black)
224
 term.setTextColour(colors.white)
225
 term.clear()
226
 term.setCursorPos(1,1)
227
 write("Task number: ")
228
 local tsknmbr = tonumber(read())
229
 table.remove(tasks, tsknmbr)
230
 saveTasks(tasks)
231
end
232
233
local function showTask(pg, pos, h, w)
234
 local tasks = getTasks()
235
 local step1 = (h-2)*(pg-1)
236
 local step2 = (pos-1)+step1
237
 term.setBackgroundColour(color2)
238
 term.setTextColour(color1)
239
 term.clear()
240
 term.setCursorPos(1,1)
241
 if tasks[step2] ~= nil then
242
  write("Task #"..step2..":")
243
  local text = tasks[step2]
244
  local k = 1
245
  for i=1, h-1 do
246
   term.setCursorPos(1,i+1)
247
   for j=1,w do
248
    write(string.sub(text, k, k))
249
    k = k + 1
250
   end
251
  end
252
 term.setCursorPos(1,h)
253
 write("Press any key to continue")
254
 os.pullEvent("key")
255
 end
256
end
257
258
--Program loop
259
redraw(page)
260
local maxX, maxY = term.getSize()
261
while isUsing do
262
 sleep(0)
263
 ev, b, xPos, yPos = os.pullEvent()
264
 if ev == "mouse_click" then
265
  if xPos == 2 and yPos == 1 and not Options then
266
   addTask()
267
  elseif xPos == 6 and yPos == 1 and not Options then
268
   delTask()
269
  elseif xPos >= maxX-12 and xPos <= maxX-4 and yPos == 1 and not Options then
270
  Options = true
271
  elseif xPos >=maxX-3 and xPos <= maxX and yPos == 1 and not Options then
272
  isUsing = false
273
  elseif xPos == 2 and yPos == maxY and not Options then
274
   if page > 1 then
275
    page = page - 1
276
   end
277
  elseif xPos == maxX-1 and yPos == maxY and not Options then
278
   page = page + 1
279
  elseif xPos > 1 and yPos < maxY and not Options then
280
   showTask(page, yPos, maxY, maxX)
281
  elseif xPos >= maxX-6 and xPos <= maxX-1 and yPos == 1 and Options then
282
   Options = false
283
   local opfile = fs.open("/.todocfg", "w")
284
   opfile.writeLine(color1)
285
   opfile.write(color2)
286
   opfile.close()
287
  elseif xPos == 15 and yPos == 3 and Options then
288
    if choice-1 ~= -1 then
289
        choice = choice-1
290
    else
291
        choice = 15
292
    end
293
    redraw(page)
294
  elseif xPos == 17 and yPos == 3 and Options then
295
    if choice+1 ~= 16 then
296
        choice = choice+1
297
    else
298
        choice = 0
299
    end
300
    redraw(page)
301
  elseif xPos == 15 and yPos == 7 and Options then
302
    if choice2-1 ~= -1 then
303
        choice2 = choice2-1
304
    else
305
        choice2 = 15
306
    end
307
    redraw(page)
308
  elseif xPos == 17 and yPos == 7 and Options then
309
    if choice2+1 ~= 16 then
310
        choice2 = choice2+1
311
    else
312
        choice2 = 0
313
    end
314
    redraw(page)
315-
 elseif ev == "mouse_scroll" then
315+
 elseif ev == "mouse_scroll" and not Options then
316
  if b == -1 then
317
   if page > 1 then page = page - 1 end
318
  elseif b == 1 then
319
   page = page + 1
320
  end
321
 end
322
 redraw(page)
323
end
324
end