View difference between Paste ID: hnkw5rQH and FbnKPcKg
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
function time_refresh()
74
      --time start
75
    redrawTimer = os.startTimer(.83)
76
      time_nospace_zero = string.gsub(textutils.formatTime(os.time(), false), " ", "")  
77
       time_nospace_10error = string.gsub(time_nospace_zero, "0:", "12:")
78
         time_nospace = string.gsub(time_nospace_10error, "112:", "10:")
79
     timeposfloat = (maxX / 2) - (#time_nospace / 2)  
80
       timepos = math.floor(timeposfloat+2.6) - 1
81
                        term.setCursorPos(timepos,1)
82
print(time_nospace)
83
    end
84
85
local function redraw(page)
86
    
87
 if isUsing and not Options then
88
    local tasks = getTasks()
89
    local nMaxY = maxY - 2
90
 
91
    term.clear()
92
    term.setCursorPos(1,1)
93
    term.setBackgroundColour(color1)
94-
                        term.setCursorPos(10,1)
94+
95-
print(textutils.formatTime(os.time(), false))
95+
96
    elseif color1 == color2 and color1 ~= colors.white then
97
        term.setTextColor(colors.white)
98
    else
99
        term.setTextColor(colors.black)
100
    end
101
    term.clearLine()
102
    print(" + / -  ")
103
    term.setCursorPos(maxX-12,1)
104
    print("     Opt Exit")
105
time_refresh()
106
--time end        
107
        
108
    for i=1, nMaxY do
109
        if i%2 == 1 and color1 ~= color2 then
110
            term.setBackgroundColour(color2)
111
            term.setTextColour(color1)
112
        elseif color1 ~= color2 then
113
            term.setBackgroundColour(color1)
114
            term.setTextColour(color2)
115
        elseif color1 == colors.white then
116
            term.setBackgroundColor(color1)
117
            term.setTextColor(colors.black)
118
        else
119
            term.setBackgroundColor(color1)
120
            term.setTextColor(colors.black)
121
        end
122
  
123
        term.setCursorPos(1,1+i)
124
        term.clearLine()
125
  
126
        local num = i+(nMaxY*(page-1))
127
  
128
        if tasks[num] ~= nil then
129
            write(num..": "..tasks[num])
130
        else
131
            write(num..": ")
132
        end
133
    end
134
 
135
 if maxY%2 == 0 and color1 ~= color2 then
136
  term.setBackgroundColour(color2)
137
  term.setTextColour(color1)
138
 elseif color1 ~= color2 then
139
  term.setBackgroundColour(color1)
140
  term.setTextColour(color2)
141
 elseif color1 == colors.white then
142
    term.setBackgroundColor(color1)
143
    term.setTextColor(colors.black)
144
 else
145
    term.setBackgroundColor(color1)
146
    term.setTextColor(colors.white)
147
 end 
148
term.setCursorPos(2,maxY)
149
 term.clearLine()
150
 write("<")
151
 term.setCursorPos((maxX/2-#tostring(page)/2)+1,maxY)
152
 write(page)
153
 term.setCursorPos(maxX-1,maxY)
154
 write(">")
155
        
156
157
        
158
 elseif not isUsing and not Options then --Exited program
159
    term.setBackgroundColor(colors.black)
160
    term.setTextColor(colors.white)
161
    term.clear()
162
    term.setCursorPos(1,1)
163
    print("Goodbye !")
164
 elseif isUsing and Options then
165
    term.setBackgroundColor(colors.gray)
166
    if color1 ~= colors.white then
167
        term.setTextColor(colors.white)
168
    else
169
        term.setTextColor(colors.black)
170
    end
171
    term.clear()
172
    color1 = numconv[choice]
173
    color2 = numconv[choice2]
174
    term.setCursorPos(1,1)
175
    term.setBackgroundColor(color1)
176
    term.clearLine()
177
    term.setCursorPos(maxX-(maxX-2),1)
178
    print("Options")
179
    term.setCursorPos(math.ceil(maxX/2)+1,1)
180
    print("|")
181
    term.setCursorPos(maxX-6,1)
182
    print("Return")
183
    term.setBackgroundColor(colors.gray)
184
    term.setTextColor(colors.white)
185
    term.setCursorPos(15,3)
186
    print("<->")
187
    paintutils.drawLine(14,4,14+string.len(colnames[choice]),4,numconv[choice])
188
    term.setCursorPos(3,4)
189
    if color1 ~= colors.white then
190
        term.setTextColor(colors.white)
191
    else
192
        term.setTextColor(colors.black)
193
    end
194
    print("1st color : " .. colnames[choice])
195
    term.setBackgroundColor(colors.gray)
196
    paintutils.drawLine(14,6,14+string.len(colnames[choice2]),6,numconv[choice2])
197
    if color2 ~= colors.white then
198
        term.setTextColor(colors.white)
199
    else
200
        term.setTextColor(colors.black)
201
    end
202
    term.setCursorPos(3,6)
203
    print("2nd color : " .. colnames[choice2])
204
    term.setBackgroundColor(colors.gray)
205
    term.setTextColor(colors.white)
206
    term.setCursorPos(15,7)
207
    print("<->")
208
    term.setCursorPos(5,10)
209
    print("About this program")
210
    term.setCursorPos(4,12)
211
    print("HD's Todo list V1.6")
212
    term.setCursorPos(1,14)
213
    print("-masterdisasterHD : Orignal program and idea")
214
    term.setCursorPos(1,17)
215
    print("-s0r00t : V1.5 enhancements")
216
    
217
 end
218
end
219
220
local function saveTasks(tbl)
221
 local A = fs.open(taskFile, "w")
222
 A.write(textutils.serialize(tbl))
223
 A.close()
224
end
225
226
local function addTask()
227
 local tasks = getTasks()
228
 term.setBackgroundColour(colors.black)
229
 term.setTextColour(colors.white)
230
 term.clear()
231
 term.setCursorPos(1,1)
232
 term.setCursorBlink(true)
233
 write("Task: ")
234
 local tsk = read()
235
 table.insert(tasks, tsk)
236
 saveTasks(tasks)
237
end
238
239
local function delTask()
240
 local tasks = getTasks()
241
 term.setBackgroundColour(colors.black)
242
 term.setTextColour(colors.white)
243
 term.clear()
244
 term.setCursorPos(1,1)
245
 write("Task number: ")
246
 local tsknmbr = tonumber(read())
247
 table.remove(tasks, tsknmbr)
248
 saveTasks(tasks)
249
end
250
251
local function showTask(pg, pos, h, w)
252
 local tasks = getTasks()
253
 local step1 = (h-2)*(pg-1)
254
 local step2 = (pos-1)+step1
255
 term.setBackgroundColour(color2)
256
 term.setTextColour(color1)
257
 term.clear()
258
 term.setCursorPos(1,1)
259
 if tasks[step2] ~= nil then
260
  write("Task #"..step2..":")
261
  local text = tasks[step2]
262
  local k = 1
263
  for i=1, h-1 do
264
   term.setCursorPos(1,i+1)
265
   for j=1,w do
266
    write(string.sub(text, k, k))
267
    k = k + 1
268
   end
269
  end
270
 term.setCursorPos(1,h)
271
 write("Press any key to continue")
272
 os.pullEvent("key")
273
 end
274
end
275
276
--Program loop
277
redraw(page)
278
local maxX, maxY = term.getSize()
279
while isUsing do
280
 sleep(0)
281
 ev, b, xPos, yPos = os.pullEvent()
282
    
283
284
  if ev == "mouse_click" then
285
  if xPos == 2 and yPos == 1 and not Options then
286
   addTask()
287
  elseif xPos == 6 and yPos == 1 and not Options then
288
   delTask()
289
  elseif xPos >= maxX-12 and xPos <= maxX-4 and yPos == 1 and not Options then
290
  Options = true
291
  elseif xPos >=maxX-3 and xPos <= maxX and yPos == 1 and not Options then
292
  isUsing = false
293
  elseif xPos == 2 and yPos == maxY and not Options then
294
   if page > 1 then
295
    page = page - 1
296
   end
297
  elseif xPos == maxX-1 and yPos == maxY and not Options then
298
   page = page + 1
299
  elseif xPos > 1 and yPos < maxY and not Options then
300
   showTask(page, yPos, maxY, maxX)
301
  elseif xPos >= maxX-6 and xPos <= maxX-1 and yPos == 1 and Options then
302
   Options = false
303
   local opfile = fs.open("/.todocfg", "w")
304
   opfile.writeLine(color1)
305
   opfile.write(color2)
306
   opfile.close()
307
  elseif xPos == 15 and yPos == 3 and Options then
308
    if choice-1 ~= -1 then
309
        choice = choice-1
310
    else
311
        choice = 15
312
    end
313
    redraw(page)
314
  elseif xPos == 17 and yPos == 3 and Options then
315
    if choice+1 ~= 16 then
316
        choice = choice+1
317
    else
318
        choice = 0
319
    end
320
    redraw(page)
321
  elseif xPos == 15 and yPos == 7 and Options then
322
    if choice2-1 ~= -1 then
323
        choice2 = choice2-1
324
    else
325
        choice2 = 15
326
    end
327
    redraw(page)
328
  elseif xPos == 17 and yPos == 7 and Options then
329
    if choice2+1 ~= 16 then
330
        choice2 = choice2+1
331
    else
332
        choice2 = 0
333
    end
334-
     redraw(page)
334+
335
   end
336
 elseif ev == "mouse_scroll" then
337
  if b == -1 then
338
   if page > 1 then page = page - 1 end
339
  elseif b == 1 then
340
   page = page + 1
341
  end
342
343
 elseif ev == "timer" then
344
     time_refresh()
345
end
346
 redraw(page)
347
end