View difference between Paste ID: fGbMtuXU and 3CVX5cPE
SHOW: | | - or go back to the newest paste.
1
--NhUI
2-
tBarC = 32768
2+
nhver = "v0.4u"
3-
tBartC = 1
3+
wip = 0
4-
backColor = 32768
4+
5-
term.setBackgroundColor(backColor)
5+
--Loading
6
if deskLoad==nil then
7-
--Functions
7+
8-
function titleBar()
8+
  local cycles = {"   ",".  ",".. ","..."," ..","  .","   "}
9
  local message = "Loading NhUI "..nhver
10-
  term.setBackgroundColor(tBarC)
10+
  for i=0,7 do
11-
  term.setTextColor(tBartC)
11+
    term.setCursorPos(1,1)
12
    print(message..cycles[(i%#cycles)+1])
13
    sleep(.1)
14-
  term.write("[Start]")
14+
15
  deskLoad=false
16-
  term.write("[Settings]")
16+
17-
  term.setCursorPos(25, 1)
17+
18-
  term.write("[NhUI]")
18+
--Unstable version detected
19
local function suggestedUpdate()
20
  if wip==2 and sugUpdate==nil then sugUpdate=false
21
    term.clear()
22-
  term.setTextColor(1)
22+
    term.setCursorPos(1,1)
23
    sleep(.1)
24-
  term.write(textutils.formatTime(os.time(), false ))
24+
    print("You're running an unstable WIP build.\nUpdate to the newest "..nhver.." build now?")
25
    print("\n1|Yes\n2|No")
26
    while true do
27
      local event, b, x, y = os.pullEventRaw()
28-
function drawDesktop()
28+
      if event == "key" then
29-
  term.setBackgroundColor(backColor)
29+
        if b==2 then
30
          term.clear()
31
          term.setCursorPos(1,1)
32-
    term.setCursorPos(2,17)
32+
          shell.run("delete","installer")
33-
    term.setTextColor(16384)
33+
          shell.run("pastebin","get","WCdpCaEm","installer")
34-
    term.write("NOTE: WIP BUILD - CURRENTLY STABLE")
34+
          shell.run("installer")
35
        elseif b==3 then
36-
  term.setCursorPos(2,18)
36+
          break
37-
  term.setTextColor(256)
37+
        end
38-
  term.write("(Click the menus for more options.)")
38+
      elseif event == "mouse_click" then
39-
  term.setCursorPos(47,17)
39+
        if b==1 and x>=1 and x<=5 and y==4 then
40-
  term.setTextColor(128)
40+
          shell.run("delete","installer")
41-
  term.write("NhUI")
41+
          shell.run("pastebin","get","WCdpCaEm","installer")
42-
  term.setCursorPos(46,18)
42+
          shell.run("installer")
43-
  term.write(nhver)
43+
        elseif b==1 and x>=1 and x<=4 and y==5 then
44
          break
45
        end
46
      end
47
    end
48
  end
49
end
50
51-
function drawMenu1()
51+
52-
  term.setTextColor(1)
52+
if not term.isColor then
53-
  term.setBackgroundColor(32768)
53+
else
54
  tBarC = 32768
55-
  print(">CraftOS")
55+
  tBartC = 1
56
  backColor = 32768
57-
  print("--------")
57+
58
59-
  print(">Shutdown")
59+
--Desktop prep
60
local function resetScreen()
61-
  print(">Restart")
61+
62
  term.setCursorPos(1,1)
63
end
64-
function clearMenu1()
64+
65
local function setBackColor()
66
  if not term.isColor then
67
  elseif term.isColor() then
68
    term.setBackgroundColor(backColor)
69
  else
70
    term.setBackgroundColor(backColor)
71
  end
72
end
73
74
local function setTextWhite()
75-
function drawMenu2()
75+
  if not term.isColor then
76-
  term.setTextColor(1)
76+
  elseif term.isColor() then
77-
  term.setBackgroundColor(32768)
77+
    term.setTextColor(1)
78
  else
79-
  print(">Password")
79+
    term.setTextColor(1)
80
  end
81
end
82-
function clearMenu2()
82+
83
local function titleBarColor()
84
  if not term.isColor then
85
  elseif term.isColor() then
86
    term.setBackgroundColor(tBarC)
87-
function drawMenu3()
87+
    term.setTextColor(tBartC)
88-
  term.setTextColor(1)
88+
  else
89-
  term.setBackgroundColor(32768)
89+
    term.setBackgroundColor(tBarC)
90-
  term.setCursorPos(25,2)
90+
    term.setTextColor(tBartC)
91-
  print(">Versions")
91+
92-
  term.setCursorPos(25,3)
92+
93-
  print(">Uninstall")
93+
94
local function titleBar()
95
  term.setCursorPos(1,1)
96-
function clearMenu3()
96+
  titleBarColor()
97-
  term.setCursorPos(25,2)
97+
98
  term.setCursorPos(2, 1)
99-
  term.setCursorPos(25,3)
99+
  term.write("1|Start")
100
  term.setCursorPos(12, 1)
101
  term.write("2|Options")
102
  term.setCursorPos(24, 1)
103-
function runShell()
103+
  term.write("3|NhUI")
104
end
105
106
local function titleBarExt()
107-
  term.setTextColor(16)
107+
108
  titleBarColor()
109-
  term.setTextColor(1)
109+
110
  term.setCursorPos(2, 1)
111
  term.write("-|Start")
112-
function uninstallCheck()
112+
113
  term.write("-|Options")
114
  term.setCursorPos(24, 1)
115
  term.write("-|NhUI")
116
end
117-
  term.setTextColor(256)
117+
118-
  print("(Click to make your selection.)\n")
118+
local function deskRun()
119-
  term.setTextColor(1)
119+
  if fs.exists("desktop") then
120-
  print("[Options]")
120+
    shell.run("desktop")
121-
  print(">Yes")
121+
  else
122-
  print(">No")
122+
    shell.run("startup")
123
  end
124-
    local event, b, x, y = os.pullEvent()
124+
125-
    if event == "mouse_click" then
125+
126-
      if b==1 and x>=1 and x<=4 and y==5 then
126+
127
  setTextWhite()
128-
        term.setCursorPos(1,1)
128+
129
  if os.time()>=10 and os.time()<13 then
130
    term.write(textutils.formatTime(os.time(), false ))
131
  elseif os.time()>=22 and os.time()>0 then
132
    term.write(textutils.formatTime(os.time(), false ))
133
  else
134
    term.write(" "..textutils.formatTime(os.time(), false ))
135-
      elseif b==1 and x>=1 and x<=4 and y==6 then
135+
136
  sleep(.83)
137-
        term.setCursorPos(1,1)
137+
138
139-
        shell.run("desktop")
139+
local function displayTimeExt()
140
  setTextWhite()
141
  term.setCursorPos(43, 1)
142
  if os.time()>=10 and os.time()<13 then
143
    term.write(textutils.formatTime(os.time(), false ))
144
  elseif os.time()>=22 and os.time()>0 then
145
    term.write(textutils.formatTime(os.time(), false ))
146-
function runDesktop()
146+
  else
147
    term.write(" "..textutils.formatTime(os.time(), false ))
148
  end
149
end
150-
    local event, b, x, y = os.pullEvent()
150+
151-
    if event == "mouse_click" then
151+
local function drawDesktop()
152
  setBackColor()
153
  term.clear()
154
  term.setCursorPos(2,17)
155
  if wip==1 then
156-
      elseif b==1 and x>=12 and x<=21 and y==1 then sel=2
156+
    if not term.isColor then
157
      term.write("NOTE: WIP BUILD - CURRENTLY STABLE")
158
    elseif term.isColor() then
159
      term.setTextColor(8192)
160-
      elseif b==1 and x>=25 and x<=30 and y==1 then sel=3
160+
      term.write("NOTE: WIP BUILD - CURRENTLY STABLE")
161
      term.setTextColor(1)
162
    else
163
      term.setTextColor(1)
164-
      elseif sel==1 and b==1 and x>=2 and x<=9 and y==2 then sel=0
164+
      term.write("NOTE: WIP BUILD - CURRENTLY STABLE")
165
    end
166
  elseif wip==2 then
167
    if not term.isColor then
168
      term.write("NOTE: WIP BUILD - CURRENTLY UNSTABLE")
169
    elseif term.isColor() then
170
      term.setTextColor(16384)
171-
      elseif sel==1 and b==1 and x>=2 and x<=10 and y==4 then sel=0
171+
      term.write("NOTE: WIP BUILD - CURRENTLY UNSTABLE")
172
    else
173-
      elseif sel==1 and b==1 and x>=2 and x<=9 and y==5 then sel=0
173+
      term.setTextColor(1)
174
      term.write("NOTE: WIP BUILD - CURRENTLY UNSTABLE")
175-
      elseif sel==2 and b==1 and x>=12 and x<=20 and y==2 then sel=0
175+
176
  end
177-
        shell.run("passwordsetup")
177+
  if not term.isColor then
178
    term.setCursorPos(2,18)
179-
      elseif sel==3 and b==1 and x>=25 and x<=33 and y==2 then sel=0
179+
    term.write("(Mouse and keyboard supported.)")
180
    term.setCursorPos(47,17)
181-
        shell.run("updater")
181+
    term.write("NhUI")
182
    term.setCursorPos(46,18)
183-
      elseif sel==3 and b==1 and x>=25 and x<=34 and y==3 then sel=0
183+
    term.write(nhver)
184
  else
185
    term.setTextColor(256)
186
    term.setCursorPos(2,18)
187
    term.write("(Mouse and keyboard supported.)")
188
    term.setTextColor(128)
189
    term.setCursorPos(47,17)
190
    term.write("NhUI")
191
    term.setCursorPos(46,18)
192
    term.write(nhver)
193
  end
194
  titleBar()
195
  disptime=1
196
  repeat
197
    displayTime()
198
  until disptime==0
199
end
200
201
local function menuColor()
202
  if not term.isColor then
203
  elseif term.isColor() then
204
    term.setTextColor(tBartC)
205
    term.setBackgroundColor(backColor)
206
  else
207
    term.setTextColor(tBartC)
208
    term.setBackgroundColor(backColor)
209
  end
210
end
211
 
212
local function drawMenu1()
213
  menuColor()
214
  term.setCursorPos(2,2)
215
  print("1|CraftOS")
216
  term.setCursorPos(2,3)
217
  print("---------")
218
  term.setCursorPos(2,4)
219
  print("2|Shutdown")
220
  term.setCursorPos(2,5)
221
  print("3|Restart")
222
end
223
224
local function clearMenu1()
225
  term.setCursorPos(2,2)
226
  term.clearLine()
227
  term.setCursorPos(2,3)
228
  term.clearLine()
229
  term.setCursorPos(2,4)
230
  term.clearLine()
231
  term.setCursorPos(2,5)
232
  term.clearLine()
233
end
234
235
local function drawMenu2()
236
  menuColor()
237
  term.setCursorPos(12,2)
238
  print("1|Password")
239
end
240
241
local function clearMenu2()
242
  term.setCursorPos(12,2)
243
  term.clearLine()
244
end
245
246
local function drawMenu3()
247
  menuColor()
248
  term.setCursorPos(24,2)
249
  print("1|Versions")
250
  term.setCursorPos(24,3)
251
  print("2|Components")
252
  term.setCursorPos(24,4)
253
  print("3|Uninstall")
254
end
255
256
local function clearMenu3()
257
  term.setCursorPos(24,2)
258
  term.clearLine()
259
  term.setCursorPos(24,3)
260
  term.clearLine()
261
  term.setCursorPos(24,4)
262
  term.clearLine()
263
end
264
265
--Desktop menus
266
local function runShell()
267
  resetScreen()
268
  sleep(.1)
269
  if not term.isColor then
270
  elseif term.isColor() then
271
    term.setTextColor(16)
272
  else
273
    term.setTextColor(1)
274
  end
275
  print("CraftOS shell (Ctrl+R will reinitialize NhUI.)")
276
  setTextWhite()
277
end
278
279
local function passwordSetup()
280
  resetScreen()
281
  sleep(.1)
282
  setTextWhite()
283
  print("Would you like your computer to have a password?")
284
  print("\n[Choices]\n1|Yes\n2|No\n3|(Back)")
285
  while true do
286
    local event, b, x, y = os.pullEventRaw()
287
    if event == "key" then
288
      if b==2 then
289
        shell.run("rename","startup","desktop")
290
        shell.run("delete","startup")
291
        shell.run("pastebin","get","Csag1T39","startup") --v0.4u+
292
        shell.run("delete",".info")
293
        term.clear()
294
        sleep(.1)
295
        os.reboot()
296
      elseif b==3 then
297
        shell.run("rename","startup","desktop")
298
        shell.run("delete","startup")
299
        shell.run("rename","desktop","startup")
300
        shell.run("delete",".info")
301
        resetScreen()
302
        sleep(.1)
303
        print("Preferences saved.")
304
        term.write("Rebooting to take effect")
305
        textutils.slowPrint("...",2.5)
306
        sleep(.5)
307
        term.clear()
308
        sleep(.3)
309
        os.reboot()
310
      elseif b==4 then
311
        deskRun()
312
        break
313
      end
314
    elseif event == "mouse_click" then
315
      if b==1 and x>=1 and x<=5 and y==4 then
316
        shell.run("rename","startup","desktop")
317
        shell.run("delete","startup")
318
        shell.run("pastebin","get","Csag1T39","startup") --v0.4u+
319
        shell.run("delete",".info")
320
        term.clear()
321
        sleep(.1)
322
        os.reboot()
323
      elseif b==1 and x>=1 and x<=4 and y==5 then
324
        shell.run("rename","startup","desktop")
325
        shell.run("delete","startup")
326
        shell.run("rename","desktop","startup")
327
        shell.run("delete",".info")
328
        resetScreen()
329
        sleep(.1)
330
        print("Preferences saved.")
331
        term.write("Rebooting to take effect")
332
        textutils.slowPrint("...",2.5)
333
        sleep(.5)
334
        term.clear()
335
        sleep(.3)
336
        os.reboot()
337
      elseif b==1 and x>=1 and x<=8 and y==6 then
338
        deskRun()
339
        break
340
      end
341
    end
342
  end
343
end
344
345
local function irlInternetCheck()
346
  if intCheckAgain==true or intCheckAgain==nil then
347
    resetScreen()
348
    sleep(.1)
349
    sel=0
350
    print("INTERNET CHECK: Are you connected to the internet?")
351
    print("\n1|Yes\n2|No")
352
    while true do
353
      local event, b, x, y = os.pullEventRaw()
354
      if event == "key" then
355
        if b==2 and sel==0 then sel=1
356
          internet=true
357
          term.setCursorPos(1,3)
358
          print("-\n-")
359
          term.setCursorPos(1,6)
360
          print("Don't ask again until next startup?")
361
          print("\n1|True\n2|False")
362
        elseif b==3 and sel==0 then
363
          internet=false
364
          break
365
        elseif b==2 and sel==1 then sel=0
366
          intCheckAgain=false
367
          break
368
        elseif b==3 and sel==1 then sel=0
369
          intCheckAgain=true
370
          break
371
        end
372
      elseif event == "mouse_click" then
373
        if b==1 and x>=1 and x<=5 and y==3 and sel==0 then sel=1
374
          internet=true
375
          term.setCursorPos(1,3)
376
          print("-\n-")
377
          term.setCursorPos(1,6)
378
          print("Don't ask again until next startup?")
379
          print("\n1|True\n2|False")
380
       elseif b==1 and x>=1 and x<=4 and y==4 and sel==0 then
381
          internet=false
382
          break
383
        elseif b==1 and x>=1 and x<=5 and y==8 and sel==1 then sel=0
384
          intCheckAgain=false
385
          break
386
        elseif b==1 and x>=1 and x<=7 and y==9 and sel==1 then sel=0
387
          intCheckAgain=true
388
          break
389
        end
390
      end
391
    end
392
  end
393
end
394
395
local function nhuiProgList()
396
  resetScreen()
397
  sleep(.1)
398
  setTextWhite()
399
  print("Which program would you like to re-download?")
400
  print("\n[Choices]\n1|Updater\n2|Uninstaller\n3|(Back)")
401
  while true do
402
    local event, b, x, y = os.pullEventRaw()
403
    if event == "key" then
404
      if b==2 then
405
        resetScreen()
406
        print("Downloading program...")
407
        shell.run("delete","updater")
408
        shell.run("pastebin","get","LrBWAr2L","updater") --v0.3a+
409
        resetScreen()
410
        print("Download complete.")
411
        sleep(.8)
412
        deskRun()
413
        break
414
      elseif b==3 then
415
        resetScreen()
416
        print("Downloading program...")
417
        shell.run("delete","uninstaller")
418
        shell.run("pastebin","get","PNvB0uw4","uninstaller") --v0.2a+
419
        resetScreen()
420
        print("Download complete.")
421
        sleep(.8)
422
        deskRun()
423
        break
424
      elseif b==4 then
425
        deskRun()
426
        break
427
      end
428
    elseif event == "mouse_click" then
429
      if b==1 and x>=1 and x<=9 and y==4 then
430
        resetScreen()
431
        print("Downloading program...")
432
        shell.run("delete","updater")
433
        shell.run("pastebin","get","LrBWAr2L","updater") --v0.3a+
434
        resetScreen()
435
        print("Download complete.")
436
        sleep(.8)
437
        deskRun()
438
        break
439
      elseif b==1 and x>=1 and x<=13 and y==5 then
440
        resetScreen()
441
        print("Downloading program. Will reboot when finished.")
442
        shell.run("delete","uninstaller")
443
        shell.run("pastebin","get","PNvB0uw4","uninstaller") --v0.2a+
444
        resetScreen()
445
        print("Download complete.")
446
        sleep(.8)
447
        deskRun()
448
        break
449
      elseif b==1 and x>=1 and x<=8 and y==6 then
450
        deskRun()
451
        break
452
      end
453
    end
454
  end
455
end
456
457
local function uninstallCheck()
458
  resetScreen()
459
  sleep(.1)
460
  print("Would you like to uninstall NhUI "..nhver.."? ;-;")
461
  if not term.isColor then
462
  else
463
    term.setTextColor(256)
464
  end
465
  print("(User-created programs will *not* be deleted.)\n")
466
  setTextWhite()
467
  print("[Choices]\n1|Yes\n2|No (Back)")
468
  while true do
469
    local event, b, x, y = os.pullEventRaw()
470
    if event == "key" then
471
      if b==2 then
472
        resetScreen()
473
        sleep(.1)
474
        shell.run("uninstaller")
475
        term.write("Rebooting to complete uninstall")
476
        textutils.slowPrint("...",2.307)
477
        sleep(.2)
478
        os.reboot()
479
      elseif b==3 then
480
        resetScreen()
481
        sleep(.1)
482
        deskRun()
483
        break
484
      end
485
    elseif event == "mouse_click" then
486
      if b==1 and x>=1 and x<=5 and y==5 then
487
        resetScreen()
488
        sleep(.1)
489
        shell.run("uninstaller")
490
        term.write("Rebooting to complete uninstall")
491
        textutils.slowPrint("...",2.307)
492
        sleep(.2)
493
        os.reboot()
494
      elseif b==1 and x>=1 and x<=11 and y==6 then
495
        resetScreen()
496
        sleep(.1)
497
        deskRun()
498
        break
499
      end
500
    end
501
  end 
502
end
503
504
--Desktop
505
local function runDesktop()
506
  sel=0
507
  desk=1
508
  repeat
509
    local event, b, x, y = os.pullEventRaw()
510
    if event == "key" then
511
      if sel==0 and b==2 then sel=1
512
        clearMenu2()
513
        clearMenu3()
514
        titleBarExt()
515
        displayTimeExt()
516
        drawMenu1()
517
      elseif sel==0 and b==3 then sel=2
518
        clearMenu1()
519
        clearMenu3()
520
        titleBarExt()
521
        displayTimeExt()
522
        drawMenu2()
523
      elseif sel==0 and b==4 then sel=3
524
        clearMenu1()
525
        clearMenu2()
526
        titleBarExt()
527
        displayTimeExt()
528
        drawMenu3()
529
      elseif sel==1 and b==2 then sel=0
530
        disptime=0
531
        desk=0
532
        runShell()
533
        break
534
      elseif sel==1 and b==3 then sel=0
535
        os.shutdown()
536
      elseif sel==1 and b==4 then sel=0
537
        os.reboot()
538
      elseif sel==2 and b==2 then sel=0
539
        disptime=0
540
        term.clear()
541
        irlInternetCheck()
542
        if internet==true then
543
          resetScreen()
544
          passwordSetup()
545
        elseif internet==false then
546
          deskRun()
547
          break
548
        end
549
      elseif sel==3 and b==2 then sel=0
550
        disptime=0
551
        term.clear()
552
        irlInternetCheck()
553
        if internet==true then
554
          resetScreen()
555
          print("Getting newest updater build...")
556
          shell.run("delete","updater")
557
          shell.run("pastebin","get","LrBWAr2L","updater") --v0.3a+
558
          shell.run("updater")
559
          break
560
        elseif internet==false then
561
          deskRun()
562
          break
563
        end
564
      elseif sel==3 and b==3 then sel=0
565
        disptime=0
566
        term.clear()
567
        irlInternetCheck()
568
        if internet==true then
569
          resetScreen()
570
          nhuiProgList()
571
        elseif internet==false then
572
          deskRun()
573
          break
574
        end
575
      elseif sel==3 and b==4 then sel=0
576
        disptime=0
577
        uninstallCheck()
578
        break
579
      else
580
        sel=0
581
        parallel.waitForAll(drawDesktop, runDesktop)
582
      end
583
    elseif event == "mouse_click" then
584
      if b==1 and x>=2 and x<=8 and y==1 then sel=1
585
        clearMenu2()
586
        clearMenu3()
587
        titleBarExt()
588
        displayTimeExt()
589
        drawMenu1()
590
      elseif b==1 and x>=12 and x<=20 and y==1 then sel=2
591
        clearMenu1()
592
        clearMenu3()
593
        titleBarExt()
594
        displayTimeExt()
595
        drawMenu2()
596
      elseif b==1 and x>=24 and x<=29 and y==1 then sel=3
597
        clearMenu1()
598
        clearMenu2()
599
        titleBarExt()
600
        displayTimeExt()
601
        drawMenu3()
602
      elseif sel==1 and b==1 and x>=2 and x<=10 and y==2 then sel=0
603
        disptime=0
604
        desk=0
605
        runShell()
606
        break
607
      elseif sel==1 and b==1 and x>=2 and x<=9 and y==3 then sel=1
608
        drawMenu1()
609
      elseif sel==1 and b==1 and x>=2 and x<=11 and y==4 then sel=0
610
        os.shutdown()
611
      elseif sel==1 and b==1 and x>=2 and x<=10 and y==5 then sel=0
612
        os.reboot()
613
      elseif sel==2 and b==1 and x>=12 and x<=21 and y==2 then sel=0
614
        disptime=0
615
        term.clear()
616
        irlInternetCheck()
617
        if internet==true then
618
          resetScreen()
619
          passwordSetup()
620
        elseif internet==false then
621
          deskRun()
622
          break
623
        end
624
      elseif sel==3 and b==1 and x>=24 and x<=35 and y==2 then sel=0
625
        disptime=0
626
        term.clear()
627
        irlInternetCheck()
628
        if internet==true then
629
          resetScreen()
630
          print("Getting newest updater build...")
631
          shell.run("delete","updater")
632
          shell.run("pastebin","get","LrBWAr2L","updater") --v0.3a+
633
          shell.run("updater")
634
          break
635
        elseif internet==false then
636
          deskRun()
637
          break
638
        end
639
      elseif sel==3 and b==1 and x>=24 and x<=33 and y==3 then sel=0        disptime=0
640
        disptime=0
641
        term.clear()
642
        irlInternetCheck()
643
        if internet==true then
644
          resetScreen()
645
          nhuiProgList()
646
        elseif internet==false then
647
          deskRun()
648
          break
649
        end
650
      elseif sel==3 and b==1 and x>=24 and x<=34 and y==4 then sel=0
651
        disptime=0
652
        uninstallCheck()
653
        break
654
      else
655
        sel=0
656
        parallel.waitForAll(drawDesktop, runDesktop)
657
      end
658
    end
659
  until desk==0
660
end
661
662
--Run desktop
663
term.clear()
664
sleep(.1)
665
suggestedUpdate()
666
parallel.waitForAll(drawDesktop, runDesktop)