-
Notifications
You must be signed in to change notification settings - Fork 0
/
out.ete
2494 lines (2257 loc) · 76.5 KB
/
out.ete
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
./PortOS"3"D./PortOS/bin"10"D./PortOS/bin/.bashrc"1050"F# ~/.bashrc: executed by bash for non-login shells
# this .bashrc is made for PortOS and may not reflect 100% accurately on other systems.
# conversely, other systems' .bashrc may not reflect 100% accurately on PortOS.
# If not running interactively, don't do anything
[ -z *$PS1* ] && return
# don't put duplicate lines in the history
# ... of force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
#append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS
shopt -s checkwinsize
# make less more friendly for non-text input files
[ -x /usr/bin/lesspipe ] && eval *$(SHELL=/bin/bash lesspipe)
# Uncomment for a colored prompt, if the terminal has the capability;
# turned off by default to not distract the user: the focus in a terminal
# window should be on the output of commands, not on the prompt
#force_color_prompt=yes
./PortOS/bin/apps"1"D./PortOS/bin/apps/notepad"1"D./PortOS/bin/apps/notepad/main.lua"0"F./PortOS/bin/bash.lua"2651"F--This must not rely on PortOS systems as this is the fallback in case anything breaks.
local args = {...}
if #args > 1 then
end
--Not using actual root for the root directory. This is to keep PortOS
--self contained, in case users don't want the OS taking over the whole PC
local root = "./PortOS/root"
local running = true
local insert = false
local caretPosition = 1
local currentToken = {}
local posix = false
local function split_string(str)
local output = {}
for idx,char in pairs(str) do
output[idx] = char
end
return output
end
local function parseArguments(arguments)
local aliases = {
["--dump-strings"] = "-d",
["--verbose"] = "-v",
["--init-file"] = "--rcfile"
}
local expect_args = {}
local printHelp = false
local dump_strings = false
local options = true
for _,arg in pairs(arguments) do
if options then
local current = aliases[arg] or arg
local islong = current:sub(2,2) == "-"
current = (islong and current:sub(3) or current:sub(1)):lower()
if current == "help" then
printHelp = true
elseif current == "d" then
dump_strings = true
elseif current == "rcfile" then
table.insert(expect_args, "rcfile")
elseif not islong then
for _,c in pairs(split_string(current)) do
table.insert(arguments, "-"..c)
end
else --It's long and not a recognised argument above
write("Unknown symbol \"--", current, "\"")
end
end
end
end
local function parseCommand(command)
command = command or currentToken
for _,ch in pairs(command) do
if ch == "#" then
break
end
end
end
local function listenForInput()
while running do
local data = {os.pullEvent("key")}
if data[2] == keys.enter or data[2] == keys.numPadEnter then
parseCommand()
elseif data[2] == keys.home then
caretPosition = 1
elseif data[2] == keys["end"] then
caretPosition = #currentToken
elseif data[2] == keys.insert then
insert = not insert
elseif data[2] == keys.delete and caretPosition < #currentToken then
table.remove(currentToken, caretPosition + 1)
elseif data[2] == keys.backspace and caretPosition > 1 then
table.remove(currentToken, caretPosition)
caretPosition = caretPosition - 1
elseif data[2] == keys.left and caretPosition > 1 then
caretPosition = caretPosition - 1
elseif data[2] == keys.right and caretPosition < #currentToken then
caretPosition = caretPosition + 1
else
local toAdd = keys.getName(data[2])
if #toAdd == 1 then
if insert then
currentToken[caretPosition] = toAdd
else
table.insert(currentToken, toAdd, caretPosition)
end
caretPosition = caretPosition + 1
end
end
end
end
./PortOS/bin/boot.lua"596"Fterm.clear()
term.setCursorPos(1, 1)
print("Loading libraries..")
shell.run("PortOS/bin/setup.lua")
print("Checking for updates")
print("Starting OS..")
threading:killAllThreads()
local function runShell()
term.clear()
term.setCursorPos(1, 1)
shell.run("shell")
events:stopEvents()
threading:stopThreadProcessor()
threading:killAllThreads()
end
threading:startThread(events.acceptEvents, events)
threading:startThread(shell.run, "./PortOS/bin/ux/explorer")
-- threading:startThread(runShell)
threading:startThreadProcessor()
print("Goodbye!")
sleep(1)
os.shutdown()
./PortOS/bin/data"1"D./PortOS/bin/data/default.reg"52"F{
fileHandlers = {
[ ".lua" ] = "edit",
},
}./PortOS/bin/download.lua"558"Flocal args = {...}
fs.makeDir("PortOS/Users/Global")
fs.makeDir("PortOS/Users/Global/Downloads")
local url = args[1]
if url then
if http.checkURL(url) then
local request = http.get(url)
local data = request.readAll()
request.close()
local slash = url:reverse():find("%/")
local name = url:sub(1-slash)
local file = fs.open("PortOS/Users/Global/Downloads/"..name, "w")
file.write(data)
file.close()
else
error("Invalid URL")
end
else
error("Usage: download <URL>")
end
./PortOS/bin/events.lua"3040"Flocal events = {
handleEvents = false,
threads = {}
}
local function addHandler(self, event, delegate, ...)
if type(delegate) ~= "function" then
error("Delegate expects function, received " .. type(delegate), 2)
end
if type(event) == "table" then
event = event.id
elseif type(event) ~= "string" then
error("Event expected to be a table or a string. Found "..type(event), 2)
end
if type(self[event]) ~= "table" then
self[event] = {}
end
local delegateData = {
delegate = delegate,
args = {...}
}
table.insert(self[event], delegateData)
end
events["addHandler"] = addHandler
local function removeHandler(self, event, delegate)
if type(event) == "table" then
event = event.id
end
if type(self[event]) ~= "table" then
return false
else
for idx, del in pairs(self[event]) do
if del.delegate == delegate then
table.remove(self[event], idx)
return true
end
end
return false
end
end
events["removeHandler"] = removeHandler
local function raiseEvent(self, ...)
os.queueEvent(self.id, ...)
end
local function createEvent(self)
local base = os.epoch("utc")
while self[tostring(base)] do
base = base + math.random(1000)
end
local newEvent = {
invoke = raiseEvent,
id = tostring(base)
}
self[tostring(base)] = {}
return newEvent
end
events["createEvent"] = createEvent
local function deleteEvent(self, event)
if type(event) ~= "table" then
error("Event was not a custom event", 2)
elseif event.id == nil then
error("Event was not a custom event", 2)
elseif self[event.id] == nil then
error("Event was already removed", 2)
else
self[event.id] = nil
end
end
events["deleteEvent"] = deleteEvent
local function processEvent(self, event, eventData)
if type(self[event]) == "table" then
for _, del in pairs(self[event]) do
local success, errorMsg = pcall(function()
if #del.args > 0 then
del.delegate(table.unpack(del.args), table.unpack(eventData))
else
del.delegate(table.unpack(eventData))
end
end)
if not success then
error(errorMsg, 0)
end
end
end
end
local function acceptEvents(self)
self.handleEvents = true
while self.handleEvents do
local eventData = {os.pullEvent()}
local event = eventData[1]
if event == ".portOS_cancelEvent" then
self.handleEvents = false
break
else
if self[event] then
threading:startThread(processEvent, self, event, eventData)
end
end
end
end
events["acceptEvents"] = acceptEvents
local function stopEvents()
os.queueEvent(".portOS_cancelEvent")
end
events["stopEvents"] = stopEvents
return events
./PortOS/bin/registry.lua"828"Flocal registry = {
data = {
fileHandlers = {}
},
defaultLocation = "/PortOS/bin/data/default.reg"
}
function registry.addFileHandler(type, programPath, force)
if registry.data.fileHandlers[type] == nil or force then
registry.data.fileHandlers[type] = programPath
return true
else
return false
end
end
function registry.getFileHandler(type)
if registry.data.fileHandlers then
return registry.data.fileHandlers[type]
else
return nil
end
end
function registry.save()
local file = fs.open(registry.defaultLocation, "w")
file.write(textutils.serialise(registry.data))
file.close()
end
function registry.load()
if fs.exists(registry.defaultLocation) then
local file = fs.open(registry.defaultLocation, "r")
registry.data = textutils.unserialise(file.readAll())
file.close()
end
end
return registry./PortOS/bin/setup.lua"270"Frequire(".PortOS.lib.lang.keywords")
_G["registry"] = require(".PortOS.bin.registry")
registry.load()
require(".PortOS.lib.data.table")
-- require(".PortOS.lib.data.string")
_G["threading"] = require(".PortOS.lib.threading")
_G["events"] = require(".PortOS.bin.events")
./PortOS/bin/ux"2"D./PortOS/bin/ux/entry.lua"219"Flocal app = require(".PortOS.lib.controls.application")
local textbox = require(".PortOS.lib.controls.textbox")
local label = require(".PortOS.lib.controls.label")
local button = require(".PortOS.lib.controls.button")
./PortOS/bin/ux/explorer.lua"3259"Flocal glamour = require(".PortOS.lib.glamour")
local explorer = require(".PortOS.lib.controls.explorer")
local button = require(".PortOS.lib.controls.button")
local textbox = require(".PortOS.lib.controls.textbox")
local label = require(".PortOS.lib.controls.label")
local rectangle = require(".PortOS.lib.controls.rectangle")
local app = require(".PortOS.lib.controls.application")
term.setCursorBlink(false)
local function checkFileOpeners()
if registry.getFileHandler(".lua") == nil then
registry.addFileHandler(".lua", "edit")
end
registry.save()
end
checkFileOpeners()
local myTextbox = new 'textbox'() {
ShowBorder = true,
Text = "/PortOS"
}
myTextbox.bounds {
Top = 2,
Height = 3,
Width = 51
}
local myExplorer = new 'explorer'()
myExplorer.bounds {
Width = 51,
Height = 15,
Top = 5
}
local myButton = new 'button'() {
Text = "X",
Background = colors.red,
Foreground = colors.white
}
myButton.bounds {
Left = 51,
Top = 1,
Width = 1,
Height = 1
}
local btnBack = new 'button'() {
Text = " <",
Background = colors.gray,
Foreground = colors.black
}
btnBack.bounds {
Top = 1,
Width = 2,
Height = 1,
Left = 1
}
local btnNext = new 'button'() {
Text = "> ",
Background = colors.gray,
Foreground = colors.black
}
btnNext.bounds {
Top = 1,
Width = 2,
Height = 1,
Left = 4
}
local lblSep = new 'label'() {
Text = "|",
Background = colors.lightGray
}
lblSep.bounds {
Top = 1,
Left = 3,
Width = 1
}
local rctBack = new 'rectangle'() {
Background = colors.lightGray
}
rctBack.bounds {
Top = 1,
Left = 6,
Width = 46,
Height = 1
}
local lblTitle = new 'label'() {
Text = "File Explorer",
Background = colors.lightGray,
Foreground = colors.black
}
lblTitle.bounds {
Top = 1,
Left = 7
}
local function onChangeDirectory(_, _, _, prev)
myTextbox.Text = myExplorer.fileLocation
myTextbox.updateGraphics = true
btnBack.Background = #myExplorer.history > 0 and colors.lightGray or colors.gray
btnBack.updateGraphics = true
btnNext.Background = #myExplorer.future > 0 and colors.lightGray or colors.gray
btnNext.updateGraphics = true
end
local function close()
threading:stopThreadProcessor()
Screen:stop()
end
local function navigate(_, _, key)
if key == keys.enter then
myExplorer:navigate(myTextbox.Text)
end
end
local function back()
myExplorer:navigateBack()
end
local function nxt()
myExplorer:navigateNext()
end
local function handleFileOpen(_, _, file)
myExplorer:openFile(file)
print("guh")
sleep(2)
end
events:addHandler(btnBack.Click, back)
events:addHandler(btnNext.Click, nxt)
events:addHandler(myTextbox.KeyPressed, navigate)
events:addHandler(myExplorer.changeDirectory, onChangeDirectory)
events:addHandler(myButton.Click, close)
events:addHandler(myExplorer.selectFile, handleFileOpen)
Screen = new 'app'()
Screen.Background = colors.white
Screen:addControl(myExplorer)
Screen:addControl(myTextbox)
Screen:addControl(btnBack)
Screen:addControl(btnNext)
Screen:addControl(lblSep)
Screen:addControl(rctBack)
Screen:addControl(myButton)
Screen:addControl(lblTitle)
Screen:run()
./PortOS/lib"7"D./PortOS/lib/controls"7"D./PortOS/lib/controls/application.lua"9958"Flocal control = require(".PortOS.lib.controls.control")
-- Properties and Class Definition
class 'app' {
controls = {},
_oldBounds = {},
Background = colors.black,
focusedControl = nil,
-- Rendering
getControlsInRect = function(controls, rect)
local roundRect = rect:truncate()
local output = {}
for _, c in pairs(controls) do
local roundBounds = c.bounds:truncate()
if roundBounds:intersectsWith(roundRect) then
table.insert(output, c)
end
end
return output
end,
getControlsToConsider = function(controls, idx)
local toConsider = {
behind = table.sub(controls, 1, idx - 1),
before = {}
}
local toCheck = table.sub(controls, idx - 1)
for _, c in pairs(toCheck) do
if not c.updateGraphics then
table.insert(toConsider.before, c)
end
end
return toConsider
end,
renderControl = function(self, control, idx, force)
if control.Enabled and (control.updateGraphics or force) then
control.updateGraphics = false
if control.draw then
local predrawn = false
if self["_oldBounds"][control[".screenuuid"]] then
local oldBounds = self["_oldBounds"][control[".screenuuid"]]
local dx = oldBounds.Left ~= control.bounds.Left
local dy = oldBounds.Top ~= control.bounds.Top
local dw = oldBounds.Width ~= control.bounds.Width
local dh = oldBounds.Height ~= control.bounds.Height
if dx or dy or dw or dh then
local toConsider = self.getControlsToConsider(self.controls, idx)
local toRedrawBehind = self.getControlsInRect(toConsider.behind, oldBounds)
local toRedrawBefore = self.getControlsInRect(toConsider.before, oldBounds)
paintutils.drawFilledBox(oldBounds.Left, oldBounds.Top, oldBounds.Left + oldBounds.Width - 1,
oldBounds.Top + oldBounds.Height - 1, self.Background)
for _, control in pairs(toRedrawBehind) do
control:draw()
end
control:draw()
predrawn = true
for _, control in pairs(toRedrawBefore) do
control:draw()
end
end
end
self["_oldBounds"][control[".screenuuid"]] = {
Left = control.bounds.Left,
Top = control.bounds.Top,
Width = control.bounds.Width,
Height = control.bounds.Height
}
if not predrawn then
local toRedraw = self.getControlsInRect(self.getControlsToConsider(self.controls, idx).before,
control.bounds)
control:draw()
for _, c in pairs(toRedraw) do
c:draw()
end
end
end
end
end,
draw = function(self, force)
local cursorBlink = term.getCursorBlink()
term.setCursorBlink(false)
for idx, control in pairs(self.controls) do
self.renderControl(self, control, idx, force)
end
term.setCursorBlink(cursorBlink)
end,
invalidate = function(self, force)
term.setBackgroundColor(self.Background)
term.clear()
self:draw(force)
end,
-- Click Handling
_mouseClickHandler = function(self, event, button, x, y)
local hitControl = false
for _, control in pairs(table.reverse(self.controls)) do
if control.Enabled and control.bounds.Left and control.bounds.Width and
control.bounds.Top and control.bounds.Height then
local inXBounds = control.bounds.Left <= x and control.bounds.Left + control.bounds.Width - 1 >= x
local inYBounds = control.bounds.Top <= y and control.bounds.Top + control.bounds.Height - 1 >= y
if inXBounds and inYBounds then
if self.focusedControl then
if self.focusedControl.unfocus then
self.focusedControl:unfocus(control)
end
end
local data = {
scroll = event == "mouse_scroll",
button = button,
X = 1 + x - control.bounds.Left,
Y = 1 + y - control.bounds.Top
}
self.mouseclick:invoke(control, data)
self.focusedControl = control
hitControl = true
break
end
end
end
if not hitControl then
if self.focusedControl then
if self.focusedControl.unfocus then
self.focusedControl:unfocus(control)
end
end
self.focusedControl = nil
local data = {
scroll = event == "mouse_scroll",
button = button,
X = x,
Y = y
}
self.mouseclick:invoke(nil, data)
end
end,
handleMouse = function(self)
events:addHandler("mouse_click", self._mouseClickHandler, self)
events:addHandler("mouse_scroll", self._mouseClickHandler, self)
end,
unhandleMouse = function(self)
events:removeHandler("mouse_click", self._mouseClickHandler)
events:removeHandler("mouse_scroll", self._mouseClickHandler)
end,
-- Elements
addControl = function(self, ctrl)
if ctrl.extends == nil or not ctrl:extends(control) then
error("Expected type extending Control, got "..typeof(ctrl), 2)
end
ctrl[".screenuuid"] = os.epoch("utc") - #self.controls
table.insert(self.controls, ctrl)
ctrl:bind(self)
end,
removeControl = function(self, control)
if control.extends == nil or not control:extends(control) then
error("Expected type extending Control, got "..typeof(control), 2)
end
local loc = -1
for idx, con in pairs(self.controls) do
if con[".screenuuid"] == control[".screenuuid"] then
loc = idx
break
end
end
if loc == -1 then
return false
else
if self.controls[loc].destroy then
if type(self.controls[loc].destroy) == "table" then
for _, func in pairs(self.controls[loc].destroy) do
func(self.controls[loc])
end
else
self.controls[loc]:destroy()
end
end
table.remove(self.controls, loc)
return true
end
end,
containsControl = function(self, control)
if control.extends == nil or not control:extends(control) then
error("Expected type extending Control, got "..typeof(control), 2)
end
if control[".screenuuid"] then
for _, con in pairs(self.controls) do
if con[".screenuuid"] == control[".screenuuid"] then
return true
end
end
end
return false
end,
clear = function(self)
for _, control in pairs(self.controls) do
self:removeControl(control)
end
self._oldBounds = {}
self.focusedControl = nil
end,
bringToFront = function(self, control)
if control.extends == nil or not control:extends(control) then
error("Expected type extending Control, got "..typeof(control), 2)
end
for idx, c in pairs(self.controls) do
if c[".screenuuid"] == control[".screenuuid"] then
table.remove(self.controls, idx)
break
end
end
table.insert(self.controls, control)
end,
pushToBack = function(self, control)
if control.extends == nil or not control:extends(control) then
error("Expected type extending Control, got "..typeof(control), 2)
end
for idx, c in pairs(self.controls) do
if c[".screenuuid"] == control[".screenuuid"] then
table.remove(self.controls, idx)
break
end
end
table.insert(self.controls, 1, control)
end,
-- Control
new = function(this)
this {
mouseclick = events:createEvent()
}
end,
run = function(self)
if self.threadId then
error("Application was already running! Create a copy if you want two", 2)
end
self:handleMouse()
self:invalidate()
self["threadId"] = threading:startTimer(0, self.draw, self)
end,
stop = function(self)
if self.threadId then
self:unhandleMouse()
threading:killThread(self["threadId"])
self:clear()
self.threadId = nil
end
end,
pause = function(self)
if self.threadId and not self.paused then
self:unhandleMouse()
self.paused = true
threading:pauseThread(self.threadId)
end
end,
resume = function(self)
if self.threadId and self.paused then
self:handleMouse()
self:invalidate()
threading:resumeThread(self.threadId)
self.paused = false
else
end
end
}
---@diagnostic disable-next-line: undefined-global
return app
./PortOS/lib/controls/button.lua"1061"Flocal control = require(".PortOS.lib.controls.control")
class 'button' 'control' {
Text = "Button",
Background = colors.lightGray,
Foreground = colors.black,
PressedColor = colors.gray,
draw = function(self)
paintutils.drawFilledBox(self.bounds.Left, self.bounds.Top, self.bounds.Left + self.bounds.Width - 1,
self.bounds.Top + self.bounds.Height - 1, self.Background)
term.setTextColor(self.Foreground)
local toWrite = self.Text
if #self.Text > self.bounds.Width then
local difference = #self.Text - self.bounds.Width
toWrite = self.Text:sub(difference / 2, -(difference / 2))
end
term.setCursorPos(math.ceil(self.bounds.Left + ((self.bounds.Width - #self.Text) / 2)),
math.ceil((self.bounds.Top - 1) + (self.bounds.Height / 2)))
write(toWrite)
end,
new = function(this)
this.bounds {
Width = 8,
Height = 3
}
end
}
---@diagnostic disable-next-line: undefined-global
return button
./PortOS/lib/controls/control.lua"764"Flocal rect = require ".PortOS.lib.data.rect"
class 'control' {
bounds = new 'rect'(1, 1, 1, 1),
Enabled = true,
updateGraphics = true,
clickHandler = function(self, _, control, data)
if control and type(control) == "table" and control[".screenuuid"] == self[".screenuuid"] then
self.Click:invoke(data)
end
end,
destroy = function(self)
events:removeHandler(self[".parentScreen"].mouseclick, self.clickHandler)
end,
bind = function(self, screen)
self[".parentScreen"] = screen
events:addHandler(self[".parentScreen"].mouseclick, self.clickHandler, self)
end,
new = function(this)
this {
Click = events:createEvent()
}
end
}
return control
./PortOS/lib/controls/explorer.lua"7449"Flocal control = require(".PortOS.lib.controls.control")
class 'explorer' 'control' {
NoFilesMessage = "There aren't any files here",
selectedColor = colors.lightBlue,
folderColor = colors.yellow,
fileColor = colors.blue,
background = colors.cyan,
textColor = colors.black,
border = colors.gray,
scroll = 1,
selected = -1,
timetravel = false,
sortDirectory = function(parent, fileList)
if type(parent) ~= "string" then
error("Parameter 1 'parent' expected type string, got "..typeof(parent), 2)
elseif typeof(fileList) ~= "table" then
error("Parameter 2 'fileList' expected type table, got "..typeof(fileList), 2)
end
local folders = {}
local files = {}
for _, file in pairs(fileList) do
local name = parent .. "/" .. file
if fs.isDir(name) then
table.insert(folders, file)
else
table.insert(files, file)
end
end
local output = {}
for _, folder in pairs(folders) do
table.insert(output, folder)
end
for _, file in pairs(files) do
table.insert(output, file)
end
return output
end,
draw = function(self)
if self.bounds.Width < 10 then
self.bounds.Width = 10
end
if self.bounds.Height < 5 then
self.bounds.Height = 5
end
paintutils.drawBox(self.bounds.Left, self.bounds.Top, self.bounds.Left + self.bounds.Width - 1,
self.bounds.Top + self.bounds.Height - 1, self.border)
paintutils.drawFilledBox(self.bounds.Left + 1, self.bounds.Top + 1, self.bounds.Left + self.bounds.Width - 2,
self.bounds.Top + self.bounds.Height - 2, self.background)
term.setTextColor(self.textColor)
if fs.exists(self.fileLocation) and fs.isDir(self.fileLocation) then
---@diagnostic disable-next-line: undefined-global
local files = explorer.sortDirectory(self.fileLocation, fs.list(self.fileLocation))
local upper = math.min(self.scroll + self.bounds.Height - 3, #files)
for idx = self.scroll, upper do
local file = files[idx]
local fileLoc = self.fileLocation .. "/" .. file
paintutils.drawLine(self.bounds.Left + 1, self.bounds.Top + idx - (self.scroll - 1),
self.bounds.Left + self.bounds.Width - 2, self.bounds.Top + idx - (self.scroll - 1),
self.selected == idx and self.selectedColor or self.background)
term.setCursorPos(self.bounds.Left + 1, self.bounds.Top + idx - (self.scroll - 1))
local icon = fs.isDir(fileLoc) and "#" or "O"
local iconColor = fs.isDir(fileLoc) and self.folderColor or self.fileColor
write("-")
term.setTextColor(iconColor)
write(icon .. " ")
term.setTextColor(self.textColor)
if #file > self.bounds.Width - 6 then
write(file:sub(1, self.bounds.Width - 7) .. "..")
else
write(file)
end
end
else
local noFiles = self.NoFilesMessage
local lines = string.wrap(noFiles, self.bounds.Width - 2)
for idx, line in pairs(lines) do
term.setCursorPos(self.bounds.Left + 1, self.bounds.Top + idx)
write(string.pad(line, self.bounds.Width - 2))
end
end
end,
navigate = function(self, location)
if type(location) ~= "string" then
error("Parameter 2 'location' expected type string, got "..typeof(location), 2)
end
if location and fs.exists(location) then
if location == self.fileLocation then
return false, "The explorer is already at this location"
end
if fs.isDir(location) then
if self.timetravel then
self.timetravel = false
else
table.insert(self.history, self.fileLocation)
self.future = {}
end
self.changeDirectory:invoke(self, location, self.fileLocation)
self.fileLocation = location
self.selected = -1
else
self.selectFile:invoke(self, location)
end
self.updateGraphics = true
return true
else
return false, "The location could not be found"
end
end,
navigateBack = function(self)
if #self.history > 0 then
self.timetravel = true
local togo = self.history[#self.history]
self.history[#self.history] = nil
table.insert(self.future, self.fileLocation)
return self:navigate(togo)
end
end,
navigateNext = function(self)
if #self.future > 0 then
self.timetravel = true
local togo = self.future[#self.future]
self.future[#self.future] = nil
table.insert(self.history, self.fileLocation)
return self:navigate(togo)
end
end,
click = function(self, _, data)
local files = self.sortDirectory(self.fileLocation, fs.list(self.fileLocation))
self.updateGraphics = true
if data.scroll then
if self.scroll + data.button > 0 and self.scroll + data.button < (#files - (self.bounds.Height - 4)) then
self.scroll = self.scroll + data.button
end
elseif data.button == 1 then
if data.Y == 1 or (2 + #files - self.scroll < data.Y) then
self.selected = -1