-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMynaptic.lua
1731 lines (1612 loc) · 50.8 KB
/
Mynaptic.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--Made by Wilma456
print("Starting Mynaptic Please Wait ...")
os.loadAPI("/usr/apis/wilmaapi")
os.loadAPI("/usr/apis/clipboard")
if fs.exists("/usr/apis/backpack") then
os.loadAPI("/usr/apis/backpack")
elseif fs.exists("/usr/apis/minepackapi") then
os.loadAPI("/usr/apis/minepackapi")
else
printError("Could not find Backpack/minepackapi")
return 1
end
if term.isColor() == false then
printError("This Programm only run on a Advanced Computer/Turtle/Pocket")
return 2
end
--[[
term.setBackgroundColor(colors.blue)
term.clear()
local logo={
{16384,16384,00000,00000,00000,16384,16384,00000,16384,00000,00000,00000,16384,00000,16384,00000,00000,16384,00000,00000,00000,00000,16384,00000,00000,00000,00000,16384,16384,16384,00000,16384,16384,16384,00000,16384,00000,16384,16384,16384,},
{16384,00000,16384,00000,16384,00000,16384,00000,00000,16384,00000,16384,00000,00000,16384,16384,00000,16384,00000,00000,00000,16384,00000,16384,00000,00000,00000,16384,00000,16384,00000,00000,16384,00000,00000,16384,00000,16384,},
{16384,00000,00000,16384,00000,00000,16384,00000,00000,00000,16384,00000,00000,00000,16384,00000,16384,16384,00000,00000,16384,16384,16384,16384,16384,00000,00000,16384,16384,16384,00000,00000,16384,00000,00000,16384,00000,16384,},
{16384,00000,00000,00000,00000,00000,16384,00000,00000,00000,16384,00000,00000,00000,16384,00000,00000,16384,00000,16384,00000,00000,00000,00000,00000,16384,00000,16384,00000,00000,00000,00000,16384,00000,00000,16384,00000,16384,16384,16384,},
}
local logoPocket={
{16384,16384,00000,00000,00000,16384,16384,},
{16384,00000,16384,00000,16384,00000,16384,},
{16384,00000,00000,16384,00000,00000,16384,},
{16384,00000,00000,00000,00000,00000,16384,},
}
if pocket then
paintutils.drawImage(logoPocket,5,5)
else
paintutils.drawImage(logo,5,5)
end
--]]
if wilmaapi == nil then
printError("Error whith loading wilmaapi")
return 3
end
if clipboard == nil then
printError("Error whith loading clipboard API")
return 3
end
mynaptic = {}
mynaptic.version = "12.0"
--Get Options for Commandline
mynaptic.ops = {}
for k,v in ipairs({...}) do
local head,body = wilmaapi.splitString(v,"=")
mynaptic.ops[head] = body
end
mynaptic.shellmode = false
if minepackapi then
mynaptic.packapi = minepackapi
elseif backpack then
mynaptic.packapi = backpack
end
function getPrint(text)
packlist.writeLine(text)
rcou = rcou + 1
end
local screenw,screenh = term.getSize()
mynaptic.screenw = screenw
mynaptic.screenh = screenh
mynaptic.isUpdateDone = {}
--Write lang
lang = {}
lang.keyContinue = "Press any Key to continue"
lang.search = "Search:"
lang.shell = "Shell:"
lang.noCommand = "Command not found"
lang.packNotFound = "Package not found"
lang.cancel = "Cancel"
lang.ok = "OK"
lang.apply = "Apply"
lang.fetch = "Fetch"
lang.update = "Update"
lang.config = "Config"
lang.menu = "Menu"
lang.help = "Help"
lang.yes = "Yes"
lang.no = "No"
lang.name = "Name:"
lang.installed = "Installed:"
lang.updateAviable = "Update aviable:"
lang.filename = "Filename:"
lang.target = "Target:"
lang.typ = "Type:"
lang.url = "URL:"
lang.size = "Size:"
lang.version = "Version:"
lang.category = "Category:"
lang.dependencies = "Dependencies:"
lang.description = "Description:"
lang.none = "None"
lang.installPack = "These Packages will be installed:"
lang.removePack = "These Packages will be removed:"
lang.updatePack = "These Packages will be updated:"
lang.install = "Install "
lang.remove = "Remove "
lang.youEdit = "You Edit:"
lang.old = "Old:"
lang.default = "Default:"
lang.needRestart = "Needs Restart"
lang.selectColour = "Please select a Colour"
lang.newEntry = "New Entry:"
lang.newEntryText = "Please enter new Entry"
lang.boolEntry = "Please choose new Entry"
lang.keyEntry = "Please choose a new Key"
lang.back = "Back"
lang.reset = "Reset"
lang.resetConfig = "Your config has been reseted to the default values"
lang.history = "History"
lang.clear = "Clear"
lang.exitText = "Thank you for using Mynaptic!"
lang.configerror = "There are Errors in the your Config. You now had to set some Entrys new"
lang.updating = "Updating: "
lang.noUpdates = "All Packages are up to date"
lang.pluginError = "The following Errors hapens while loading Plugin \"{pluginName}\""
lang.mynapticCrash = "It looks like Mynaptic had crashed. Sorry for that. Please report this Bug in the CC Forum."
--Start Help
local tmpta = {}
helpta = {}
tmpta.titel = "What is Packman and Mynaptic"
tmpta.con = [[Packman is a package manager like apt made by Lyqyd. It allows you to easy install,remove and update programs.
Mynaptic is a GUI for Packman made by Wilma456]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Navigate"
tmpta["con"] = [[Use the mousewhell or the arrow keys to scroll. You can mark packages by leftclicking it.
Exit Mynaptic by clicking to "X" in to right up corner
To use the search, just write your text
You can scroll in many menus.
]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Install Software"
tmpta["con"] = [[The white software are not installed. Click on it to mark it to install.
If you have choose your software, just click "Apply"
]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Remove Software"
tmpta["con"] = [[The red software are installed. Click on it to mark it to remove.
If you have choose your software, just click "Apply"
]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Get more Information"
tmpta["con"] = "If you want more information about a package, just rightclick it"
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "What is Apply"
tmpta.con = 'With "Apply" you can install all Packages that you have marked to install and remove all Packages that you have marked to remove.'
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "What is Fetch"
tmpta.con = 'The List with all Packages is saved on your Computer. Whith "Fetch" you can update this list. You need to restart Mynaptic to see the changes.'
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "Update your Programs"
tmpta.con = 'With "Update" you can Update your Programs. Mynaptic will see, what Programs can be updated.'
tmpta = {}
tmpta["titel"] = "Use History"
tmpta["con"] = [[In the default config, Mynaptic write all changes to the file /var/MynapticHistory.txt. To view the content of the file, use the Historymenu.]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "Use Clipboard"
tmpta.con = [[You can use the system clipboard by pressing Ctrl+V
You can use the clipboard from the clipboard API by pressing the mousewhell
]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Personalisierte Mynaptic"
tmpta["con"] = [[You can change the Config with the "config" Menu or by editing /etc/mynaptic
Mynaptic checks every run, if the config correct.
If you get any config errors by runing Mynaptic (maybe after update) and don't want to fix it, just delete /etc/mynaptic. If the config file not exists, Mynaptic will create them by running
Lines in /etc/mynaptic who are started with # are ignored.
]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "Move Items in the Menubar"
tmpta.con = "You can move Items in the Menubar by drag and drop them with the right Mousebutton. The Position is not saved, so it get lost with closing Mynaptic."
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "On what Devices run Mynaptic"
tmpta["con"] = [[Mynaptic fully supports Advanced Computers
The Helpmenu doesn't works full on a turle and on a Pocket Computer. Other things work.
Other Devices are not supported]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Using Plugins"
tmpta["con"] = [[With Plugins you can modify Mynaptic e.g another language or another package system
Simple place Plugins in the pluginFoler (default /usr/share/mynaptic/plugins) and be sure, thet loadPlugins is true
]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "Commandline Arguments"
tmpta.con = [[You can set the config of Mynaptic with the Commandline. e.g "Mynaptic showVersion=true textColour=red" will start Mynaptic and set showVersion to true and textColour to red.
You can also set the Path to the Config File with configPath=Path]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "Develop Plugins"
tmpta.con = "To install the developer Documentation install the Package mynaptic-plugindev and view the help with 'ghv Mynaptic'"
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "Add your Program"
tmpta.con = "To add your Program to Packman/Mynaptic visit https://github.com/lyqyd/cc-packman and follow the instructions"
tmpta.url = {{"Click here, to visit the GitHub Page of Packman","https://github.com/lyqyd/cc-packman"}}
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Report Bugs/Feedback"
tmpta["con"] = [[You can report bugs or left feedback at this sites:
http://www.computercraft.info/forums2/index.php?/topic/27327-mynaptic-a-gui-for-packman/
https://github.com/Wilma456/Computercraft/issues]]
tmpta.url = {{"Click here to visit the Thread in the CC Forum","http://www.computercraft.info/forums2/index.php?/topic/27327-mynaptic-a-gui-for-packman/"},{"Click here to visit the GitHub Issue Tracker","https://github.com/Wilma456/Computercraft/issues"}}
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "Use Mynaptic in your OS"
tmpta["con"] = [[If you use packman in your OS, you may want to incluse Mynaptic. You have my permission to do this. If you want to optimize Mynaptic for your OS, just write Wilma456 at the CC Forum a PM.]]
table.insert(helpta,tmpta)
tmpta = {}
tmpta.titel = "License"
tmpta.con = 'Mynaptic is licesed under the BSD 2-clause "Simplified" License. For more information look at https://github.com/Wilma456/Computercraft/blob/master/LICENSE'
tmpta.url = {{"Click here to see the License","https://github.com/Wilma456/Computercraft/blob/master/LICENSE"}}
table.insert(helpta,tmpta)
tmpta = {}
tmpta["titel"] = "About"
tmpta["con"] = "This is Mynaptic Version "..mynaptic.version.." made by Wilma456"
table.insert(helpta,tmpta)
tmpta = nil
--End Help
--Shellcommands
shellcom = {}
function shellcom.update()
mynaptic.updatemenu()
end
function shellcom.top()
tpos = 0
mynaptic.drawMenu()
end
function shellcom.debug()
mynaptic.debugmenu()
end
function shellcom.bottom()
tpos = packcou - screenh + 2
mynaptic.drawMenu()
end
function shellcom.apply()
mynaptic.doChanges()
end
function shellcom.fetch()
mynaptic.reload()
end
function shellcom.history()
mynaptic.history()
end
function shellcom.about()
mynaptic.setShellText("Mynaptic Version "..mynaptic.version.." made by Wilma456")
end
function shellcom.menu()
mynaptic.showMenulist()
end
function shellcom.langedit()
mynaptic.langScreen()
end
--End Shellcommands
function ioread()
return "N"
end
local function nichts()
end
function shellresolve(ag)
shell.resolveProgram(ag)
end
function mynaptic.setShellText(text)
term.setCursorBlink(false)
term.setCursorPos(1,screenh)
term.clearLine()
write(text)
end
function mynaptic.showTextWindow(sText)
term.setTextColor(colors[config.menuTextColour])
while true do
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.clear()
term.setCursorPos(1,1)
print(sText)
term.setCursorPos(1,mynaptic.screenh)
term.setBackgroundColor(colors[config.bottomBarColour])
term.clearLine()
term.write(lang.ok)
local ev,me,x,y = os.pullEvent()
if ev == "mouse_click" and y == mynaptic.screenh then
return
elseif ev == "term_resize" then
mynaptic.screenw, mynaptic.screenh = term.getSize()
end
end
end
function mynaptic.showErrorWindow(sText,sError)
while true do
term.setTextColor(colors[config.menuTextColour])
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.clear()
term.setCursorPos(1,1)
print(sText)
term.setTextColor(colors[config.errorColour])
print(sError)
term.setTextColor(colors[config.menuTextColour])
term.setCursorPos(1,mynaptic.screenh)
term.setBackgroundColor(colors[config.bottomBarColour])
term.clearLine()
term.write(lang.ok)
local ev,me,x,y = os.pullEvent()
if ev == "mouse_click" and y == mynaptic.screenh then
return
elseif ev == "term_resize" then
mynaptic.screenw, mynaptic.screenh = term.getSize()
end
end
end
function mynaptic.setLineColor(text,arrow)
if type(text) == "string" then
term.clearLine()
term.write(text)
local x,y = term.getCursorPos()
term.setCursorPos(mynaptic.screenw,y)
term.write(arrow)
print()
end
end
function mynaptic.drawLine(te,arrow)
if te == nil then
return
end
term.setBackgroundColor(colors[config["notinstalledColour"]])
if statuscheck[te] == "instaled" then
term.setBackgroundColor(colors[config["installedColour"]])
elseif statuscheck[te] == "install" then
term.setBackgroundColor(colors[config["installColour"]])
elseif statuscheck[te] == "remove" then
term.setBackgroundColor(colors[config["removeColour"]])
end
ins,teb,ver = te:match("([^ ]+) ([^ ]+) ([^ ]+)")
if config["showRepository"] == "false" then
repo,teb = wilmaapi.splitString(teb,"/")
end
if config["showVersion"] == "true" then
mynaptic.setLineColor(teb.." "..ver,arrow)
else
mynaptic.setLineColor(teb,arrow)
end
checkta[checkcou] = te
checkcou = checkcou + 1
end
function mynaptic.drawMenu()
term.setTextColor(colors[config["textColour"]])
term.setBackgroundColor(colors[config["backgroundColour"]])
term.clear()
term.setCursorPos(1,1)
checkcou = 1
term.setBackgroundColor(colors[config["menubarColour"]])
term.clearLine()
if config.closeButtonRight == "true" then
term.setBackgroundColor(colors[config["closeColour"]])
term.write("X")
term.setBackgroundColor(colors[config["menubarColour"]])
end
local menutext = ""
for key,menuitem in ipairs(mynaptic.menubar) do
menutext = menutext..menuitem.text.." "
end
term.write(menutext)
if config.closeButtonRight == "false" then
term.setCursorPos(mynaptic.screenw,1)
term.setBackgroundColor(colors[config["closeColour"]])
term.write("X")
end
print()
if tpos ~= 0 and config.showScrollArrows == "true" then
mynaptic.drawLine(textta[tpos+1],"\30")
else
mynaptic.drawLine(textta[tpos+1]," ")
end
for i=3,mynaptic.screenh-2 do
mynaptic.drawLine(textta[tpos+i-1]," ")
end
if tpos+mynaptic.screenh-2 ~= #textta and config.showScrollArrows == "true" then
mynaptic.drawLine(textta[tpos+mynaptic.screenh-2],"\31")
else
mynaptic.drawLine(textta[tpos+mynaptic.screenh-2]," ")
end
term.setCursorPos(1,mynaptic.screenh)
term.setBackgroundColor(colors[config["searchColour"]])
term.clearLine()
term.setCursorPos(1,mynaptic.screenh)
if mynaptic.shellmode == true then
write(lang.shell..shelltext)
else
write(lang.search..search)
end
if config.showCursorBlink == "true" then
term.setCursorBlink(true)
end
end
helpta["egg"] = {}
function mynaptic.doChanges()
local packlist = {}
local installta = {}
table.insert(packlist,lang.installPack)
for k,v in pairs(install.check) do
local tmpstr = k:sub(3):match("([^ ]+) ([^ ]+)")
table.insert(packlist,tmpstr)
table.insert(installta,tmpstr)
end
local removeta = {}
table.insert(packlist,lang.removePack)
for k,v in pairs(remove.check) do
local tmpstr = k:sub(3):match("([^ ]+) ([^ ]+)")
table.insert(packlist,tmpstr)
table.insert(removeta,tmpstr)
end
local scrollpos = 0
while true do
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.setTextColor(colors[config.menuTextColour])
term.clear()
term.setCursorPos(1,1)
for i=1,mynaptic.screenh-1 do
if type(packlist[i+scrollpos]) == "string" then
print(packlist[i+scrollpos])
end
end
if scrollpos ~= 0 and config.showScrollArrows == "true" then
term.setCursorPos(mynaptic.screenw,1)
term.write("\30")
end
if #packlist ~= scrollpos+mynaptic.screenh-1 and config.showScrollArrows == "true" and #packlist > mynaptic.screenh-1 then
term.setCursorPos(mynaptic.screenw,mynaptic.screenh-1)
term.write("\31")
end
term.setBackgroundColor(colors[config.bottomBarColour])
term.setCursorPos(1,mynaptic.screenh)
term.clearLine()
term.write(lang.cancel)
term.setCursorPos(mynaptic.screenw-#lang.ok+1,mynaptic.screenh)
term.write(lang.ok)
local ev,me,x,y = os.pullEvent()
if ev == "mouse_scroll" then
if me == -1 and scrollpos ~= 0 then
scrollpos = scrollpos - 1
elseif me == 1 and #packlist ~= scrollpos+mynaptic.screenh-1 and #packlist > mynaptic.screenh-1 then
scrollpos = scrollpos + 1
end
elseif ev == "key" then
if me == confid.scrollDownKey and scrollpos ~= 0 then
scrollpos = scrollpos - 1
elseif me == config.scrollUpKey and #packlist ~= scrollpos+mynaptic.screenh-1 and #packlist > mynaptic.screenh-1 then
scrollpos = scrollpos + 1
end
elseif ev == "term_resize" then
mynaptic.screenw,mynaptic.screenh = term.getCursorPos()
elseif ev == "mouse_click" then
if y == mynaptic.screenh then
if x < #lang.cancel+1 then
mynaptic.drawMenu()
return
elseif x > mynaptic.screenw-#lang.ok then
break
end
end
end
end
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.clear()
term.setCursorPos(1,1)
local hisfile = fs.open(config.historyPath,"a")
for k,v in ipairs(installta) do
term.setTextColor(colors[config.textColour])
term.setBackgroundColor(colors[config.menuBackgroundColour])
print(lang.install..v)
for packname,_ in pairs(mynaptic.packapi.findDependencies(v)) do
mynaptic.packapi.list[packname]:install(getfenv())
end
--shell.run(config.packmanPath.." auto install "..v)
if config.writeHistory == "true" and not minepackapi then
hisfile.writeLine("Installed "..v)
end
statuscheck["A "..v.." "..mynaptic.packapi.list[v]["version"]] = "instaled"
end
install.check = {}
install.list = {}
for k,v in ipairs(removeta) do
term.setTextColor(colors[config.textColour])
term.setBackgroundColor(colors[config.menuBackgroundColour])
print(lang.remove..v)
mynaptic.packapi.list[v]:remove(getfenv())
if config.writeHistory == "true" and not minepackapi then
hisfile.writeLine("Removed "..v)
end
statuscheck["I "..v.." "..mynaptic.packapi.list[v]["version"]] = "notinstaled"
end
hisfile.close()
remove.check = {}
remove.list = {}
mynaptic.drawMenu()
end
helpta["egg"]["con"] = "You found a EasterEgg!"
function mynaptic.printcol(text)
term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
print(text)
end
function mynaptic.reload()
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)
shell.run(config.packmanPath.." fetch")
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)
mynaptic.drawMenu()
end
function mynaptic.showUpdates(tUpdate)
while true do
local w,h = term.getSize()
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.setTextColor(colors[config.menuTextColour])
term.clear()
term.setCursorPos(1,1)
print(lang.updatePack)
for k,v in ipairs(tUpdate) do
print(v)
end
term.setBackgroundColor(colors[config.bottomBarColour])
term.setCursorPos(1,h)
term.clearLine()
term.write(lang.cancel)
term.setCursorPos(w-#lang.ok+1,h)
term.write(lang.ok)
local ev,me,x,y = os.pullEvent()
if y == mynaptic.screenh then
if x < #lang.cancel+1 then
return
elseif x > w-#lang.ok then
break
end
end
end
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.clear()
term.setCursorPos(1,1)
local hisfile = fs.open(config.historyPath,"a")
for k,v in ipairs(tUpdate) do
print(lang.updating..v)
mynaptic.packapi.list[v]:upgrade()
if config.writeHistory == "true" and not minepackapi then
hisfile.writeLine("Updated "..v)
end
end
hisfile.close()
end
function mynaptic.updatemenu()
local tUpdate = {}
for k,v in pairs(mynaptic.packapi.installed) do
if k:find("/") ~= nil then
if mynaptic.packapi.installed[k]["version"] ~= mynaptic.packapi.list[k]["version"] and not mynaptic.isUpdateDone[k] then
write(k.." ")
table.insert(tUpdate,k)
mynaptic.isUpdateDone[k] = true
end
end
end
if #tUpdate == 0 then
mynaptic.showTextWindow(lang.noUpdates)
else
mynaptic.showUpdates(tUpdate)
end
mynaptic.drawMenu()
end
function mynaptic.debugmenu()
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,1)
local debughis = {}
local running = true
local tEnv = {
["exit"] = function()
running = false
end,
}
setmetatable( tEnv, { __index = _ENV } )
print("Call exit() to exit")
while true do
if not running then
break
end
write(">")
local re = read(nil,debughis)
table.insert(debughis,re)
local ok,err = pcall(load(re,"Debugmenu","t",tEnv))
if not ok then
printError(err)
end
end
mynaptic.drawMenu()
end
function mynaptic.getPackInfo(ypos)
term.setCursorBlink(false)
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,1)
local getname = textta[tpos+ypos]:sub(3,-1)
getname = wilmaapi.splitString(getname," ")
if mynaptic.packapi.list[getname] == nil then
print("Error while getting Information")
print()
print(lang["keyContinue"])
os.pullEvent("key_up")
mynaptic.drawMenu()
return
end
local updatetext = lang.no
local installtest = lang.no
if string.byte(textta[tpos+ypos],1) == 85 then --U
updatetext = lang.yes
installtest = lang.yes
elseif string.byte(textta[tpos+ypos],1) == 73 then
installtest = lang.yes
end
local getname = textta[tpos+ypos]:sub(3,-1)
getname = wilmaapi.splitString(getname," ")
print(lang.name.." "..tostring(getname))
print(lang.installed.." "..tostring(installtest))
if mynaptic.packapi.list[getname]["download"]["type"]["type"] ~= "meta" then
print(lang.target.." "..mynaptic.packapi.list[getname]["target"])
print(lang.filename.." "..tostring(mynaptic.packapi.list[getname]["download"]["type"]["filename"]))
end
print(lang.typ.." "..tostring(mynaptic.packapi.list[getname]["download"]["type"]["type"]))
if mynaptic.packapi.list[getname]["download"]["type"]["type"] ~= "meta" then
print(lang.url.." "..tostring(mynaptic.packapi.list[getname]["download"]["type"]["url"]))
print(lang.size.." "..tostring(mynaptic.packapi.list[getname]["size"]).." Bytes")
end
print(lang.version.." "..tostring(mynaptic.packapi.list[getname]["version"]))
io.write(lang.category.. " ")
for cate,_ in pairs(mynaptic.packapi.list[getname]["category"]) do
io.write(cate.." ")
end
io.write("\n")
local testdep = false
local getdep = mynaptic.packapi.list[getname]["dependencies"]
getdep[getname] = nil
io.write(lang.dependencies.." ")
for dep,_ in pairs(getdep) do
io.write(dep.." ")
testdep = true
end
if testdep == false then
io.write(lang.none)
end
io.write("\n")
if minepackapi then
print(lang.description.." "..mynaptic.packapi.list[getname]["description"])
end
print()
print(lang["keyContinue"])
os.pullEvent("key_up")
mynaptic.drawMenu()
end
function mynaptic.configNormal(entry,restart,default)
term.setTextColor(colors[config.menuTextColour] or colors.black)
term.setBackgroundColor(colors[config.menuBackgroundColour] or colors.white)
term.clear()
term.setCursorPos(1,1)
print(lang.newEntryText)
print()
print(lang.youEdit.." "..entry)
print()
print(lang.old.." "..config[entry])
print()
print(lang.default.." "..default)
print()
if restart == true then
print(lang.needRestart)
print()
end
write(lang.newEntry)
local input = read(nil,nil,nil,config[entry])
if not(input=="") then
config[entry] = input
end
end
function mynaptic.configColor(entry,restart,default)
term.setTextColor(colors[config.menuTextColour] or colors.black)
term.setBackgroundColor(colors[config.menuBackgroundColour] or colors.white)
term.clear()
term.setCursorPos(1,1)
print(lang.selectColour)
print()
print(lang.youEdit.." "..entry)
print()
print(lang.old.." "..config[entry])
print()
print(lang.default.." "..default)
print()
local colorta = {}
for ind in pairs(colors) do
if type(colors[ind]) == "number" then
term.setBackgroundColor(colors[ind])
write(" ")
table.insert(colorta,ind)
end
end
while true do
ev,me,x,y = os.pullEvent("mouse_click")
if y == 9 then
if type(colorta[x]) == "string" then
config[entry] = colorta[x]
break
end
end
end
end
function mynaptic.configBool(entry,restart,default)
term.setTextColor(colors[config.menuTextColour] or colors.black)
term.setBackgroundColor(colors[config.menuBackgroundColour] or colors.white)
term.clear()
term.setCursorPos(1,1)
print(lang.boolEntry)
print()
print(lang.youEdit.." "..entry)
print()
print(lang.old.." "..config[entry])
print()
print(lang.default.." "..default)
print()
term.setTextColor(colors.green)
write("true ")
term.setTextColor(colors.red)
write("false")
term.setTextColor(colors.black)
if restart == true then
print()
print()
print(lang.needRestart)
end
while true do
local ev,me,x,y = os.pullEvent("mouse_click")
if y == 9 then
if x < 5 then
config[entry] = "true"
break
elseif x > 5 and x < 11 then
config[entry] = "false"
break
end
end
end
end
function mynaptic.configKey(entry,restart,default)
term.setTextColor(colors[config.menuTextColour] or colors.black)
term.setBackgroundColor(colors[config.menuBackgroundColour] or colors.white)
term.clear()
term.setCursorPos(1,1)
print(lang.keyEntry)
print()
print(lang.youEdit.." "..entry)
print()
print(lang.old.." "..config[entry])
print()
print(lang.default.." "..default)
print()
local ev,me = os.pullEvent("key")
config[entry] = keys.getName(me)
end
function mynaptic.configScreen()
local configpos = 0
--Configloop
while true do
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.setTextColor(colors[config.menuTextColour])
term.clear()
term.setCursorPos(1,1)
for i=1,mynaptic.screenh-1 do
if type(configed[i+configpos]) == "table" then
print(configed[i+configpos]["name"])
end
end
term.setCursorPos(1,mynaptic.screenh)
term.setBackgroundColor(colors[config.bottomBarColour])
term.clearLine()
term.write( lang.ok )
term.setCursorPos(mynaptic.screenw-#lang.reset+1,mynaptic.screenh)
term.write(lang.reset)
term.setBackgroundColor(colors[config.menuBackgroundColour])
if config.showScrollArrows == "true" then
if configpos ~= 0 then
term.setCursorPos(mynaptic.screenw,1)
term.write("\30")
end
if mynaptic.configcou ~= configpos+mynaptic.screenh-1 then
term.setCursorPos(mynaptic.screenw,mynaptic.screenh-1)
term.write("\31")
end
end
local ev,me,x,y = os.pullEvent()
if ev == "mouse_scroll" or ev == "key" then
if me == 1 or me == keys[config.scrollDownKey] then
if mynaptic.configcou ~= configpos+mynaptic.screenh-1 then
configpos = configpos + 1
end
elseif me == -1 or me == keys[config.scrollUpKey] then
if configpos ~= 0 then
configpos = configpos - 1
end
end
elseif ev == "term_resize" then
mynaptic.screenw, mynaptic.screenh = term.getSize()
elseif ev == "mouse_click" then
if y == mynaptic.screenh then
if x < #lang.ok+1 then
configloop = nil
break
elseif x > mynaptic.screenw-#lang.reset then
for k,v in ipairs( configed ) do
config[v.name] = v.default
end
mynaptic.showTextWindow( lang.resetConfig )
end
elseif type(configed[configpos+y]) == "table" then
if configed[configpos+y]["contype"] == "col" then
mynaptic.configColor(configed[configpos+y]["name"],configed[configpos+y]["restart"],configed[configpos+y]["default"])
elseif configed[configpos+y]["contype"] == "bool" then
mynaptic.configBool(configed[configpos+y]["name"],configed[configpos+y]["restart"],configed[configpos+y]["default"])
elseif configed[configpos+y]["contype"] == "key" then
mynaptic.configKey(configed[configpos+y]["name"],configed[configpos+y]["restart"],configed[configpos+y]["default"])
else
mynaptic.configNormal(configed[configpos+y]["name"],configed[configpos+y]["restart"],configed[configpos+y]["default"])
end
end
end
end
--write config
local writecon = io.open(mynaptic.ops.configPath or "/etc/mynaptic","w")
for ind,con in pairs(config) do
writecon:write(ind.." "..con.."\n")
end
writecon:close()
mynaptic.drawMenu()
end
function mynaptic.helpList()
term.setBackgroundColor(colors[config.menuBackgroundColour])
term.setTextColor(colors[config.menuTextColour])
term.clear()
term.setCursorPos(1,1)
for i=1,mynaptic.screenh-1 do
if type(helpta[i+mynaptic.helpos]) == "table" then
print(helpta[i+mynaptic.helpos]["titel"])
end
end
if mynaptic.helpos ~= 0 and config.showScrollArrows == "true" then
term.setCursorPos(mynaptic.screenw,1)
term.write("\30")
end
if mynaptic.helpos+mynaptic.screenh-1 < #helpta and config.showScrollArrows == "true" then
term.setCursorPos(mynaptic.screenw,mynaptic.screenh-1)
term.write("\31")
end
term.setCursorPos(1,screenh)
term.setBackgroundColor(colors[config.bottomBarColour])
term.clearLine()
write("OK")
term.setBackgroundColor(colors[config.menuBackgroundColour])
end
function mynaptic.showHelp(num)
if type(helpta[num]["url"]) == "table" and commands and config.helpChatURL == "true" then
for k,v in ipairs(helpta[num]["url"]) do
commands.execAsync('tellraw @p ["",{"text":"'..v[1]..'","color":"blue","clickEvent":{"action":"open_url","value":"'..v[2]..'"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"'..v[2]..'"}]}}}]')
end
end
mynaptic.showTextWindow(helpta[num]["con"])
end
function mynaptic.helpMenu()
mynaptic.helpos = 0
mynaptic.helpList()
while true do
local ev,me,x,y = os.pullEvent()
if ev == "mouse_click" then
if y == screenh then
mynaptic.drawMenu()
break
elseif type(helpta[mynaptic.helpos+y]) == "table" then
mynaptic.showHelp(mynaptic.helpos+y)
mynaptic.helpList()
end
elseif ev == "mouse_scroll" then
if me == 1 then
if mynaptic.helpos+mynaptic.screenh-1 < #helpta then
mynaptic.helpos = mynaptic.helpos + 1
mynaptic.helpList()