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