· 9 years ago · Jan 08, 2017, 05:48 PM
1--[[
2#install_file_path#:api/button
3-- Button API by FileStriker
4
5function create(anyButton, event, par1, par2, par3 ,size, isSelected, stringOptions , triggerButtons, colorOptions)
6 if anyButton then
7 return false, true
8 end
9 local bracketStart = ""
10 local bracketEnd = ""
11 local text = string.rep(" ",size)
12 local ending = ""
13 if stringOptions[1] ~= nil then
14 text = stringOptions[1]
15 end
16 if stringOptions[6] ~= nil then
17 ending = stringOptions[6]
18 end
19
20 local oldTextCol = term.getTextColor()
21 local oldBeckgroundCol = term.getBackgroundColor()
22
23 local posXStart, posYStart = term.getCursorPos()
24 if isSelected then
25 if stringOptions[4] ~= nil then
26 bracketStart = stringOptions[4]
27 end
28 if stringOptions[5] ~= nil then
29 bracketEnd = stringOptions[5]
30 end
31
32 if colorOptions[3] ~= nul then
33 screen.setTextColor(colorOptions[3])
34 end
35 if colorOptions[4] ~= nil then
36 screen.setBackgroundColor(colorOptions[4])
37 end
38
39 if size == 0 then
40 size = string.len( text ) + string.len ( bracketStart ) + string.len ( bracketEnd )
41 end
42
43 term.write(bracketStart .. stringN.cutRight(text, ending, size - string.len ( bracketStart ) - string.len ( bracketEnd ) ) .. bracketEnd)
44 else
45 if stringOptions[2] ~= nil then
46 bracketStart = stringOptions[2]
47 end
48 if stringOptions[3] ~= nil then
49 bracketEnd = stringOptions[3]
50 end
51
52 if colorOptions[1] ~= nil then
53 screen.setTextColor(colorOptions[1])
54 end
55 if colorOptions[2] ~= nil then
56 screen.setBackgroundColor(colorOptions[2])
57 end
58
59 if size == 0 then
60 size = string.len( text ) + string.len ( bracketStart ) + string.len ( bracketEnd )
61 end
62
63 term.write(bracketStart .. stringN.cutRight(text, ending, size - string.len ( bracketStart ) - string.len ( bracketEnd ) ) .. bracketEnd)
64 end
65 local posXEnd , posYEnd = term.getCursorPos()
66
67 screen.setTextColor(oldTextCol)
68 screen.setBackgroundColor(oldBeckgroundCol)
69
70 if event == "mouse_up" then
71 if par2 >= posXStart and par2 <= posXEnd and par3 == posYStart then
72 return true , true
73 end
74 elseif event == "monitor_touch" then
75 if par1 >= posXStart and par1 <= posXEnd and par2 == posYStart then
76 return true , true
77 end
78 elseif isSelected and event == "key_up" then
79 for i=1, #triggerButtons do
80 if par1 == triggerButtons[i] then
81 if anyButton then
82 return false , true
83 else
84 return true , true
85 end
86 end
87 end
88 end
89 return false , false
90end
91
92function createGroupTable(buttonGroups)
93 buttonGroups = {}
94 buttonGroups.count = 0
95 buttonGroups.current = 0
96 buttonGroups.size = {}
97 buttonGroups.selected = {}
98 return buttonGroups
99end
100
101function addGroup(size, current, buttonGroups)
102 buttonGroups.count = buttonGroups.count + 1
103 table.insert(buttonGroups.size,size)
104 table.insert(buttonGroups.selected,current)
105 return buttonGroups
106end
107
108function isSelected(index, selection, buttonGroups)
109 if index == buttonGroups.current then
110 if buttonGroups.selected[index] == selection then
111 return true
112 end
113 end
114 return false
115end
116#install_file_path#:api/fileN
117function readLines(path)
118 local file = fs.open(path, "r")
119 local lines = {}
120 local line = file.readLine()
121 while line ~= nil do
122 table.insert( lines, line )
123 line = file.readLine()
124 end
125 file.close()
126 return lines
127end
128
129function contains(content,lines)
130 for i=1,#lines do
131 if lines[i] == content then return true end
132 end
133 return false
134end
135#install_file_path#:api/list
136-- List API by FileStriker
137
138function list(intHight, intItems, intSelected)
139 if intHight >= intItems then
140 return 1, intItems
141 end
142 local intStart = math.floor(intHight / 2)
143 local intEnd = intSelected + intHight - intStart - 1
144 intStart = intSelected - intStart
145 if intEnd > intItems then
146 intStart = intItems - intHight + 1
147 intEnd = intItems
148 end
149 if intStart < 1 then
150 intEnd = intHight
151 intStart = 1
152 end
153 return intStart, intEnd
154end
155
156function scrollbar(intHight, intDisplay, intItems, intSelected)
157
158 local intPosX , intPosY = term.getCursorPos()
159
160 local intStart = 1
161 local intEnd = intHight
162 if intItems > intHight then
163 local intSize = math.floor(intDisplay / intItems * intHight)
164 local p = (intHight - intSize) / intItems
165 intStart = math.ceil(intSelected * p)
166 intEnd = intStart + intSize
167 end
168 for i = 1 ,intHight do
169 term.setCursorPos(intPosX,i + intPosY - 1)
170 if i >= intStart and i <= intEnd then
171 term.write("#")
172 else
173 term.write("|")
174 end
175 end
176end
177#install_file_path#:api/screen
178-- Screen API by FileStriker
179
180function clear(colColor)
181 width , height = term.getSize()
182 term.setCursorPos(1,1)
183 if term.isColor() then
184 term.setBackgroundColor(colColor)
185 end
186 for i=1,height do
187 term.setCursorPos(1,i)
188 term.write(string.rep(" ", width))
189 end
190 term.setCursorPos(1,1)
191end
192
193function clearLine(colColor)
194 local width , height = term.getSize()
195 local intPosX, intPosY = term.getCursorPos()
196 term.setCursorPos(1,intPosY)
197 if term.isColor() then
198 term.setBackgroundColor(colColor)
199 end
200 term.write(string.rep(" ", width))
201 term.setCursorPos(1,intPosY);
202end
203
204function setTextColor(colColor)
205 if term.isColor() then
206 term.setTextColor(colColor)
207 end
208end
209
210function setBackgroundColor(colColor)
211 if term.isColor() then
212 term.setBackgroundColor(colColor)
213 end
214end
215
216function inputField(event, par1 , strText ,intEditPos, intOffset, intSize, numberMode)
217 if event == "key" then
218 if par1 == keys.backspace then
219 if intEditPos > 0 then
220 strText = stringN.removeAt(strText, intEditPos)
221 intEditPos = intEditPos -1
222 if intEditPos < 0 then
223 intEditPos = 0
224 end
225 end
226 elseif par1 == keys.left then
227 intEditPos = intEditPos - 1
228 if intEditPos < 0 then
229 intEditPos = 0
230 end
231 elseif par1 == keys.right then
232 intEditPos = intEditPos + 1
233 if intEditPos > string.len( strText ) then
234 intEditPos = string.len( strText )
235 end
236 end
237 end
238 if event == "char" then
239 if numberMode then
240 c = tonumber(par1)
241 if c ~= nil then
242 strText = stringN.insertAt(strText,c, intEditPos)
243 intEditPos = intEditPos + 1
244 end
245 else
246 strText = stringN.insertAt(strText,par1, intEditPos)
247 intEditPos = intEditPos + 1
248 end
249 end
250 write , intOffset = stringN.getFocus (strText , intOffset , intEditPos , intSize )
251 term.write(write)
252 return strText, intEditPos, intOffset
253end
254
255local function waitInput()
256 while true do
257 event, par1, par2, par3, par4, par5 = os.pullEvent()
258 if event == "mouse_up" or event == "monitor_touch" or event == "key_up" then
259 break
260 end
261 end
262end
263
264local wTime = 0
265local function waitTime()
266 sleep(wTime)
267end
268
269function infoPopup(text,time)
270 if string.len(text) > 0 then
271 local width , height = term.getSize()
272 local part = stringN.split(text,"\n")
273 local start = math.max( math.floor( height / 2 - #part / 2) , 0 )
274 local oldColor = term.getBackgroundColor()
275 term.setCursorPos(2,start)
276 screen.setBackgroundColor(colors.yellow)
277 term.write( "+" .. string.rep( "-" , width - 4 ) .. "+" )
278 for i=1,#part do
279 term.setCursorPos(2,start + i)
280 term.write("|")
281 screen.setBackgroundColor(oldColor)
282 term.write(stringN.setCenter(part[i],"",width - 4))
283 screen.setBackgroundColor(colors.yellow)
284 term.write("|")
285 end
286 term.setCursorPos(2,start + #part + 1)
287 term.write( "+" .. string.rep( "-" , width - 4 ) .. "+" )
288 screen.setBackgroundColor(colors.white)
289 end
290 wTime = time
291 parallel.waitForAny(waitInput,waitTime)
292end
293#install_file_path#:api/startN
294function setAsStartup (path, arguments)
295 local file = fs.open("lightOS/startup/start", "w")
296 file.writeLine(path)
297 for i=1,#arguments do
298 file.writeLine(arguments[i])
299 end
300 file.close()
301end
302
303function getStartupPath ()
304 if fs.exists("lightOS/startup/start") then
305 local file = fs.open("lightOS/startup/start", "r")
306 line = file.readLine()
307 file.close()
308 return line
309 end
310 return nil
311end
312
313function removeStartup()
314 if fs.exists("lightOS/startup/start") then
315 fs.delete("lightOS/startup/start")
316 return true
317 end
318 return false
319end
320#install_file_path#:api/stringN
321function split(strText,char)
322 t = {}
323 if string.len( strText ) > 0 then
324 for s in string.gmatch(strText, "([^" .. char .. "]+)") do
325 table.insert( t, s )
326 end
327 end
328 return t
329end
330
331function insertAt(strText,char,index)
332 local strStart = string.sub( strText,1, index)
333 local strEnd = string.sub( strText,index + 1)
334 return strStart .. char .. strEnd
335end
336
337function removeAt(strText, index)
338 local strStart = string.sub( strText,1, index - 1)
339 local strEnd = string.sub( strText,index + 1)
340 return strStart .. strEnd
341end
342
343function cutRight(strText, strEnding, size)
344 intTextLenght = string.len( strText )
345 strFinalText = strText
346 if intTextLenght < size then
347 intSpace = size - intTextLenght
348 for i = 1, intSpace do
349 strFinalText = strFinalText .. " "
350 end
351 elseif intTextLenght > size then
352 local intMaxLenght = size - string.len(strEnding)
353 if intMaxLenght < 0 then
354 strFinalText = string.sub( strText, 1, size)
355 else
356 strFinalText = string.sub( strText, 1, intMaxLenght) .. strEnding
357 end
358 end
359 return strFinalText
360end
361
362function setCenter( strText , strEnding , size)
363 if string.len( strText ) > size then
364 strText = string.sub ( strText , 1 , size - string.len ( strEnding ) ) .. strEnding
365 end
366 strText = string.sub ( strText , 1 , math.min( string.len( strText ) , size ) )
367 intTextLenght = string.len( strText )
368 local intRight = size - intTextLenght
369 local intLeft = math.floor( intRight / 2 )
370 intRight = intRight - intLeft
371 return string.rep ( " " , intLeft ) .. strText .. string.rep ( " " , intRight )
372end
373
374function getFocus( strText , intOffset , intCurrent , size )
375 size = size - 2
376 local intTextLenght = string.len ( strText )
377 if intOffset + size + 1 > intTextLenght then
378 intOffset = intTextLenght - size - 1
379 end
380 if intCurrent > intOffset + size then
381 intOffset = intCurrent - size
382 end
383 if intCurrent < intOffset + math.min ( math.floor ( size / 2 ) , 5) then
384 intOffset = intCurrent - math.min ( math.floor ( size / 2 ) , 5)
385 end
386 if intOffset < 0 then
387 intOffset = 0
388 intCurrent = 0
389 end
390 return string.sub ( strText , intOffset , intOffset + size + 1 ), intOffset
391end
392
393function cutLeft(strText, strBegin, size)
394 local intTextLenght = string.len( strText )
395 local strFinalText = strText
396 if intTextLenght < size then
397 local intSpace = size - intTextLenght
398 for i = 1, intSpace do
399 strFinalText = strFinalText .. " "
400 end
401 elseif intTextLenght > size then
402 local intMaxLenght = size - string.len(strBegin)
403 if intMaxLenght < 0 then
404 strFinalText = string.sub( strText, 1, size)
405 else
406 strFinalText = strBegin .. string.sub( strText, - intMaxLenght)
407 end
408 end
409 return strFinalText
410end
411
412function endsWith(text,ending)
413 local textLenght = string.len( text )
414 local endingLenght = string.len( ending )
415 if textLenght < endingLenght then
416 return false
417 elseif textLenght == endingLenght then
418 return (text == ending)
419 else
420 return (string.sub(text,textLenght - endingLenght + 1,textLenght) == ending)
421 end
422end
423#install_file_path#:lightOS/browser/browser
424if fs.exists("lightOS/browser/download") then
425 fs.delete("lightOS/browser/download")
426end
427screen.clear(colors.white)
428screen.setTextColor(colors.black)
429shell.run("pastebin","get","ZbWvc7x9","lightOS/browser/download")
430
431local width, height = term.getSize()
432
433local anyButton = false
434local isClick = false
435local event
436local par1
437local par2
438local par3
439local par4
440local par5
441
442
443local buttonGroups
444
445local selection = 2
446
447local programs
448
449local function isType(types)
450 local parts = stringN.split(types,",")
451 for i=1,#parts do
452 if (parts[i] == "computer" and computer )
453 or (parts[i] == "turtle" and turtle)
454 or (parts[i] == "pocket" and pocket) then
455 return true
456 end
457 end
458 return false
459end
460
461local function initialize()
462 lastCurrent = 2
463 lastSelected = 1
464 if buttonGroups ~= nil then
465 lastCurrent = buttonGroups.current
466 lastSelected = buttonGroups.selected[lastCurrent]
467 elseif term.isColor() then
468 lastCurrent = 0
469 end
470
471 local lines = fileN.readLines("lightOS/browser/download")
472 programs = {}
473 programs.name = {}
474 programs.version = {}
475 programs.types = {}
476 programs.pastebin = {}
477 programs.pack = {}
478 programs.info = {}
479 for i=1,#lines do
480 local parts = stringN.split(lines[i],"$")
481 table.insert(programs.name , parts[1])
482 table.insert(programs.version , parts[2])
483 table.insert(programs.types , isType(parts[3]))
484 table.insert(programs.pastebin , parts[4])
485 table.insert(programs.pack , parts[5])
486 table.insert(programs.info , parts[6])
487 end
488
489 buttonGroups = {}
490 buttonGroups = button.createGroupTable(buttonGroups)
491 buttonGroups = button.addGroup(1,1,buttonGroups)
492 buttonGroups = button.addGroup(#programs.name,1,buttonGroups)
493 buttonGroups = button.addGroup(#programs.name,1,buttonGroups)
494
495 buttonGroups.current = lastCurrent
496 if lastCurrent > 1 then
497 buttonGroups.selected[2] = math.min(lastSelected, buttonGroups.size[2])
498 buttonGroups.selected[3] = buttonGroups.selected[2]
499 elseif lastCurrent == 1 then
500 buttonGroups.selected[1] = lastSelected
501 end
502end
503
504-- if term.isColor() then
505-- selected = 0
506-- end
507
508local function header()
509 screen.clear(colors.white)
510 screen.setTextColor(colors.black)
511 screen.clearLine(colors.lime)
512 term.write(stringN.setCenter("Browser","",width - 3))
513 screen.setBackgroundColor(colors.white)
514end
515
516if fs.exists("lightOS/browser/download") then
517 initialize()
518 header()
519 while true do
520 if event == "key" then
521 if buttonGroups.current == 0 then
522 buttonGroups.current = 1
523 elseif buttonGroups.current == 1 then
524 if par1 == keys.tab then
525 buttonGroups.current = selection
526 end
527 else
528 if par1 == keys.up or par1 == keys.w then
529 buttonGroups.selected[2] = math.max(1, buttonGroups.selected[2] - 1)
530 buttonGroups.selected[3] = buttonGroups.selected[2]
531 elseif par1 == keys.down or par1 == keys.s then
532 buttonGroups.selected[2] = math.min(buttonGroups.size[2], buttonGroups.selected[2] + 1)
533 buttonGroups.selected[3] = buttonGroups.selected[2]
534 elseif par1 == keys.left or par1 == keys.a then
535 buttonGroups.current = math.max(2, buttonGroups.current - 1)
536 elseif par1 == keys.right or par1 == keys.d then
537 buttonGroups.current = math.min(3, buttonGroups.current + 1)
538 elseif par1 == keys.tab then
539 selection = buttonGroups.current
540 buttonGroups.current = 1
541 end
542 end
543 elseif event == "mouse_scroll" then
544 if buttonGroups.current < 2 then
545 buttonGroups.current = 2
546 else
547 if par1 == -1 then
548 buttonGroups.selected[2] = math.max(1, buttonGroups.selected[2] - 1)
549 buttonGroups.selected[3] = buttonGroups.selected[2]
550 end
551 if par1 == 1 then
552 buttonGroups.selected[2] = math.min(buttonGroups.size[2], buttonGroups.selected[2] + 1)
553 buttonGroups.selected[3] = buttonGroups.selected[2]
554 end
555 end
556 end
557
558
559 if buttonGroups.current > 1 and #programs.name == 0 then
560 buttonGroups.current = 1
561 end
562
563 term.setCursorPos(width - 2,1)
564 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0, button.isSelected(1,1,buttonGroups), {"X"," "," ","[","]"},{keys.enter,keys.space},{colors.black,colors.red,colors.white,colors.red})
565 if isClick then
566 screen.clear(colors.black)
567 screen.setTextColor(colors.white)
568 break
569 end
570
571 --Up
572 term.setCursorPos(width, 3)
573 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0,false, {"-"}, {keys.enter,keys.space} , {colors.black,colors.lightBlue})
574 if isClick then
575 if buttonGroups.current < 2 then
576 buttonGroups.current = 2
577 end
578 buttonGroups.selected[2] = math.max(1, buttonGroups.selected[2] - 1)
579 buttonGroups.selected[3] = buttonGroups.selected[2]
580 end
581
582 --Down
583 term.setCursorPos(width, height)
584 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0,false, {"+"}, {keys.enter,keys.space} , {colors.black,colors.lightBlue})
585 if isClick then
586 if buttonGroups.current < 2 then
587 buttonGroups.current = 2
588 end
589 buttonGroups.selected[2] = math.min(buttonGroups.size[2], buttonGroups.selected[2] + 1)
590 buttonGroups.selected[3] = buttonGroups.selected[2]
591 end
592
593 local start, ending = list.list(height - 1, buttonGroups.size[2], buttonGroups.selected[2])
594 local line = 2
595 local linecolor = {}
596 for i = start, ending do
597 term.setCursorPos(1,line)
598 if programs.types[i] then
599 linecolor = {colors.black,colors.white,colors.black,colors.white}
600 else
601 linecolor = {colors.lightGray,colors.white,colors.lightGray,colors.white}
602 end
603 isClick , anyButton = button.create(anyButton, event,par1,par2,par3,width - 12, button.isSelected(2,i,buttonGroups), {programs.name[i]," "," ",">"," ",".."},{keys.enter,keys.space},linecolor)
604 if isClick then
605 local name = programs.name[i]
606 if programs.pack[i] == "true" then
607 name = name .. ".install"
608 end
609 print("ok")
610 shell.run("rom/programs/http/pastebin","get",programs.pastebin[i],"programs/"..name)
611 if programs.pack == "true" then
612 assert(loadfile("lightOS/explorer/open/open.install"))("programs/"..name)
613 end
614 end
615 term.write("|".. stringN.cutLeft(programs.version[i],"",5).."|")
616 isClick , anyButton = button.create(anyButton, event,par1,par2,par3,0, button.isSelected(3,i,buttonGroups), {"i"," "," ","[","]"},{keys.enter,keys.space},{colors.cyan,colors.white,colors.cyan,colors.white})
617 if isClick then
618 if startUpPath == programs.path[i] then
619 startN.removeStartup()
620 startUpPath = startN.getStartupPath()
621 else
622 os.run({}, "lightOS/startup/setAsStartup", programs.path[i])
623 startUpPath = startN.getStartupPath()
624 header()
625 end
626 end
627 term.write("|")
628 line = line + 1
629 end
630
631 for i=2,height do
632 term.setCursorPos(width - 11,i)
633 term.write("|")
634 term.setCursorPos(width - 5,i)
635 term.write("|")
636 term.setCursorPos(width - 1,i)
637 term.write("|")
638 end
639 term.setCursorPos(width,3)
640 list.scrollbar(height - 3 , height - 2 ,buttonGroups.size[2], buttonGroups.selected[1])
641
642 if anyButton then
643 anyButton = false
644 event = nil
645 par1 = nil
646 par2 = nil
647 par3 = nil
648 par4 = nil
649 par5 = nil
650 else
651 while true do
652 event, par1, par2, par3, par4, par5 = os.pullEvent()
653 if event == "mouse_click" or event == "mouse_scroll" or event == "mouse_up" or event == "monitor_touch" or event == "key" or event == "key_up" then
654 break
655 end
656 end
657 end
658
659 if event == "mouse_up" then
660 selected = 0
661 end
662
663 end
664
665end
666#install_file_path#:lightOS/explorer/edit
667-- Get file to edit
668local tArgs = { ... }
669if #tArgs == 0 then
670 print( "Usage: edit <path>" )
671 return
672end
673
674-- Error checking
675local sPath = tArgs[1]
676local bReadOnly = fs.isReadOnly( sPath )
677if fs.exists( sPath ) and fs.isDir( sPath ) then
678 print( "Cannot edit a directory." )
679 return
680end
681
682local x,y = 1,1
683local w,h = term.getSize()
684local scrollX, scrollY = 0,0
685
686local tLines = {}
687local bRunning = true
688
689-- Colours
690local highlightColour, keywordColour, commentColour, textColour, bgColour, stringColour
691if term.isColour() then
692 bgColour = colours.black
693 textColour = colours.white
694 highlightColour = colours.yellow
695 keywordColour = colours.yellow
696 commentColour = colours.green
697 stringColour = colours.red
698else
699 bgColour = colours.black
700 textColour = colours.white
701 highlightColour = colours.white
702 keywordColour = colours.white
703 commentColour = colours.white
704 stringColour = colours.white
705end
706
707-- Menus
708local bMenu = false
709local nMenuItem = 1
710local tMenuItems = {}
711if not bReadOnly then
712 table.insert( tMenuItems, "Save" )
713end
714if peripheral.find( "printer" ) then
715 table.insert( tMenuItems, "Print" )
716end
717table.insert( tMenuItems, "Exit" )
718
719local sStatus = "Press Ctrl to access menu"
720if string.len( sStatus ) > w - 5 then
721 sStatus = "Press Ctrl for menu"
722end
723
724local function load( _sPath )
725 tLines = {}
726 if fs.exists( _sPath ) then
727 local file = io.open( _sPath, "r" )
728 local sLine = file:read()
729 while sLine do
730 table.insert( tLines, sLine )
731 sLine = file:read()
732 end
733 file:close()
734 end
735
736 if #tLines == 0 then
737 table.insert( tLines, "" )
738 end
739end
740
741local function save( _sPath )
742 -- Create intervening folder
743 local sDir = _sPath:sub(1, _sPath:len() - fs.getName(_sPath):len() )
744 if not fs.exists( sDir ) then
745 fs.makeDir( sDir )
746 end
747
748 -- Save
749 local file = nil
750 local function innerSave()
751 file = fs.open( _sPath, "w" )
752 if file then
753 for n, sLine in ipairs( tLines ) do
754 file.write( sLine .. "\n" )
755 end
756 else
757 error( "Failed to open ".._sPath )
758 end
759 end
760
761 local ok, err = pcall( innerSave )
762 if file then
763 file.close()
764 end
765 return ok, err
766end
767
768local tKeywords = {
769 ["and"] = true,
770 ["break"] = true,
771 ["do"] = true,
772 ["else"] = true,
773 ["elseif"] = true,
774 ["end"] = true,
775 ["false"] = true,
776 ["for"] = true,
777 ["function"] = true,
778 ["if"] = true,
779 ["in"] = true,
780 ["local"] = true,
781 ["nil"] = true,
782 ["not"] = true,
783 ["or"] = true,
784 ["repeat"] = true,
785 ["return"] = true,
786 ["then"] = true,
787 ["true"] = true,
788 ["until"]= true,
789 ["while"] = true,
790}
791
792local function tryWrite( sLine, regex, colour )
793 local match = string.match( sLine, regex )
794 if match then
795 if type(colour) == "number" then
796 term.setTextColour( colour )
797 else
798 term.setTextColour( colour(match) )
799 end
800 term.write( match )
801 term.setTextColour( textColour )
802 return string.sub( sLine, string.len(match) + 1 )
803 end
804 return nil
805end
806
807local function writeHighlighted( sLine )
808 while string.len(sLine) > 0 do
809 sLine =
810 tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or
811 tryWrite( sLine, "^%-%-.*", commentColour ) or
812 tryWrite( sLine, "^\"\"", stringColour ) or
813 tryWrite( sLine, "^\".-[^\\]\"", stringColour ) or
814 tryWrite( sLine, "^\'\'", stringColour ) or
815 tryWrite( sLine, "^\'.-[^\\]\'", stringColour ) or
816 tryWrite( sLine, "^%[%[.-%]%]", stringColour ) or
817 tryWrite( sLine, "^[%w_]+", function( match )
818 if tKeywords[ match ] then
819 return keywordColour
820 end
821 return textColour
822 end ) or
823 tryWrite( sLine, "^[^%w_]", textColour )
824 end
825end
826
827local tCompletions
828local nCompletion
829
830local tCompleteEnv = _ENV
831local function complete( sLine )
832 -- if settings.get( "edit.autocomplete" ) then
833 -- local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.]+$" )
834 -- if nStartPos then
835 -- sLine = string.sub( sLine, nStartPos )
836 -- end
837 -- if #sLine > 0 then
838 -- return textutils.complete( sLine, tCompleteEnv )
839 -- end
840 -- end
841 return nil
842end
843
844local function recomplete()
845 local sLine = tLines[y]
846 if not bMenu and not bReadOnly and x == string.len(sLine) + 1 then
847 tCompletions = complete( sLine )
848 if tCompletions and #tCompletions > 0 then
849 nCompletion = 1
850 else
851 nCompletion = nil
852 end
853 else
854 tCompletions = nil
855 nCompletion = nil
856 end
857end
858
859local function writeCompletion( sLine )
860 if nCompletion then
861 local sCompletion = tCompletions[ nCompletion ]
862 term.setTextColor( colours.white )
863 term.setBackgroundColor( colours.grey )
864 term.write( sCompletion )
865 term.setTextColor( textColour )
866 term.setBackgroundColor( bgColour )
867 end
868end
869
870local function redrawText()
871 local cursorX, cursorY = x, y
872 for y=1,h-1 do
873 term.setCursorPos( 1 - scrollX, y )
874 term.clearLine()
875
876 local sLine = tLines[ y + scrollY ]
877 if sLine ~= nil then
878 writeHighlighted( sLine )
879 if cursorY == y and cursorX == #sLine + 1 then
880 writeCompletion()
881 end
882 end
883 end
884 term.setCursorPos( x - scrollX, y - scrollY )
885end
886
887local function redrawLine(_nY)
888 local sLine = tLines[_nY]
889 if sLine then
890 term.setCursorPos( 1 - scrollX, _nY - scrollY )
891 term.clearLine()
892 writeHighlighted( sLine )
893 if _nY == y and x == #sLine + 1 then
894 writeCompletion()
895 end
896 term.setCursorPos( x - scrollX, _nY - scrollY )
897 end
898end
899
900local function redrawMenu()
901 -- Clear line
902 term.setCursorPos( 1, h )
903 term.clearLine()
904
905 -- Draw line numbers
906 term.setCursorPos( w - string.len( "Ln "..y ) + 1, h )
907 term.setTextColour( highlightColour )
908 term.write( "Ln " )
909 term.setTextColour( textColour )
910 term.write( y )
911
912 term.setCursorPos( 1, h )
913 if bMenu then
914 -- Draw menu
915 term.setTextColour( textColour )
916 for nItem,sItem in pairs( tMenuItems ) do
917 if nItem == nMenuItem then
918 term.setTextColour( highlightColour )
919 term.write( "[" )
920 term.setTextColour( textColour )
921 term.write( sItem )
922 term.setTextColour( highlightColour )
923 term.write( "]" )
924 term.setTextColour( textColour )
925 else
926 term.write( " "..sItem.." " )
927 end
928 end
929 else
930 -- Draw status
931 term.setTextColour( highlightColour )
932 term.write( sStatus )
933 term.setTextColour( textColour )
934 end
935
936 -- Reset cursor
937 term.setCursorPos( x - scrollX, y - scrollY )
938end
939
940local tMenuFuncs = {
941 Save = function()
942 if bReadOnly then
943 sStatus = "Access denied"
944 else
945 local ok, err = save( sPath )
946 if ok then
947 sStatus="Saved to "..sPath
948 else
949 sStatus="Error saving to "..sPath
950 end
951 end
952 redrawMenu()
953 end,
954 Print = function()
955 local printer = peripheral.find( "printer" )
956 if not printer then
957 sStatus = "No printer attached"
958 return
959 end
960
961 local nPage = 0
962 local sName = fs.getName( sPath )
963 if printer.getInkLevel() < 1 then
964 sStatus = "Printer out of ink"
965 return
966 elseif printer.getPaperLevel() < 1 then
967 sStatus = "Printer out of paper"
968 return
969 end
970
971 local screenTerminal = term.current()
972 local printerTerminal = {
973 getCursorPos = printer.getCursorPos,
974 setCursorPos = printer.setCursorPos,
975 getSize = printer.getPageSize,
976 write = printer.write,
977 }
978 printerTerminal.scroll = function()
979 if nPage == 1 then
980 printer.setPageTitle( sName.." (page "..nPage..")" )
981 end
982
983 while not printer.newPage() do
984 if printer.getInkLevel() < 1 then
985 sStatus = "Printer out of ink, please refill"
986 elseif printer.getPaperLevel() < 1 then
987 sStatus = "Printer out of paper, please refill"
988 else
989 sStatus = "Printer output tray full, please empty"
990 end
991
992 term.redirect( screenTerminal )
993 redrawMenu()
994 term.redirect( printerTerminal )
995
996 local timer = os.startTimer(0.5)
997 sleep(0.5)
998 end
999
1000 nPage = nPage + 1
1001 if nPage == 1 then
1002 printer.setPageTitle( sName )
1003 else
1004 printer.setPageTitle( sName.." (page "..nPage..")" )
1005 end
1006 end
1007
1008 bMenu = false
1009 term.redirect( printerTerminal )
1010 local ok, error = pcall( function()
1011 term.scroll()
1012 for n, sLine in ipairs( tLines ) do
1013 print( sLine )
1014 end
1015 end )
1016 term.redirect( screenTerminal )
1017 if not ok then
1018 print( error )
1019 end
1020
1021 while not printer.endPage() do
1022 sStatus = "Printer output tray full, please empty"
1023 redrawMenu()
1024 sleep( 0.5 )
1025 end
1026 bMenu = true
1027
1028 if nPage > 1 then
1029 sStatus = "Printed "..nPage.." Pages"
1030 else
1031 sStatus = "Printed 1 Page"
1032 end
1033 redrawMenu()
1034 end,
1035 Exit = function()
1036 bRunning = false
1037 end
1038}
1039
1040local function doMenuItem( _n )
1041 tMenuFuncs[tMenuItems[_n]]()
1042 if bMenu then
1043 bMenu = false
1044 term.setCursorBlink( true )
1045 end
1046 redrawMenu()
1047end
1048
1049local function setCursor( newX, newY )
1050 local oldX, oldY = x, y
1051 x, y = newX, newY
1052 local screenX = x - scrollX
1053 local screenY = y - scrollY
1054
1055 local bRedraw = false
1056 if screenX < 1 then
1057 scrollX = x - 1
1058 screenX = 1
1059 bRedraw = true
1060 elseif screenX > w then
1061 scrollX = x - w
1062 screenX = w
1063 bRedraw = true
1064 end
1065
1066 if screenY < 1 then
1067 scrollY = y - 1
1068 screenY = 1
1069 bRedraw = true
1070 elseif screenY > h-1 then
1071 scrollY = y - (h-1)
1072 screenY = h-1
1073 bRedraw = true
1074 end
1075
1076 recomplete()
1077 if bRedraw then
1078 redrawText()
1079 elseif y ~= oldY then
1080 redrawLine( oldY )
1081 redrawLine( y )
1082 else
1083 redrawLine( y )
1084 end
1085 term.setCursorPos( screenX, screenY )
1086
1087 redrawMenu()
1088end
1089
1090-- Actual program functionality begins
1091load(sPath)
1092
1093term.setBackgroundColour( bgColour )
1094term.clear()
1095term.setCursorPos(x,y)
1096term.setCursorBlink( true )
1097
1098recomplete()
1099redrawText()
1100redrawMenu()
1101
1102local function acceptCompletion()
1103 if nCompletion then
1104 -- Append the completion
1105 local sCompletion = tCompletions[ nCompletion ]
1106 tLines[y] = tLines[y] .. sCompletion
1107 setCursor( x + string.len( sCompletion ), y )
1108 end
1109end
1110
1111-- Handle input
1112while bRunning do
1113 local sEvent, param, param2, param3 = os.pullEvent()
1114 if sEvent == "key" then
1115 local oldX, oldY = x, y
1116 if param == keys.up then
1117 -- Up
1118 if not bMenu then
1119 if nCompletion then
1120 -- Cycle completions
1121 nCompletion = nCompletion - 1
1122 if nCompletion < 1 then
1123 nCompletion = #tCompletions
1124 end
1125 redrawLine(y)
1126
1127 elseif y > 1 then
1128 -- Move cursor up
1129 setCursor(
1130 math.min( x, string.len( tLines[y - 1] ) + 1 ),
1131 y - 1
1132 )
1133 end
1134 end
1135
1136 elseif param == keys.down then
1137 -- Down
1138 if not bMenu then
1139 -- Move cursor down
1140 if nCompletion then
1141 -- Cycle completions
1142 nCompletion = nCompletion + 1
1143 if nCompletion > #tCompletions then
1144 nCompletion = 1
1145 end
1146 redrawLine(y)
1147
1148 elseif y < #tLines then
1149 -- Move cursor down
1150 setCursor(
1151 math.min( x, string.len( tLines[y + 1] ) + 1 ),
1152 y + 1
1153 )
1154 end
1155 end
1156
1157 elseif param == keys.tab then
1158 -- Tab
1159 if not bMenu and not bReadOnly then
1160 if nCompletion and x == string.len(tLines[y]) + 1 then
1161 -- Accept autocomplete
1162 acceptCompletion()
1163 else
1164 -- Indent line
1165 local sLine = tLines[y]
1166 tLines[y] = string.sub(sLine,1,x-1) .. " " .. string.sub(sLine,x)
1167 setCursor( x + 2, y )
1168 end
1169 end
1170
1171 elseif param == keys.pageUp then
1172 -- Page Up
1173 if not bMenu then
1174 -- Move up a page
1175 local newY
1176 if y - (h - 1) >= 1 then
1177 newY = y - (h - 1)
1178 else
1179 newY = 1
1180 end
1181 setCursor(
1182 math.min( x, string.len( tLines[newY] ) + 1 ),
1183 newY
1184 )
1185 end
1186
1187 elseif param == keys.pageDown then
1188 -- Page Down
1189 if not bMenu then
1190 -- Move down a page
1191 local newY
1192 if y + (h - 1) <= #tLines then
1193 newY = y + (h - 1)
1194 else
1195 newY = #tLines
1196 end
1197 local newX = math.min( x, string.len( tLines[newY] ) + 1 )
1198 setCursor( newX, newY )
1199 end
1200
1201 elseif param == keys.home then
1202 -- Home
1203 if not bMenu then
1204 -- Move cursor to the beginning
1205 if x > 1 then
1206 setCursor(1,y)
1207 end
1208 end
1209
1210 elseif param == keys["end"] then
1211 -- End
1212 if not bMenu then
1213 -- Move cursor to the end
1214 local nLimit = string.len( tLines[y] ) + 1
1215 if x < nLimit then
1216 setCursor( nLimit, y )
1217 end
1218 end
1219
1220 elseif param == keys.left then
1221 -- Left
1222 if not bMenu then
1223 if x > 1 then
1224 -- Move cursor left
1225 setCursor( x - 1, y )
1226 elseif x==1 and y>1 then
1227 setCursor( string.len( tLines[y-1] ) + 1, y - 1 )
1228 end
1229 else
1230 -- Move menu left
1231 nMenuItem = nMenuItem - 1
1232 if nMenuItem < 1 then
1233 nMenuItem = #tMenuItems
1234 end
1235 redrawMenu()
1236 end
1237
1238 elseif param == keys.right then
1239 -- Right
1240 if not bMenu then
1241 local nLimit = string.len( tLines[y] ) + 1
1242 if x < nLimit then
1243 -- Move cursor right
1244 setCursor( x + 1, y )
1245 elseif nCompletion and x == string.len(tLines[y]) + 1 then
1246 -- Accept autocomplete
1247 acceptCompletion()
1248 elseif x==nLimit and y<#tLines then
1249 -- Go to next line
1250 setCursor( 1, y + 1 )
1251 end
1252 else
1253 -- Move menu right
1254 nMenuItem = nMenuItem + 1
1255 if nMenuItem > #tMenuItems then
1256 nMenuItem = 1
1257 end
1258 redrawMenu()
1259 end
1260
1261 elseif param == keys.delete then
1262 -- Delete
1263 if not bMenu and not bReadOnly then
1264 local nLimit = string.len( tLines[y] ) + 1
1265 if x < nLimit then
1266 local sLine = tLines[y]
1267 tLines[y] = string.sub(sLine,1,x-1) .. string.sub(sLine,x+1)
1268 recomplete()
1269 redrawLine(y)
1270 elseif y<#tLines then
1271 tLines[y] = tLines[y] .. tLines[y+1]
1272 table.remove( tLines, y+1 )
1273 recomplete()
1274 redrawText()
1275 end
1276 end
1277
1278 elseif param == keys.backspace then
1279 -- Backspace
1280 if not bMenu and not bReadOnly then
1281 if x > 1 then
1282 -- Remove character
1283 local sLine = tLines[y]
1284 tLines[y] = string.sub(sLine,1,x-2) .. string.sub(sLine,x)
1285 setCursor( x - 1, y )
1286 elseif y > 1 then
1287 -- Remove newline
1288 local sPrevLen = string.len( tLines[y-1] )
1289 tLines[y-1] = tLines[y-1] .. tLines[y]
1290 table.remove( tLines, y )
1291 setCursor( sPrevLen + 1, y - 1 )
1292 redrawText()
1293 end
1294 end
1295
1296 elseif param == keys.enter then
1297 -- Enter
1298 if not bMenu and not bReadOnly then
1299 -- Newline
1300 local sLine = tLines[y]
1301 local _,spaces=string.find(sLine,"^[ ]+")
1302 if not spaces then
1303 spaces=0
1304 end
1305 tLines[y] = string.sub(sLine,1,x-1)
1306 table.insert( tLines, y+1, string.rep(' ',spaces)..string.sub(sLine,x) )
1307 setCursor( spaces + 1, y + 1 )
1308 redrawText()
1309
1310 elseif bMenu then
1311 -- Menu selection
1312 doMenuItem( nMenuItem )
1313
1314 end
1315
1316 elseif param == keys.leftCtrl or param == keys.rightCtrl or param == keys.rightAlt then
1317 -- Menu toggle
1318 bMenu = not bMenu
1319 if bMenu then
1320 term.setCursorBlink( false )
1321 else
1322 term.setCursorBlink( true )
1323 end
1324 redrawMenu()
1325
1326 end
1327
1328 elseif sEvent == "char" then
1329 if not bMenu and not bReadOnly then
1330 -- Input text
1331 local sLine = tLines[y]
1332 tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)
1333 setCursor( x + 1, y )
1334
1335 elseif bMenu then
1336 -- Select menu items
1337 for n,sMenuItem in ipairs( tMenuItems ) do
1338 if string.lower(string.sub(sMenuItem,1,1)) == string.lower(param) then
1339 doMenuItem( n )
1340 break
1341 end
1342 end
1343 end
1344
1345 elseif sEvent == "paste" then
1346 if not bMenu and not bReadOnly then
1347 -- Input text
1348 local sLine = tLines[y]
1349 tLines[y] = string.sub(sLine,1,x-1) .. param .. string.sub(sLine,x)
1350 setCursor( x + string.len( param ), y )
1351 end
1352
1353 elseif sEvent == "mouse_click" then
1354 if not bMenu then
1355 if param == 1 then
1356 -- Left click
1357 local cx,cy = param2, param3
1358 if cy < h then
1359 local newY = math.min( math.max( scrollY + cy, 1 ), #tLines )
1360 local newX = math.min( math.max( scrollX + cx, 1 ), string.len( tLines[newY] ) + 1 )
1361 setCursor( newX, newY )
1362 end
1363 end
1364 end
1365
1366 elseif sEvent == "mouse_scroll" then
1367 if not bMenu then
1368 if param == -1 then
1369 -- Scroll up
1370 if scrollY > 0 then
1371 -- Move cursor up
1372 scrollY = scrollY - 1
1373 redrawText()
1374 end
1375
1376 elseif param == 1 then
1377 -- Scroll down
1378 local nMaxScroll = #tLines - (h-1)
1379 if scrollY < nMaxScroll then
1380 -- Move cursor down
1381 scrollY = scrollY + 1
1382 redrawText()
1383 end
1384
1385 end
1386 end
1387
1388 elseif sEvent == "term_resize" then
1389 w,h = term.getSize()
1390 setCursor( x, y )
1391 redrawMenu()
1392 redrawText()
1393
1394 end
1395end
1396
1397-- Cleanup
1398term.clear()
1399term.setCursorBlink( false )
1400term.setCursorPos( 1, 1 )
1401#install_file_path#:lightOS/explorer/editFile
1402path = ...
1403if path == nil then
1404 path = ""
1405end
1406local startUpPath = startN.getStartupPath()
1407
1408local text = fs.getName(path)
1409local intEditPos = string.len( text )
1410local intOffset = 0
1411
1412local intSelected = 6
1413
1414local width, intHight = term.getSize()
1415
1416local clicked = false
1417local anyButtonClicked = false
1418
1419local event = nil
1420local par1 = nil
1421local par2 = nil
1422local par3 = nil
1423local par4 = nil
1424local par5 = nil
1425
1426
1427function header()
1428 screen.clear(colors.white)
1429 screen.setTextColor(colors.black)
1430 screen.setBackgroundColor(colors.lime)
1431 term.write ( stringN.setCenter ( fs.getName(path), ".." , width - 3 ) )
1432 screen.setBackgroundColor(colors.white)
1433 term.setCursorPos(1,2)
1434 term.write("Path: ")
1435 if string.len( path ) == 0 then
1436 term.write("Root")
1437 else
1438 term.write(stringN.cutLeft(path, "..", width - 6))
1439 end
1440 screen.setBackgroundColor(colors.blue)
1441 term.setCursorPos(1,4)
1442 term.write("+" .. string.rep("-" , width - 2) .. "+")
1443 term.setCursorPos(1,5)
1444 term.write(string.rep("|" , width))
1445 term.setCursorPos(1,6)
1446 term.write("+" .. string.rep("-" , width - 2) .. "+")
1447 screen.setBackgroundColor(colors.white)
1448end
1449
1450header()
1451
1452while true do
1453 if event == "key" then
1454 if intSelected == 0 then
1455 intSelected = 4
1456 elseif intSelected == 1 then
1457 if par1 == keys.tab then
1458 intSelected = 8
1459 elseif par1 == keys.down or par1 == keys.s then
1460 intSelected = 2
1461 end
1462 elseif intSelected == 2 then
1463 if par1 == keys.up or par1 == keys.tab then
1464 intSelected = 1
1465 elseif par1 == keys.down then
1466 intSelected = 3
1467 end
1468 elseif intSelected == 3 then
1469 if par1 == keys.up or par1 == keys.w or par1 == keys.tab then
1470 intSelected = 2
1471 elseif par1 == keys.down or par1 == keys.s then
1472 intSelected = 6
1473 elseif par1 == keys.right or par1 == keys.d then
1474 intSelected = 4
1475 end
1476 elseif intSelected == 4 then
1477 if par1 == keys.up or par1 == keys.w then
1478 intSelected = 2
1479 elseif par1 == keys.down or par1 == keys.s then
1480 intSelected = 7
1481 elseif par1 == keys.left or par1 == keys.a or par1 == keys.tab then
1482 intSelected = 3
1483 elseif par1 == keys.right or par1 == keys.d then
1484 intSelected = 5
1485 end
1486 elseif intSelected == 5 then
1487 if par1 == keys.up or par1 == keys.w then
1488 intSelected = 2
1489 elseif par1 == keys.left or par1 == keys.a or par1 == keys.tab then
1490 intSelected = 4
1491 elseif par1 == keys.down or par1 == keys.s then
1492 intSelected = 8
1493 end
1494 elseif intSelected == 6 then
1495 if par1 == keys.up or par1 == keys.w then
1496 intSelected = 3
1497 elseif par1 == keys.tab then
1498 intSelected = 5
1499 elseif par1 == keys.right or par1 == keys.d then
1500 intSelected = 7
1501 end
1502 elseif intSelected == 7 then
1503 if par1 == keys.up or par1 == keys.w then
1504 intSelected = 4
1505 elseif par1 == keys.left or par1 == keys.a or par1 == keys.tab then
1506 intSelected = 6
1507 elseif par1 == keys.right or par1 == keys.d then
1508 intSelected = 8
1509 end
1510 elseif intSelected == 8 then
1511 if par1 == keys.up or par1 == keys.w then
1512 intSelected = 5
1513 elseif par1 == keys.left or par1 == keys.a or par1 == keys.tab then
1514 intSelected = 7
1515 end
1516 end
1517 elseif event == "mouse_click" then
1518 intSelected = 0
1519 end
1520
1521 screen.setBackgroundColor(colors.white)
1522 screen.setTextColor(colors.black)
1523
1524 screen.setBackgroundColor(colors.white)
1525 screen.setTextColor(colors.black)
1526
1527 term.setCursorPos(width - 2, 1)
1528 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 1), {"X"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.red,colors.white,colors.red})
1529 if clicked then
1530 term.setCursorBlink(false)
1531 screen.clear(colors.black)
1532 screen.setTextColor(colors.white)
1533 break
1534 end
1535
1536 if event == "mouse_click" then
1537 if par2 >= 1 and par2 <= width and par3 >= 4 and par3 <= 6 then
1538 clicked = true
1539 anyButtonClicked = true
1540 end
1541 elseif event == "monitor_touch" then
1542 if par1 >= 1 and par1 <= width and par2 >= 4 and par2 <= 6 then
1543 clicked = true
1544 anyButtonClicked = true
1545 end
1546 elseif event == "key_up" and intSelected == 2 then
1547 if par1 == keys.enter then
1548 clicked = true
1549 anyButtonClicked = true
1550 end
1551 end
1552 if clicked then
1553 if par1 == keys.enter then
1554 term.setCursorBlink(false)
1555 local newPath = string.sub(path,0, - string.len( fs.getName( path ) ) - 1 ) .. text
1556 if fs.exists(newPath) then
1557 screen.infoPopup("File allreayd exists!",5)
1558 text = fs.getName(path)
1559 intEditPos = string.len( fs.getName(path) )
1560 intOffset = 0
1561 header()
1562 else
1563 fs.move(path, newPath)
1564 term.setCursorBlink(false)
1565 screen.clear(colors.black)
1566 screen.setTextColor(colors.white)
1567 break
1568 end
1569 else
1570 intSelected = 2
1571 end
1572 end
1573
1574 term.setCursorPos(2, 8)
1575 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 3), {"Move"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1576 if clicked then
1577 ret = assert(loadfile("lightOS/explorer/explorer"))("open_folder",string.sub(path,0, - string.len( fs.getName( path ) ) - 1 ))
1578 if ret ~= nil then
1579 if fs.exists(ret) then
1580 screen.setBackgroundColor(colors.white)
1581 screen.infoPopup("Unable to move the File.\nFile allready exists in\nthe selected Folder",5)
1582 else
1583 fs.move(path,ret .. fs.getName(path))
1584 screen.infoPopup("Moved the File!",5)
1585 screen.clear(colors.white)
1586 screen.setTextColor(colors.black)
1587 term.setCursorBlink(false)
1588 break
1589 end
1590 end
1591 header()
1592 end
1593
1594 term.setCursorPos(10, 8)
1595 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 4), {"Copy"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1596 if clicked then
1597 ret = assert(loadfile("lightOS/explorer/explorer"))("open_folder",string.sub(path,0, - string.len( fs.getName( path ) ) - 1 ),"openFolder")
1598 if ret ~= nil then
1599 ret = ret .. fs.getName(path)
1600 if fs.exists(ret) then
1601 ret = ret .. " copy"
1602 if fs.exists(ret) then
1603 i = 2
1604 while fs.exists(ret .. "(" .. i .. ")") do
1605 i = i + 1
1606 end
1607 ret = ret .. "(" .. i .. ")"
1608 end
1609 end
1610 fs.copy(path,ret)
1611 term.setCursorBlink(false)
1612 screen.infoPopup("Copy created!",5)
1613 screen.clear(colors.black)
1614 screen.setTextColor(colors.white)
1615 break
1616 end
1617 header()
1618 end
1619
1620 term.setCursorPos(18, 8)
1621 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 5), {"Delete"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1622 if clicked then
1623 fs.delete(path)
1624 term.setCursorBlink(false)
1625 screen.clear(colors.black)
1626 screen.setTextColor(colors.white)
1627 break
1628 end
1629
1630 term.setCursorPos(2, 10)
1631 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 6), {"Exit"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1632 if clicked then
1633 term.setCursorBlink(false)
1634 screen.clear(colors.black)
1635 screen.setTextColor(colors.white)
1636 break
1637 end
1638
1639 term.setCursorPos(10, 10)
1640 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 7), {"Edit"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1641 if clicked then
1642 screen.clear(colors.black)
1643 screen.setTextColor(colors.white)
1644 os.run({},"lightOS/explorer/edit", path)
1645 header()
1646 end
1647
1648 if startUpPath == path then
1649 term.setCursorPos(18, 10)
1650 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 8), {"Remove"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1651 if clicked then
1652 startN.removeStartup()
1653 startUpPath = startN.getStartupPath()
1654 screen.setBackgroundColor(colors.white)
1655 end
1656 term.write(" ")
1657 else
1658 term.setCursorPos(18, 10)
1659 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 8), {"Startup"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1660 if clicked then
1661 os.run({},"lightOS/startup/setAsStartup",path)
1662 header()
1663 startUpPath = startN.getStartupPath()
1664 end
1665 end
1666
1667 if intSelected == 2 then
1668 term.setCursorBlink(true)
1669 screen.setTextColor(colors.white)
1670 screen.setBackgroundColor(colors.blue)
1671 term.setCursorPos(1,4)
1672 term.write("+[Rename]" .. string.rep("-" , width - 10) .. "+")
1673 term.setCursorPos(1,5)
1674 term.write(string.rep("|" , width))
1675 term.setCursorPos(1,6)
1676 term.write("+" .. string.rep("-" , width - 2) .. "+")
1677 screen.setBackgroundColor(colors.white)
1678 screen.setTextColor(colors.black)
1679 term.setCursorPos(2,5)
1680 term.write(string.rep(" ", width - 2))
1681 term.setCursorPos(2,5)
1682 text , intEditPos, intOffset = screen.inputField ( event, par1, text , intEditPos, intOffset, width - 2)
1683 text = string.gsub( text, " ","_" )
1684 else
1685 term.setCursorBlink(false)
1686 screen.setTextColor(colors.black)
1687 screen.setBackgroundColor(colors.blue)
1688 term.setCursorPos(1,4)
1689 term.write("+-Rename" .. string.rep("-" , width - 9) .. "+")
1690 term.setCursorPos(1,5)
1691 term.write(string.rep("|" , width))
1692 term.setCursorPos(1,6)
1693 term.write("+" .. string.rep("-" , width - 2) .. "+")
1694 screen.setBackgroundColor(colors.white)
1695
1696 term.setCursorPos(2,5)
1697 term.write(stringN.cutRight(text,"..",width - 2))
1698 end
1699
1700 if intSelected == 2 and ((text ~= fs.getName(path) and fs.exists(string.sub(path,0, - string.len( fs.getName( path ) ) - 1 ) .. text)) or string.len( string.gsub(text, " ", "") ) < 1) then
1701 screen.setBackgroundColor(colors.red)
1702 screen.setTextColor(colors.black)
1703 term.setCursorPos(1,12)
1704 term.write("+-Problem:" .. string.rep("-" , width - 11) .. "+")
1705 term.setCursorPos(1,13)
1706 term.write(string.rep("|" , width))
1707 term.setCursorPos(1,14)
1708 term.write(string.rep("|" , width))
1709 term.setCursorPos(1,15)
1710 term.write("+" .. string.rep("-" , width - 2) .. "+")
1711 screen.setBackgroundColor(colors.white)
1712 term.setCursorPos(2,13)
1713 term.write(stringN.setCenter("File already exist", "",width - 2))
1714 term.setCursorPos(2,14)
1715 term.write(stringN.setCenter("enter another Name", "",width - 2))
1716 else
1717 term.setCursorPos(1,12)
1718 term.write( string.rep(" ",width))
1719 term.setCursorPos(1,13)
1720 term.write( string.rep(" ",width))
1721 term.setCursorPos(1,14)
1722 term.write( string.rep(" ",width))
1723 term.setCursorPos(1,15)
1724 term.write( string.rep(" ",width))
1725 end
1726
1727 term.setCursorPos(intEditPos - intOffset + 2, 5)
1728
1729 if anyButtonClicked then
1730 anyButtonClicked = false
1731 event = nil
1732 par1 = nil
1733 par2 = nil
1734 par3 = nil
1735 par4 = nil
1736 par5 = nil
1737 else
1738 while true do
1739 event, par1, par2, par3, par4, par5 = os.pullEvent()
1740 if event == "mouse_click" or event == "mouse_up" or event == "mouse_scroll" or event == "monitor_touch" or event == "key" or event == "key_up" or event == "char" then
1741 break
1742 end
1743 end
1744 end
1745end
1746#install_file_path#:lightOS/explorer/editFolder
1747path = ...
1748if path == nil then
1749 path = ""
1750end
1751local startUpPath = startN.getStartupPath()
1752
1753local text = fs.getName(path)
1754local intEditPos = string.len( text )
1755local intOffset = 0
1756
1757local intSelected = 6
1758
1759local width, intHight = term.getSize()
1760
1761local clicked = false
1762local anyButtonClicked = false
1763
1764local event = nil
1765local par1 = nil
1766local par2 = nil
1767local par3 = nil
1768local par4 = nil
1769local par5 = nil
1770
1771function header()
1772 screen.clear(colors.white)
1773 screen.setTextColor(colors.black)
1774 screen.setBackgroundColor(colors.lime)
1775 term.write ( stringN.setCenter ( fs.getName(path), ".." , width - 3 ) )
1776 screen.setBackgroundColor(colors.white)
1777 term.setCursorPos(1,2)
1778 term.write("Path: ")
1779 if string.len( path ) == 0 then
1780 term.write("Root")
1781 else
1782 term.write(stringN.cutLeft(path, "..", width - 6))
1783 end
1784 screen.setBackgroundColor(colors.blue)
1785 term.setCursorPos(1,4)
1786 term.write("+" .. string.rep("-" , width - 2) .. "+")
1787 term.setCursorPos(1,5)
1788 term.write(string.rep("|" , width))
1789 term.setCursorPos(1,6)
1790 term.write("+" .. string.rep("-" , width - 2) .. "+")
1791 screen.setBackgroundColor(colors.white)
1792end
1793
1794header()
1795
1796while true do
1797 if event == "key" then
1798 if intSelected == 0 then
1799 intSelected = 4
1800 elseif intSelected == 1 then
1801 if par1 == keys.tab then
1802 intSelected = 6
1803 elseif par1 == keys.down or par1 == keys.s then
1804 intSelected = 2
1805 end
1806 elseif intSelected == 2 then
1807 if par1 == keys.up or par1 == keys.tab then
1808 intSelected = 1
1809 elseif par1 == keys.down then
1810 intSelected = 3
1811 end
1812 elseif intSelected == 3 then
1813 if par1 == keys.up or par1 == keys.w or par1 == keys.tab then
1814 intSelected = 2
1815 elseif par1 == keys.down or par1 == keys.s then
1816 intSelected = 6
1817 elseif par1 == keys.right or par1 == keys.d then
1818 intSelected = 4
1819 end
1820 elseif intSelected == 4 then
1821 if par1 == keys.up or par1 == keys.w then
1822 intSelected = 2
1823 elseif par1 == keys.down or par1 == keys.s then
1824 intSelected = 6
1825 elseif par1 == keys.left or par1 == keys.a or par1 == keys.tab then
1826 intSelected = 3
1827 elseif par1 == keys.right or par1 == keys.d then
1828 intSelected = 5
1829 end
1830 elseif intSelected == 5 then
1831 if par1 == keys.up or par1 == keys.w then
1832 intSelected = 2
1833 elseif par1 == keys.left or par1 == keys.a or par1 == keys.tab then
1834 intSelected = 4
1835 elseif par1 == keys.down or par1 == keys.s then
1836 intSelected = 6
1837 end
1838 elseif intSelected == 6 then
1839 if par1 == keys.up or par1 == keys.w then
1840 intSelected = 3
1841 elseif par1 == keys.tab then
1842 intSelected = 5
1843 end
1844 end
1845 elseif event == "mouse_click" then
1846 intSelected = 0
1847 end
1848
1849 screen.setBackgroundColor(colors.white)
1850 screen.setTextColor(colors.black)
1851
1852 screen.setBackgroundColor(colors.white)
1853 screen.setTextColor(colors.black)
1854
1855 term.setCursorPos(width - 2, 1)
1856 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 1), {"X"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.red,colors.white,colors.red})
1857 if clicked then
1858 term.setCursorBlink(false)
1859 screen.clear(colors.black)
1860 screen.setTextColor(colors.white)
1861 break
1862 end
1863
1864 if event == "mouse_click" then
1865 if par2 >= 1 and par2 <= width and par3 >= 4 and par3 <= 6 then
1866 clicked = true
1867 anyButtonClicked = true
1868 end
1869 elseif event == "monitor_touch" then
1870 if par1 >= 1 and par1 <= width and par2 >= 4 and par2 <= 6 then
1871 clicked = true
1872 anyButtonClicked = true
1873 end
1874 elseif event == "key_up" and intSelected == 2 then
1875 if par1 == keys.enter then
1876 clicked = true
1877 anyButtonClicked = true
1878 end
1879 end
1880 if clicked then
1881 if par1 == keys.enter then
1882 term.setCursorBlink(false)
1883 local newPath = string.sub(path,0, - string.len( fs.getName( path ) ) - 2 ) .. text .. "/"
1884 if fs.exists(newPath) then
1885 screen.infoPopup("Folder allreayd exists!",5)
1886 text = fs.getName(path)
1887 intEditPos = string.len( fs.getName(path) )
1888 intOffset = 0
1889 header()
1890 else
1891 fs.move(path, newPath)
1892 term.setCursorBlink(false)
1893 screen.clear(colors.black)
1894 screen.setTextColor(colors.white)
1895 break
1896 end
1897 else
1898 intSelected = 2
1899 end
1900 end
1901
1902 term.setCursorPos(2, 8)
1903 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 3), {"Move"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1904 if clicked then
1905 ret = assert(loadfile("lightOS/explorer/explorer"))("open_folder",string.sub(path,0, - string.len( fs.getName( path ) ) - 2 ))
1906 ret = ret .. fs.getName( path ) .. "/"
1907 if ret ~= nil then
1908 if fs.exists(ret) then
1909 screen.setBackgroundColor(colors.white)
1910 screen.infoPopup("Unable to move the Folder.\nFolder allready exists in\nthe selected Folder",5)
1911 else
1912 fs.move(path,ret .. fs.getName(path) .. "/")
1913 screen.infoPopup("Moved the Folder!",5)
1914 term.setCursorBlink(false)
1915 screen.clear(colors.white)
1916 screen.setTextColor(colors.black)
1917 break
1918 end
1919 end
1920 header()
1921 end
1922
1923 term.setCursorPos(10, 8)
1924 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 4), {"Copy"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1925 if clicked then
1926 ret = assert(loadfile("lightOS/explorer/explorer"))("open_folder",string.sub(path,0, - string.len( fs.getName( path ) ) - 2 ))
1927 if ret ~= nil then
1928 ret = ret .. fs.getName(path) .. "/"
1929 if fs.exists(ret) then
1930 ret = string.sub(ret,0,string.len(ret) - 1) .. " copy"
1931 if fs.exists(ret .. "/") then
1932 i = 2
1933 while fs.exists(ret .. "(" .. i .. ")/") do
1934 i = i + 1
1935 end
1936 ret = ret .. "(" .. i .. ")/"
1937 end
1938 end
1939 fs.copy(path,ret)
1940 screen.infoPopup("Copy created!",5)
1941 term.setCursorBlink(false)
1942 screen.clear(colors.black)
1943 screen.setTextColor(colors.white)
1944 break
1945 end
1946 header()
1947 end
1948
1949 term.setCursorPos(18, 8)
1950 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 5), {"Delete"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1951 if clicked then
1952 fs.delete(path)
1953 term.setCursorBlink(false)
1954 screen.clear(colors.black)
1955 screen.setTextColor(colors.white)
1956 break
1957 end
1958
1959 term.setCursorPos(2, 10)
1960 clicked , anyButtonClicked = button.create(anyButtonClicked , event, par1,par2,par3,0,(intSelected == 6), {"Exit"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.gray,colors.orange,colors.gray})
1961 if clicked then
1962 term.setCursorBlink(false)
1963 screen.clear(colors.black)
1964 screen.setTextColor(colors.white)
1965 break
1966 end
1967
1968 if intSelected == 2 then
1969 term.setCursorBlink(true)
1970 screen.setTextColor(colors.white)
1971 screen.setBackgroundColor(colors.blue)
1972 term.setCursorPos(1,4)
1973 term.write("+[Rename]" .. string.rep("-" , width - 10) .. "+")
1974 term.setCursorPos(1,5)
1975 term.write(string.rep("|" , width))
1976 term.setCursorPos(1,6)
1977 term.write("+" .. string.rep("-" , width - 2) .. "+")
1978 screen.setBackgroundColor(colors.white)
1979 screen.setTextColor(colors.black)
1980 term.setCursorPos(2,5)
1981 term.write(string.rep(" ", width - 2))
1982 term.setCursorPos(2,5)
1983 text , intEditPos, intOffset = screen.inputField ( event, par1, text , intEditPos, intOffset, width - 2)
1984 text = string.gsub( text, " ","_" )
1985 else
1986 term.setCursorBlink(false)
1987 screen.setTextColor(colors.black)
1988 screen.setBackgroundColor(colors.blue)
1989 term.setCursorPos(1,4)
1990 term.write("+-Rename" .. string.rep("-" , width - 9) .. "+")
1991 term.setCursorPos(1,5)
1992 term.write(string.rep("|" , width))
1993 term.setCursorPos(1,6)
1994 term.write("+" .. string.rep("-" , width - 2) .. "+")
1995 screen.setBackgroundColor(colors.white)
1996
1997 term.setCursorPos(2,5)
1998 term.write(stringN.cutRight(text,"..",width - 2))
1999 end
2000
2001 if intSelected == 2 and ((text ~= fs.getName(path) and fs.exists(string.sub(path,0, - string.len( fs.getName( path ) ) - 1 ) .. text)) or string.len( string.gsub(text, " ", "") ) < 1) then
2002 screen.setBackgroundColor(colors.red)
2003 screen.setTextColor(colors.black)
2004 term.setCursorPos(1,12)
2005 term.write("+-Problem:" .. string.rep("-" , width - 11) .. "+")
2006 term.setCursorPos(1,13)
2007 term.write(string.rep("|" , width))
2008 term.setCursorPos(1,14)
2009 term.write(string.rep("|" , width))
2010 term.setCursorPos(1,15)
2011 term.write("+" .. string.rep("-" , width - 2) .. "+")
2012 screen.setBackgroundColor(colors.white)
2013 term.setCursorPos(2,13)
2014 term.write(stringN.setCenter("Folder already exist", "",width - 2))
2015 term.setCursorPos(2,14)
2016 term.write(stringN.setCenter("enter another Name", "",width - 2))
2017 else
2018 term.setCursorPos(1,12)
2019 term.write( string.rep(" ",width))
2020 term.setCursorPos(1,13)
2021 term.write( string.rep(" ",width))
2022 term.setCursorPos(1,14)
2023 term.write( string.rep(" ",width))
2024 term.setCursorPos(1,15)
2025 term.write( string.rep(" ",width))
2026 end
2027
2028 term.setCursorPos(intEditPos - intOffset + 2, 5)
2029
2030 if anyButtonClicked then
2031 anyButtonClicked = false
2032 event = nil
2033 par1 = nil
2034 par2 = nil
2035 par3 = nil
2036 par4 = nil
2037 par5 = nil
2038 else
2039 while true do
2040 event, par1, par2, par3, par4, par5 = os.pullEvent()
2041 if event == "mouse_click" or event == "mouse_up" or event == "mouse_scroll" or event == "monitor_touch" or event == "key" or event == "key_up" or event == "char" then
2042 break
2043 end
2044 end
2045 end
2046end
2047#install_file_path#:lightOS/explorer/explorer
2048-- Explorer by FileStriker
2049local mode, path, type = ...
2050local projectPath = "lightOS/explorer"
2051
2052if path == nil then
2053 path = ""
2054end
2055
2056local hiddenPaths = fileN.readLines("lightOS/explorer/hiddenPaths")
2057local itemPaths = {}
2058local files = {}
2059local filesData = {}
2060local directorys = {}
2061local itemCount = 0
2062
2063local buttonGroups = {}
2064local headerButtons = 2
2065local tabFileTypes = {}
2066
2067local boolCreate
2068local boolReturnFolder
2069local boolReturnFile
2070local boolSeeFiles
2071local boolSeeAll
2072
2073local intOptionButtonCount = 0
2074
2075local event
2076local par1
2077local par2
2078local par3
2079local par4
2080local par5
2081
2082local boolClick = false
2083local boolButton = false
2084
2085local width, height = term.getSize()
2086
2087local function getFileTypes()
2088 tabTypeFiles = {}
2089 tabTypeFiles = fs.list(projectPath .. "/Open/")
2090 tabFileTypes.tabEnding = {}
2091 tabFileTypes.tabChar = {}
2092 tabFileTypes.tabCharColor = {}
2093 tabFileTypes.tabBackgroundColor = {}
2094
2095 for i=1,#tabTypeFiles do
2096 t1 = stringN.split(tabTypeFiles[i],".")
2097 if #t1 > 1 then
2098 table.insert(tabFileTypes.tabEnding, t1[#t1])
2099 file = fs.open( projectPath .. "/Open/" .. tabTypeFiles[i], "r" )
2100 line = file.readLine()
2101 while line ~= nil do
2102 if string.find( line, "--Info") ~= nil then
2103 t2 = {}
2104 t2 = stringN.split(line,";")
2105 table.insert(tabFileTypes.tabChar, t2[2])
2106 table.insert(tabFileTypes.tabCharColor, tonumber(t2[3]))
2107 table.insert(tabFileTypes.tabBackgroundColor, tonumber(t2[4]))
2108 end
2109 line = file.readLine()
2110 end
2111 file.close()
2112 end
2113 end
2114end
2115
2116local function GetFileData(strFile)
2117 intFileLenght = string.len( strFile )
2118 for i=1,#tabFileTypes.tabEnding do
2119 intLenght = string.len(tabFileTypes.tabEnding[i]) + 1
2120 if intFileLenght > intLenght then
2121 if "."..tabFileTypes.tabEnding[i] == string.sub( strFile, - intLenght ) then
2122 return tabFileTypes.tabEnding[i], tabFileTypes.tabChar[i], tabFileTypes.tabCharColor[i], tabFileTypes.tabBackgroundColor[i]
2123 end
2124 end
2125 end
2126 return nil
2127end
2128
2129local function initialize(strStartPath)
2130 local intLastSelection = 0
2131 local intLastCurrent = 1
2132 if buttonGroups.current ~= nil then
2133 intLastSelection = buttonGroups.current
2134 intLastCurrent = buttonGroups.selected[intLastSelection]
2135 end
2136
2137 itemCount = 0
2138 path = strStartPath
2139 itemPaths = fs.list(path)
2140 tabFiles = {}
2141 tabDirs = {}
2142
2143 tabFilesData = {}
2144 tabFilesData.tabType = {}
2145 tabFilesData.tabChar = {}
2146 tabFilesData.tabCharColor = {}
2147 tabFilesData.tabBackgroundColor = {}
2148 -- fill File/Folder Table
2149 for i = 1, #itemPaths do
2150 if fileN.contains(path .. itemPaths[i], hiddenPaths) == false then
2151 if fs.isDir(path .. itemPaths[i]) == true then
2152 table.insert( tabDirs, itemPaths[i] )
2153 itemCount = itemCount + 1
2154 elseif boolSeeFiles then
2155 if type == nil or stringN.endsWith(itemPaths[i],"."..type) then
2156 table.insert( tabFiles, itemPaths[i] )
2157 par1, par2, par3, par4 = GetFileData(itemPaths[i])
2158 if par1 == nil then
2159 table.insert(tabFilesData.tabType, "" )
2160 table.insert( tabFilesData.tabChar, "~" )
2161 table.insert( tabFilesData.tabCharColor, colors.black )
2162 table.insert(tabFilesData.tabBackgroundColor, colors.lightGray)
2163 else
2164 table.insert(tabFilesData.tabType, par1 )
2165 table.insert( tabFilesData.tabChar, par2 )
2166 table.insert( tabFilesData.tabCharColor, par3 )
2167 table.insert(tabFilesData.tabBackgroundColor, par4)
2168 end
2169 itemCount = itemCount + 1
2170 end
2171 end
2172 end
2173 end
2174
2175 buttonGroups = {}
2176 buttonGroups = button.createGroupTable(buttonGroups)
2177 buttonGroups = button.addGroup(itemCount,1,buttonGroups)
2178 buttonGroups = button.addGroup(4,1,buttonGroups)
2179 buttonGroups.current = intLastSelection
2180 buttonGroups.selected[intLastSelection] = intLastCurrent
2181 buttonGroups.selected[1] = 1
2182 if term.isColor() == false and buttonGroups.current == 0 then
2183 buttonGroups.current = 1
2184 end
2185end
2186
2187local function GoBack()
2188 tabSplitPath={}
2189 for pathPart in string.gmatch(path, "([^/]+)") do
2190 table.insert(tabSplitPath,pathPart)
2191 end
2192 strNewPath = ""
2193 if (#tabSplitPath > 1) then
2194 for i = 1, #tabSplitPath - 1 do
2195 strNewPath = strNewPath .. tabSplitPath[i] .. "/"
2196 end
2197 end
2198 initialize(strNewPath)
2199end
2200
2201if mode == "browse_files" then
2202 boolOptions = true
2203 boolCreate = true
2204 boolReturnFolder = false
2205 boolReturnFile = false
2206 boolSeeFiles = true
2207 boolSeeAll = false
2208 headerButtons = 2
2209elseif mode == "open_file" then
2210 boolOptions = false
2211 boolCreate = false
2212 boolReturnFolder = false
2213 boolReturnFile = true
2214 boolSeeFiles = true
2215 boolSeeAll = false
2216 headerButtons = 0
2217elseif mode == "open_folder" then
2218 boolOptions = false
2219 boolCreate = false
2220 boolReturnFolder = true
2221 boolReturnFile = false
2222 boolSeeFiles = false
2223 boolSeeAll = false
2224 headerButtons = 1
2225elseif mode == "save_file" then
2226 boolOptions = false
2227 boolCreate = true
2228 boolReturnFolder = false
2229 boolReturnFile = true
2230 boolSeeFiles = true
2231 boolSeeAll = false
2232 headerButtons = 2
2233elseif mode == "save_folder" then
2234 boolOptions = false
2235 boolCreate = true
2236 boolReturnFolder = true
2237 boolReturnFile = false
2238 boolSeeFiles = false
2239 boolSeeAll = false
2240 headerButtons = 2
2241elseif mode == "super" then
2242 boolOptions = false
2243 boolCreate = true
2244 boolReturnFolder = false
2245 boolReturnFile = false
2246 boolSeeFiles = true
2247 boolSeeAll = true
2248 headerButtons = 2
2249else
2250 screen.clear(colors.black)
2251 screen.setTextColor(colors.red)
2252 print("Error Mode is missing")
2253 screen.setTextColor(colors.white)
2254 return nil
2255end
2256
2257getFileTypes()
2258initialize(path)
2259
2260function header()
2261 screen.clear(colors.white)
2262 screen.setTextColor(colors.black)
2263 screen.clearLine(colors.lime)
2264 term.setCursorPos(5,1)
2265
2266 if string.len ( path ) > 1 then
2267 term.write(stringN.setCenter ( fs.getName ( path ) , ".." , width - 7 ))
2268 else
2269 term.write(stringN.setCenter ( "Root" , ".." , width - 7 ))
2270 end
2271 term.setCursorPos(1,height)
2272 screen.setBackgroundColor(colors.white)
2273 screen.setTextColor(colors.black)
2274 term.write("-+-" .. string.rep("-", width - 3 - string.len("mode: " .. mode)) )
2275 term.write("MODE: " .. string.upper( mode))
2276end
2277header()
2278
2279while true do
2280 if event == "key" then
2281 if par1 == keys.backspace then
2282 GoBack()
2283 end
2284 if buttonGroups.current == 1 then
2285 if par1 == keys.up or par1 == keys.w then
2286 buttonGroups.selected[1] = math.max(1, buttonGroups.selected[1] - 1)
2287 end
2288 if par1 == keys.down or par1 == keys.s then
2289 buttonGroups.selected[1] = math.min(itemCount, buttonGroups.selected[1] + 1)
2290 end
2291 if par1 == keys.tab then
2292 buttonGroups.current = 2
2293 end
2294 elseif buttonGroups.current == 2 then
2295 if buttonGroups.selected[2] == 1 then
2296 if par1 == keys.right or par1 ==keys.d then
2297 buttonGroups.selected[2] = 2
2298 end
2299 if par1 == keys.down or par1 == keys.s then
2300 buttonGroups.selected[2] = 3
2301 end
2302 end
2303 if buttonGroups.selected[2] == 2 then
2304 if par1 == keys.left or par1 ==keys.a then
2305 buttonGroups.selected[2] = 1
2306 end
2307 if par1 == keys.down or par1 == keys.s then
2308 buttonGroups.selected[2] = math.min(4,headerButtons + 2)
2309 end
2310 end
2311
2312 if buttonGroups.selected[2] == 3 then
2313 if (par1 == keys.right or par1 ==keys.d) and headerButtons == 2 then
2314 buttonGroups.selected[2] = 4
2315 end
2316 if par1 == keys.up or par1 == keys.w then
2317 buttonGroups.selected[2] = 1
2318 end
2319 end
2320 if buttonGroups.selected[2] == 4 then
2321 if par1 == keys.left or par1 ==keys.a then
2322 buttonGroups.selected[2] = 3
2323 end
2324 if boolCreate then
2325 if par1 == keys.up or par1 == keys.w then
2326 buttonGroups.selected[2] = 2
2327 end
2328 end
2329 end
2330
2331 if par1 == keys.tab then
2332 buttonGroups.current = 1
2333 end
2334 end
2335 elseif event == "key_up" then
2336 if buttonGroups.current == 0 then
2337 buttonGroups.current = 1
2338 end
2339 elseif event == "mouse_scroll" then
2340 if buttonGroups.current ~= 1 then
2341 buttonGroups.current = 1
2342 else
2343 if par1 == -1 then
2344 buttonGroups.selected[1] = math.max(1, buttonGroups.selected[1] - 1)
2345 end
2346 if par1 == 1 then
2347 buttonGroups.selected[1] = math.min(itemCount, buttonGroups.selected[1] + 1)
2348 end
2349 end
2350 end
2351
2352 local clickKeys = {keys.enter,keys.space, keys.leftCtrl}
2353 if boolOptions == false then
2354 clickKeys = {keys.enter,keys.space}
2355 end
2356
2357 local intStart, intEnd = list.list(height - 3, itemCount, buttonGroups.selected[1])
2358 local line = 3
2359 for i = intStart, math.min(itemCount, intEnd) do
2360 term.setCursorPos(1,line)
2361 if i <= #tabDirs then
2362 screen.setBackgroundColor(colors.yellow)
2363 term.write("#")
2364 else
2365 screen.setTextColor(tabFilesData.tabCharColor[ i - #tabDirs])
2366 screen.setBackgroundColor(tabFilesData.tabBackgroundColor[ i - #tabDirs])
2367 term.write(tabFilesData.tabChar[ i - #tabDirs])
2368 end
2369
2370 screen.setBackgroundColor(colors.white)
2371 screen.setTextColor(colors.black)
2372 term.write("|")
2373
2374 if i <= #tabDirs then
2375 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,width - 4, button.isSelected(1, i, buttonGroups), {tabDirs[i]," ","",">","",".."},clickKeys,{})
2376 if boolClick then
2377 if ((event == "mouse_up" and par1 == 2 and boolOptions) or (event == "key_up" and par1 == keys.leftCtrl)) then
2378 os.run({},projectPath .. "/editFolder", path .. tabDirs[i] .. "/")
2379 initialize(path)
2380 else
2381 initialize(path .. tabDirs[i] .. "/")
2382 end
2383 header()
2384 break
2385 end
2386 else
2387 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,width - 4, button.isSelected(1, i, buttonGroups), {tabFiles[ i - #tabDirs ]," ","",">","",".."},clickKeys,{})
2388 if boolClick then
2389 if ((event == "mouse_up" and par1 == 2 and boolOptions) or (event == "key_up" and par1 == keys.leftCtrl)) then
2390 os.run({},projectPath .. "/editFile", path .. tabFiles[i - #tabDirs])
2391 else
2392 if boolReturnFile then
2393 return path .. tabFiles[i - #tabDirs]
2394 else
2395 if tabFilesData.tabType[i - #tabDirs] == "" then
2396 os.run({},projectPath .. "/openUnknownFile", path .. tabFiles[i - #tabDirs])
2397 else
2398 shell.run(projectPath .. "/Open/open." .. tabFilesData.tabType[i - #tabDirs], path .. tabFiles[i - #tabDirs] )
2399 end
2400 end
2401 end
2402 initialize(path)
2403 header()
2404 break
2405 end
2406 end
2407 term.write("|")
2408 line = line +1
2409 end
2410
2411 --Close
2412 term.setCursorPos(width - 2, 1)
2413 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,button.isSelected(2, 2, buttonGroups), {"X"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.red,colors.white,colors.red})
2414 if boolClick then
2415 screen.clear(colors.black)
2416 screen.setTextColor(colors.white)
2417 return nil
2418 end
2419
2420 --Back
2421 term.setCursorPos(1, 1)
2422 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,button.isSelected(2, 1, buttonGroups), {"<-"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.green,colors.white,colors.green})
2423 if boolClick then
2424 GoBack()
2425 header()
2426 end
2427
2428 --Up
2429 term.setCursorPos(width, 3)
2430 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,false, {"-"}, {keys.enter,keys.space} , {colors.black,colors.lightBlue})
2431 if boolClick then
2432 if buttonGroups.current ~= 1 then
2433 buttonGroups.current = 1
2434 end
2435 buttonGroups.selected[1] = math.max(1, buttonGroups.selected[1] - 1)
2436 end
2437
2438 --Down
2439 term.setCursorPos(width, height -1)
2440 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,false, {"+"}, {keys.enter,keys.space} , {colors.black,colors.lightBlue})
2441 if boolClick then
2442 if buttonGroups.current ~= 1 then
2443 buttonGroups.current = 1
2444 end
2445 buttonGroups.selected[1] = math.min(itemCount, buttonGroups.selected[1] + 1)
2446 end
2447
2448 term.setCursorPos(1, 2)
2449 screen.clearLine(colors.blue)
2450 --New Folder
2451 if boolCreate then
2452 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,button.isSelected(2, 3, buttonGroups), {"New Folder"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.blue,colors.white,colors.blue})
2453 if boolClick then
2454 os.run({},projectPath .. "/newFolder", path)
2455 initialize(path)
2456 header()
2457 end
2458 term.write(" ")
2459 end
2460 -- Open Folder
2461 if boolReturnFolder then
2462 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,button.isSelected(2, 3, buttonGroups), {"Open Folder"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.blue,colors.white,colors.blue})
2463 if boolClick then
2464 return path
2465 end
2466 term.write(" ")
2467 end
2468 --New File
2469 if boolCreate and boolSeeFiles then
2470 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,button.isSelected(2, 4, buttonGroups), {"New File"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.blue,colors.white,colors.blue})
2471 if boolClick then
2472 local ret
2473 if type ~= nil then
2474 ret = assert(loadfile(projectPath .. "/newFile"))(path, type)
2475 else
2476 ret = assert(loadfile(projectPath .. "/newFile"))(path)
2477 end
2478 if boolReturnFile then
2479 return ret
2480 end
2481 initialize(path)
2482 header()
2483 end
2484 term.write(" ")
2485 end
2486
2487 screen.setBackgroundColor(colors.white)
2488 for i=3,height - 1 do
2489 term.setCursorPos(2,i)
2490 term.write("|")
2491 term.setCursorPos(width - 1,i)
2492 term.write("|")
2493 end
2494 term.setCursorPos(width, 4)
2495 list.scrollbar(height - 5 , height - 3 ,itemCount, buttonGroups.selected[1])
2496
2497
2498
2499 if boolButton then
2500 boolButton = false
2501 event = nil
2502 par1 = nil
2503 par2 = nil
2504 par3 = nil
2505 par4 = nil
2506 par5 = nil
2507 else
2508 while true do
2509 event, par1, par2, par3, par4, par5 = os.pullEvent()
2510 if event == "mouse_click" or event == "mouse_up" or event == "mouse_scroll" or event == "monitor_touch" or event == "key" or event == "key_up" then
2511 break
2512 end
2513 end
2514 end
2515
2516 if event == "mouse_up" then
2517 buttonGroups.current = 0
2518 end
2519end
2520#install_file_path#:lightOS/explorer/hiddenPaths
2521--lightOS
2522--startup
2523#install_file_path#:lightOS/explorer/newFile
2524local path , ending = ...
2525
2526if path == nil then
2527 path = ""
2528end
2529
2530if ending == nil then
2531 ending = ""
2532else
2533 ending = "." .. ending
2534end
2535
2536local text = ""
2537local intEditPos = 0
2538local intOffset = 0
2539
2540local intSelected = 2
2541
2542local intWidth, intHight = term.getSize()
2543
2544local boolClick = false
2545local boolButton = false
2546
2547local event = nil
2548local par1 = nil
2549local par2 = nil
2550local par3 = nil
2551local par4 = nil
2552local par5 = nil
2553
2554term.setCursorBlink(true)
2555
2556screen.clear(colors.white)
2557screen.setTextColor(colors.black)
2558screen.setBackgroundColor(colors.lime)
2559term.write ( stringN.cutRight ( "Create New File" , ".." , intWidth - 3 ) )
2560screen.setBackgroundColor(colors.white)
2561term.setCursorPos(1,2)
2562term.write("Path: ")
2563if string.len( path ) == 0 then
2564 term.write("Root")
2565else
2566 term.write(stringN.cutLeft(path, "..", intWidth - 6))
2567end
2568term.setCursorPos(1,4)
2569term.write("+-Name" .. string.rep("-" , intWidth - 7) .. "+")
2570term.setCursorPos(1,5)
2571term.write(string.rep("|" , intWidth))
2572term.setCursorPos(1,6)
2573term.write("+" .. string.rep("-" , intWidth - 2) .. "+")
2574
2575
2576
2577while true do
2578
2579 if event == "key" then
2580 if par1 == keys.up then
2581 if intSelected == 1 then
2582 intSelected = 2
2583 elseif intSelected ==2 then
2584 intSelected = 3
2585 else
2586 intSelected = 1
2587 end
2588 end
2589 if par1 == keys.down or par1 == keys.tab then
2590 if intSelected == 1 then
2591 intSelected = 3
2592 elseif intSelected ==2 then
2593 intSelected = 1
2594 else
2595 intSelected = 2
2596 end
2597 end
2598
2599 if intSelected == 0 then
2600 intSelected = 2
2601 end
2602 elseif event == "mouse_click" then
2603 intSelected = 0
2604 end
2605
2606 screen.setBackgroundColor(colors.white)
2607 screen.setTextColor(colors.black)
2608 term.setCursorPos(2,5)
2609 term.write(string.rep(" ", intWidth - 2))
2610 term.setCursorPos(2,5)
2611 text , intEditPos, intOffset = screen.inputField ( event, par1, text , intEditPos, intOffset, intWidth - 2)
2612
2613 screen.setBackgroundColor(colors.white)
2614 screen.setTextColor(colors.black)
2615
2616 term.setCursorPos(intWidth - 2, 1)
2617 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 3), {"X"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.red,colors.white,colors.red})
2618 if boolClick then
2619 term.setCursorBlink(false)
2620 screen.clear(colors.black)
2621 screen.setTextColor(colors.white)
2622 return nil
2623 end
2624
2625 term.setCursorPos(2, 8)
2626 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 2), {"Save"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.gray,colors.orange,colors.gray})
2627 if boolClick then
2628 if string.len( text ) == 0 then
2629 screen.clear(colors.black)
2630 screen.setTextColor(colors.white)
2631 return nil
2632 end
2633 if fs.exists(path .. text .. ending) then
2634 text = ""
2635 intEditPos = 0
2636 intOffset = 0
2637 else
2638 term.setCursorBlink(false)
2639 print(path..text)
2640 local file = fs.open(path..text .. ending, "w")
2641 file.close()
2642 screen.clear(colors.black)
2643 screen.setTextColor(colors.white)
2644 return path .. text .. ending
2645 end
2646 end
2647
2648 term.setCursorPos(2, 10)
2649 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 1), {"Exit"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.gray,colors.orange,colors.gray})
2650 if boolClick then
2651 term.setCursorBlink(false)
2652 screen.clear(colors.black)
2653 screen.setTextColor(colors.white)
2654 return nil
2655 end
2656
2657 if fs.exists(path .. text .. ending) and string.len( string.gsub(text, " ", "") ) > 0 then
2658 screen.setBackgroundColor(colors.red)
2659 screen.setTextColor(colors.black)
2660 term.setCursorPos(1,12)
2661 term.write("+-Problem:" .. string.rep("-" , intWidth - 11) .. "+")
2662 term.setCursorPos(1,13)
2663 term.write(string.rep("|" , intWidth))
2664 term.setCursorPos(1,14)
2665 term.write(string.rep("|" , intWidth))
2666 term.setCursorPos(1,15)
2667 term.write("+" .. string.rep("-" , intWidth - 2) .. "+")
2668 screen.setBackgroundColor(colors.white)
2669 term.setCursorPos(2,13)
2670 term.write(stringN.cutRight("File already exist", "",intWidth - 2))
2671 term.setCursorPos(2,14)
2672 term.write(stringN.cutRight("enter another Name", "",intWidth - 2))
2673 else
2674 term.setCursorPos(1,12)
2675 term.write( string.rep(" ",intWidth))
2676 term.setCursorPos(1,13)
2677 term.write( string.rep(" ",intWidth))
2678 term.setCursorPos(1,14)
2679 term.write( string.rep(" ",intWidth))
2680 term.setCursorPos(1,15)
2681 term.write( string.rep(" ",intWidth))
2682 end
2683
2684 term.setCursorPos(intEditPos - intOffset + 2, 5)
2685
2686 if boolButton then
2687 boolButton = false
2688 event = nil
2689 par1 = nil
2690 par2 = nil
2691 par3 = nil
2692 par4 = nil
2693 par5 = nil
2694 else
2695 while true do
2696 event, par1, par2, par3, par4, par5 = os.pullEvent()
2697 if event == "mouse_click" or event == "mouse_up" or event == "mouse_scroll" or event == "monitor_touch" or event == "key" or event == "key_up" or event == "char" then
2698 break
2699 end
2700 end
2701 end
2702end
2703#install_file_path#:lightOS/explorer/newFolder
2704local strPath = ...
2705
2706if strPath == nil then
2707 strPath = ""
2708else
2709 local p, a = string.gsub(strPath,"#SPACE#"," ")
2710 strPath = p
2711end
2712
2713local strText = ""
2714local intEditPos = 0
2715local intOffset = 0
2716
2717local intSelected = 2
2718
2719local intWidth, intHight = term.getSize()
2720
2721local boolClick = false
2722local boolButton = false
2723
2724local event = nil
2725local par1 = nil
2726local par2 = nil
2727local par3 = nil
2728local par4 = nil
2729local par5 = nil
2730term.setCursorBlink(true)
2731screen.clear(colors.white)
2732screen.setTextColor(colors.black)
2733screen.setBackgroundColor(colors.lime)
2734term.write ( stringN.setCenter ( "Create New Folder" , ".." , intWidth - 3 ) )
2735screen.setBackgroundColor(colors.white)
2736term.setCursorPos(1,2)
2737term.write("Path: ")
2738if string.len( strPath ) == 0 then
2739 term.write("Root")
2740else
2741 term.write(stringN.cutLeft(strPath, "..", intWidth - 6))
2742end
2743term.setCursorPos(1,4)
2744term.write("+-Name" .. string.rep("-" , intWidth - 7) .. "+")
2745term.setCursorPos(1,5)
2746term.write(string.rep("|" , intWidth))
2747term.setCursorPos(1,6)
2748term.write("+" .. string.rep("-" , intWidth - 2) .. "+")
2749
2750
2751
2752while true do
2753
2754 if event == "key" then
2755 if par1 == keys.up then
2756 if intSelected == 1 then
2757 intSelected = 2
2758 elseif intSelected ==2 then
2759 intSelected = 3
2760 else
2761 intSelected = 1
2762 end
2763 end
2764 if par1 == keys.down or par1 == keys.tab then
2765 if intSelected == 1 then
2766 intSelected = 3
2767 elseif intSelected ==2 then
2768 intSelected = 1
2769 else
2770 intSelected = 2
2771 end
2772 end
2773
2774 if intSelected == 0 then
2775 intSelected = 2
2776 end
2777 elseif event == "mouse_click" then
2778 intSelected = 0
2779 end
2780
2781 screen.setBackgroundColor(colors.white)
2782 screen.setTextColor(colors.black)
2783 term.setCursorPos(2,5)
2784 term.write(string.rep(" ", intWidth - 2))
2785 term.setCursorPos(2,5)
2786 strText , intEditPos, intOffset = screen.inputField ( event, par1, strText , intEditPos, intOffset, intWidth - 2)
2787
2788 screen.setBackgroundColor(colors.white)
2789 screen.setTextColor(colors.black)
2790
2791 term.setCursorPos(intWidth - 2, 1)
2792 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 3), {"X"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.red,colors.white,colors.red})
2793 if boolClick then
2794 term.setCursorBlink(false)
2795 screen.clear(colors.black)
2796 screen.setTextColor(colors.white)
2797 break
2798 end
2799
2800 term.setCursorPos(2, 8)
2801 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 2), {"Save"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.gray,colors.orange,colors.gray})
2802 if boolClick then
2803 if string.len( strText ) == 0 then
2804 term.setCursorBlink(false)
2805 screen.clear(colors.black)
2806 screen.setTextColor(colors.white)
2807 break
2808 end
2809 if fs.exists(strPath .. strText .. "/") then
2810 strText = ""
2811 intEditPos = 0
2812 intOffset = 0
2813 else
2814 term.setCursorBlink(false)
2815 fs.makeDir(strPath .. strText .. "/")
2816 screen.setTextColor(colors.white)
2817 break
2818 end
2819 end
2820
2821 term.setCursorPos(2, 10)
2822 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 1), {"Exit"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.gray,colors.orange,colors.gray})
2823 if boolClick then
2824 term.setCursorBlink(false)
2825 screen.clear(colors.black)
2826 screen.setTextColor(colors.white)
2827 break
2828 end
2829
2830 if fs.exists(strPath .. strText .. "/") and string.len( string.gsub(strText, " ", "") ) > 0 then
2831 screen.setBackgroundColor(colors.red)
2832 screen.setTextColor(colors.black)
2833 term.setCursorPos(1,12)
2834 term.write("+-Problem:" .. string.rep("-" , intWidth - 11) .. "+")
2835 term.setCursorPos(1,13)
2836 term.write(string.rep("|" , intWidth))
2837 term.setCursorPos(1,14)
2838 term.write(string.rep("|" , intWidth))
2839 term.setCursorPos(1,15)
2840 term.write("+" .. string.rep("-" , intWidth - 2) .. "+")
2841 screen.setBackgroundColor(colors.white)
2842 term.setCursorPos(2,13)
2843 term.write(stringN.setCenter("Folder already exist", "",intWidth - 2))
2844 term.setCursorPos(2,14)
2845 term.write(stringN.setCenter("enter another Name", "",intWidth - 2))
2846 else
2847 term.setCursorPos(1,12)
2848 term.write( string.rep(" ",intWidth))
2849 term.setCursorPos(1,13)
2850 term.write( string.rep(" ",intWidth))
2851 term.setCursorPos(1,14)
2852 term.write( string.rep(" ",intWidth))
2853 term.setCursorPos(1,15)
2854 term.write( string.rep(" ",intWidth))
2855 end
2856
2857 term.setCursorPos(intEditPos - intOffset + 2, 5)
2858
2859 if boolButton then
2860 boolButton = false
2861 event = nil
2862 par1 = nil
2863 par2 = nil
2864 par3 = nil
2865 par4 = nil
2866 par5 = nil
2867 else
2868 while true do
2869 event, par1, par2, par3, par4, par5 = os.pullEvent()
2870 if event == "mouse_click" or event == "mouse_up" or event == "mouse_scroll" or event == "monitor_touch" or event == "key" or event == "key_up" or event == "char" then
2871 break
2872 end
2873 end
2874 end
2875end
2876#install_file_path#:lightOS/explorer/open/open.install
2877--Info;>;8;512
2878local strPath = ...
2879
2880function readLines(path)
2881 local file = fs.open(path, "r")
2882 local lines = {}
2883 local line = file.readLine()
2884 while line ~= nil do
2885 table.insert( lines, line )
2886 line = file.readLine()
2887 end
2888 file.close()
2889 return lines
2890end
2891
2892lines = readLines(strPath)
2893local file
2894i = 1
2895while string.find( lines[i], "#end_install_file#" ) == nil do
2896 if string.find( lines[i], "#install_file_path#:" ) ~= nil then
2897 if file ~= nil then file.close() end
2898 file = fs.open(string.sub(lines[i], string.len("#install_file_path#:")), "w")
2899 else
2900 if file ~= nil then
2901 file.writeLine(lines[i])
2902 end
2903 end
2904 i = i + 1
2905end
2906if file ~= nil then file.close() end
2907fs.delete(strPath)
2908#install_file_path#:lightOS/explorer/openUnknownFile
2909--Info;X;16384;8192
2910local strPath = ...
2911
2912if strPath == nil then
2913 strPath = ""
2914end
2915
2916local strText = ""
2917local intEditPos = 0
2918local intOffset = 0
2919
2920local intSelected = 1
2921
2922local intWidth, intHight = term.getSize()
2923
2924local boolClick = false
2925local boolButton = false
2926
2927local event = nil
2928local par1 = nil
2929local par2 = nil
2930local par3 = nil
2931local par4 = nil
2932local par5 = nil
2933
2934term.setCursorBlink(true)
2935screen.clear(colors.white)
2936screen.setTextColor(colors.black)
2937screen.setBackgroundColor(colors.lime)
2938term.write ( stringN.setCenter ( fs.getName ( strPath ) , ".." , intWidth - 3 ) )
2939screen.setBackgroundColor(colors.white)
2940term.setCursorPos(1,2)
2941term.write("Path: ")
2942if string.len( strPath ) == 0 then
2943 term.write("Root")
2944else
2945 term.write(stringN.cutLeft(strPath, "..", intWidth - 6))
2946end
2947term.setCursorPos(1,4)
2948term.write("+-Arguments" .. string.rep("-" , intWidth - 12) .. "+")
2949term.setCursorPos(1,5)
2950term.write(string.rep("|" , intWidth))
2951term.setCursorPos(1,6)
2952term.write("+" .. string.rep("-" , intWidth - 2) .. "+")
2953
2954
2955
2956while true do
2957
2958 if event == "key" then
2959 if par1 == keys.up or par1 == keys.down or par1 == keys.tab then
2960 if intSelected == 1 then
2961 intSelected = 2
2962 else
2963 intSelected = 0
2964 end
2965 end
2966
2967 if intSelected == 0 then
2968 intSelected = 1
2969 end
2970 elseif event == "mouse_click" then
2971 intSelected = 0
2972 end
2973
2974 screen.setBackgroundColor(colors.white)
2975 screen.setTextColor(colors.black)
2976 term.setCursorPos(2,5)
2977 term.write(string.rep(" ", intWidth - 2))
2978 term.setCursorPos(2,5)
2979 strText , intEditPos, intOffset = screen.inputField ( event, par1, strText , intEditPos, intOffset, intWidth - 2)
2980
2981 term.setCursorPos(intWidth - 2, 1)
2982 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 2), {"X"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.red,colors.white,colors.red})
2983 if boolClick then
2984 term.setCursorBlink(false)
2985 screen.clear(colors.black)
2986 screen.setTextColor(colors.white)
2987 break
2988 end
2989
2990 term.setCursorPos(2, 8)
2991 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 1), {"Run"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.gray,colors.orange,colors.gray})
2992 if boolClick then
2993 term.setCursorBlink(false)
2994 screen.clear(colors.black)
2995 screen.setTextColor(colors.white)
2996 if string.len( strText ) > 0 then
2997 if shell.run(strPath, strText) == false then
2998 print("Something went wrong")
2999 print("press any Button or wait...")
3000 screen.infoPopup("",10)
3001 else
3002 print("Exing Program")
3003 print("press any Button or wait...")
3004 screen.infoPopup("",10)
3005 end
3006 else
3007 if shell.run(strPath) == false then
3008 print("Something went wrong")
3009 print("press any Button or wait...")
3010 screen.infoPopup("",10)
3011 else
3012 print("Exing Program")
3013 print("press any Button or wait...")
3014 screen.infoPopup("",10)
3015 end
3016 end
3017 break
3018 end
3019
3020 term.setCursorPos(intEditPos - intOffset + 2, 5)
3021
3022 if boolButton then
3023 Initialize(strPath)
3024 boolButton = false
3025 event = nil
3026 par1 = nil
3027 par2 = nil
3028 par3 = nil
3029 par4 = nil
3030 par5 = nil
3031 else
3032 while true do
3033 event, par1, par2, par3, par4, par5 = os.pullEvent()
3034 if event == "mouse_click" or event == "mouse_up" or event == "mouse_scroll" or event == "monitor_touch" or event == "key" or event == "key_up" or event == "char" then
3035 break
3036 end
3037 end
3038 end
3039end
3040#install_file_path#:lightOS/lightOS
3041
3042local width, height = term.getSize()
3043
3044local anyButton = false
3045local isClick = false
3046local event
3047local par1
3048local par2
3049local par3
3050local par4
3051local par5
3052
3053local startUpPath = startN.getStartupPath()
3054
3055if fs.exists("programs/") == false then
3056 fs.makeDir("programs/")
3057end
3058
3059local buttonGroups
3060local files
3061local programs
3062
3063local selection = 2
3064
3065local function initialize()
3066 lastCurrent = 2
3067 lastSelected = 1
3068 if buttonGroups ~= nil then
3069 lastCurrent = buttonGroups.current
3070 lastSelected = buttonGroups.selected[lastCurrent]
3071 elseif term.isColor() then
3072 lastCurrent = 0
3073 end
3074
3075
3076 files = fs.list("programs")
3077
3078 programs = {}
3079 programs.path = {}
3080 programs.name = {}
3081 programs.outDir = {}
3082
3083 for i=1,#files do
3084 if fs.isDir("programs/" .. files[i]) then
3085 local path = "programs/" .. fs.getName(files[i]) .. "/" .. fs.getName(files[i])
3086 if fs.exists(path) then
3087 table.insert( programs.path, path )
3088 table.insert( programs.name, fs.getName(path) )
3089 table.insert( programs.outDir, true )
3090 end
3091 else
3092 table.insert( programs.path, "programs/" .. files[i] )
3093 table.insert( programs.name, fs.getName("programs/" .. files[i]) )
3094 table.insert( programs.outDir, false )
3095 end
3096 end
3097
3098 buttonGroups = {}
3099 buttonGroups = button.createGroupTable(buttonGroups)
3100 buttonGroups = button.addGroup(4,3,buttonGroups)
3101 buttonGroups = button.addGroup(#programs.path,1,buttonGroups)
3102 buttonGroups = button.addGroup(#programs.path,1,buttonGroups)
3103 buttonGroups = button.addGroup(#programs.path,1,buttonGroups)
3104
3105 buttonGroups.current = lastCurrent
3106 if lastCurrent > 1 then
3107 buttonGroups.selected[2] = math.min(lastSelected, buttonGroups.size[2])
3108 buttonGroups.selected[3] = buttonGroups.selected[2]
3109 buttonGroups.selected[4] = buttonGroups.selected[2]
3110 elseif lastCurrent == 1 then
3111 buttonGroups.selected[1] = lastSelected
3112 end
3113end
3114initialize()
3115
3116-- if term.isColor() then
3117-- selected = 0
3118-- end
3119
3120local function header()
3121 screen.clear(colors.white)
3122 screen.setTextColor(colors.black)
3123 screen.clearLine(colors.lime)
3124 term.write(stringN.setCenter("LightOS","",width - 3))
3125 term.setCursorPos(1,2)
3126 screen.clearLine(colors.blue)
3127 screen.setBackgroundColor(colors.white)
3128end
3129
3130header()
3131while true do
3132 if event == "key" then
3133 if buttonGroups.current == 0 then
3134 buttonGroups.current = 1
3135 elseif buttonGroups.current == 1 then
3136 if par1 == keys.tab then
3137 buttonGroups.current = selection
3138 elseif buttonGroups.selected[1] == 1 then
3139 if par1 == keys.down or par1 == keys.s then
3140 buttonGroups.selected[1] = 4
3141 end
3142 elseif buttonGroups.selected[1] == 2 then
3143 if par1 == keys.up or par1 == keys.w then
3144 buttonGroups.selected[1] = 1
3145 elseif par1 == keys.right or par1 == keys.d then
3146 buttonGroups.selected[1] = 3
3147 end
3148 elseif buttonGroups.selected[1] == 3 then
3149 if par1 == keys.up or par1 == keys.w then
3150 buttonGroups.selected[1] = 1
3151 elseif par1 == keys.left or par1 == keys.a then
3152 buttonGroups.selected[1] = 2
3153 elseif par1 == keys.right or par1 == keys.d then
3154 buttonGroups.selected[1] = 4
3155 end
3156 elseif buttonGroups.selected[1] == 4 then
3157 if par1 == keys.up or par1 == keys.w then
3158 buttonGroups.selected[1] = 1
3159 elseif par1 == keys.left or par1 == keys.a then
3160 buttonGroups.selected[1] = 3
3161 end
3162 end
3163 else
3164 if par1 == keys.up or par1 == keys.w then
3165 buttonGroups.selected[2] = math.max(1, buttonGroups.selected[2] - 1)
3166 buttonGroups.selected[3] = buttonGroups.selected[2]
3167 buttonGroups.selected[4] = buttonGroups.selected[2]
3168 elseif par1 == keys.down or par1 == keys.s then
3169 buttonGroups.selected[2] = math.min(buttonGroups.size[2], buttonGroups.selected[2] + 1)
3170 buttonGroups.selected[3] = buttonGroups.selected[2]
3171 buttonGroups.selected[4] = buttonGroups.selected[2]
3172 elseif par1 == keys.left or par1 == keys.a then
3173 buttonGroups.current = math.max(2, buttonGroups.current - 1)
3174 elseif par1 == keys.right or par1 == keys.d then
3175 buttonGroups.current = math.min(4, buttonGroups.current + 1)
3176 elseif par1 == keys.tab then
3177 selection = buttonGroups.current
3178 buttonGroups.current = 1
3179 end
3180 end
3181 elseif event == "mouse_scroll" then
3182 if buttonGroups.current < 2 then
3183 buttonGroups.current = 2
3184 else
3185 if par1 == -1 then
3186 buttonGroups.selected[2] = math.max(1, buttonGroups.selected[2] - 1)
3187 buttonGroups.selected[3] = buttonGroups.selected[2]
3188 buttonGroups.selected[4] = buttonGroups.selected[2]
3189 end
3190 if par1 == 1 then
3191 buttonGroups.selected[2] = math.min(buttonGroups.size[2], buttonGroups.selected[2] + 1)
3192 buttonGroups.selected[3] = buttonGroups.selected[2]
3193 buttonGroups.selected[4] = buttonGroups.selected[2]
3194 end
3195 end
3196 end
3197
3198
3199 if buttonGroups.current > 1 and #programs.path == 0 then
3200 buttonGroups.current = 1
3201 end
3202
3203
3204 term.setCursorPos(width - 2,1)
3205 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0, button.isSelected(1,1,buttonGroups), {"X"," "," ","[","]"},{keys.enter,keys.space},{colors.black,colors.red,colors.white,colors.red})
3206 if isClick then
3207 screen.clear(colors.black)
3208 screen.setTextColor(colors.white)
3209 break
3210 end
3211
3212 term.setCursorPos(1,2)
3213 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0, button.isSelected(1,2,buttonGroups), {"Browser"," "," ","[","]"},{keys.enter,keys.space},{colors.black,colors.blue,colors.white,colors.blue})
3214 if isClick then
3215 shell.run("lightOS/browser/browser")
3216 initialize()
3217 header()
3218 end
3219
3220 term.setCursorPos(12,2)
3221 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0, button.isSelected(1,3,buttonGroups), {"Explporer"," "," ","[","]"},{keys.enter,keys.space},{colors.black,colors.blue,colors.white,colors.blue})
3222 if isClick then
3223 shell.run(unpack{"lightOS/explorer/explorer","browse_files",""})
3224 startUpPath = startN.getStartupPath()
3225 initialize()
3226 header()
3227 end
3228
3229 term.setCursorPos(width - 2,2)
3230 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0, button.isSelected(1,4,buttonGroups), {"O"," "," ","[","]"},{keys.enter,keys.space},{colors.black,colors.blue,colors.white,colors.blue})
3231 if isClick then
3232 screen.infoPopup("Options will be coming soon!\nCheck the Browser for updates!",5)
3233 header()
3234 end
3235
3236 --Up
3237 term.setCursorPos(width, 3)
3238 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0,false, {"-"}, {keys.enter,keys.space} , {colors.black,colors.lightBlue})
3239 if isClick then
3240 if buttonGroups.current < 2 then
3241 buttonGroups.current = 2
3242 end
3243 buttonGroups.selected[2] = math.max(1, buttonGroups.selected[2] - 1)
3244 buttonGroups.selected[3] = buttonGroups.selected[2]
3245 buttonGroups.selected[4] = buttonGroups.selected[2]
3246 end
3247
3248--Down
3249 term.setCursorPos(width, height)
3250 isClick , anyButton = button.create(anyButton , event, par1,par2,par3,0,false, {"+"}, {keys.enter,keys.space} , {colors.black,colors.lightBlue})
3251 if isClick then
3252 if buttonGroups.current < 2 then
3253 buttonGroups.current = 2
3254 end
3255 buttonGroups.selected[2] = math.min(buttonGroups.size[2], buttonGroups.selected[2] + 1)
3256 buttonGroups.selected[3] = buttonGroups.selected[2]
3257 buttonGroups.selected[4] = buttonGroups.selected[2]
3258 end
3259
3260 local start, ending = list.list(height - 2, buttonGroups.size[2], buttonGroups.selected[2])
3261 local line = 3
3262 local linecolor = {}
3263 for i = start, ending do
3264 term.setCursorPos(1,line)
3265 isClick , anyButton = button.create(anyButton, event,par1,par2,par3,width - 12, button.isSelected(2,i,buttonGroups), {programs.name[i]," "," ",">"," ",".."},{keys.enter,keys.space},{})
3266 if isClick then
3267 shell.run("lightOS/explorer/openUnknownFile",programs.path[i])
3268 header()
3269 end
3270 term.write("|")
3271 if startUpPath == programs.path[i] then
3272 linecolor = {colors.black,colors.orange,colors.red,colors.orange}
3273 else
3274 linecolor = {colors.black,colors.lime,colors.blue,colors.lime}
3275 end
3276 isClick , anyButton = button.create(anyButton, event,par1,par2,par3,0, button.isSelected(3,i,buttonGroups), {">"," "," ","[","]"},{keys.enter,keys.space},linecolor)
3277 if isClick then
3278 if startUpPath == programs.path[i] then
3279 startN.removeStartup()
3280 startUpPath = startN.getStartupPath()
3281 else
3282 shell.run("lightOS/startup/setAsStartup", programs.path[i])
3283 startUpPath = startN.getStartupPath()
3284 header()
3285 end
3286 end
3287 term.write("|")
3288 isClick , anyButton = button.create(anyButton, event,par1,par2,par3,0, button.isSelected(4,i,buttonGroups), {"del"," "," ","[","]"},{keys.enter,keys.space},{colors.black,colors.red,colors.white,colors.red})
3289 if isClick then
3290 if programs.outDir[i] == true then
3291 fs.delete( fs.getDir(programs.path[i]))
3292 else
3293 fs.delete( programs.path[i])
3294 end
3295 initialize()
3296 header()
3297 break
3298 end
3299 term.write("|")
3300 line = line + 1
3301 end
3302
3303 for i=3,height do
3304 term.setCursorPos(width - 11,i)
3305 term.write("|")
3306 term.setCursorPos(width - 7,i)
3307 term.write("|")
3308 term.setCursorPos(width - 1,i)
3309 term.write("|")
3310 end
3311 term.setCursorPos(width,4)
3312 list.scrollbar(height - 4 , height - 2 ,buttonGroups.size[2], buttonGroups.selected[2])
3313
3314 if anyButton then
3315 anyButton = false
3316 event = nil
3317 par1 = nil
3318 par2 = nil
3319 par3 = nil
3320 par4 = nil
3321 par5 = nil
3322 else
3323 while true do
3324 event, par1, par2, par3, par4, par5 = os.pullEvent()
3325 if event == "mouse_click" or event == "mouse_scroll" or event == "mouse_up" or event == "monitor_touch" or event == "key" or event == "key_up" then
3326 break
3327 end
3328 end
3329 end
3330
3331 if event == "mouse_up" then
3332 buttonGroups.current = 0
3333 end
3334
3335end
3336#install_file_path#:lightOS/startup/setAsStartup
3337local strPath = ...
3338
3339if strPath == nil then
3340 strPath = ""
3341else
3342 local p, a = string.gsub(strPath,"#SPACE#"," ")
3343 strPath = p
3344end
3345
3346local strText = ""
3347local intEditPos = 0
3348local intOffset = 0
3349
3350local intSelected = 1
3351
3352local intWidth, intHight = term.getSize()
3353
3354local boolClick = false
3355local boolButton = false
3356
3357local event = nil
3358local par1 = nil
3359local par2 = nil
3360local par3 = nil
3361local par4 = nil
3362local par5 = nil
3363
3364screen.clear(colors.white)
3365screen.setTextColor(colors.black)
3366screen.setBackgroundColor(colors.lime)
3367term.write ( stringN.setCenter ( fs.getName ( strPath ) , ".." , intWidth - 3 ) )
3368screen.setBackgroundColor(colors.white)
3369term.setCursorPos(1,2)
3370term.write("Path: ")
3371if string.len( strPath ) == 0 then
3372 term.write("Root")
3373else
3374 term.write(stringN.cutLeft(strPath, "..", intWidth - 6))
3375end
3376term.setCursorPos(1,4)
3377term.write("+-Arguments" .. string.rep("-" , intWidth - 12) .. "+")
3378term.setCursorPos(1,5)
3379term.write(string.rep("|" , intWidth))
3380term.setCursorPos(1,6)
3381term.write("+" .. string.rep("-" , intWidth - 2) .. "+")
3382
3383
3384
3385while true do
3386
3387 if event == "key" then
3388 if par1 == keys.up or par1 == keys.down or par1 == keys.tab then
3389 if intSelected == 1 then
3390 intSelected = 2
3391 else
3392 intSelected = 0
3393 end
3394 end
3395
3396 if intSelected == 0 then
3397 intSelected = 1
3398 end
3399 elseif event == "mouse_click" then
3400 intSelected = 0
3401 end
3402
3403 screen.setBackgroundColor(colors.white)
3404 screen.setTextColor(colors.black)
3405 term.setCursorPos(2,5)
3406 term.write(string.rep(" ", intWidth - 2))
3407 term.setCursorPos(2,5)
3408 strText , intEditPos, intOffset = screen.inputField ( event, par1, strText , intEditPos, intOffset, intWidth - 2)
3409
3410 term.setCursorPos(intWidth - 2, 1)
3411 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 2), {"X"," ", " ", "[","]"}, {keys.enter,keys.space} , {colors.black,colors.red,colors.white,colors.red})
3412 if boolClick then
3413 screen.clear(colors.black)
3414 screen.setTextColor(colors.white)
3415 break
3416 end
3417
3418 term.setCursorPos(2, 8)
3419 boolClick , boolButton = button.create(boolButton , event, par1,par2,par3,0,(intSelected == 1), {"Set As Startup"," ", " ", "[","]"}, {keys.enter} , {colors.black,colors.gray,colors.orange,colors.gray})
3420 if boolClick then
3421 screen.clear(colors.black)
3422 screen.setTextColor(colors.white)
3423 print("text: " .. strText)
3424 startN.setAsStartup(strPath, {strText} )
3425 break
3426 end
3427
3428 if boolButton then
3429 Initialize(strPath)
3430 boolButton = false
3431 event = nil
3432 par1 = nil
3433 par2 = nil
3434 par3 = nil
3435 par4 = nil
3436 par5 = nil
3437 else
3438 while true do
3439 event, par1, par2, par3, par4, par5 = os.pullEvent()
3440 if event == "mouse_click" or event == "mouse_up" or event == "mouse_scroll" or event == "monitor_touch" or event == "key" or event == "key_up" or event == "char" then
3441 break
3442 end
3443 end
3444 end
3445end
3446#end_install_file#]]