-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsh.lua
More file actions
82 lines (73 loc) · 2.16 KB
/
Copy pathsh.lua
File metadata and controls
82 lines (73 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
gpu = component.proxy(component.list("gpu")())
cursor = {
x = 3,
y = 1,
oldx = 3,
oldy = 1
}
local errorn = 0
function redrawCursor()
gpu.set(cursor.oldx, cursor.oldy, table.pack(gpu.get(cursor.oldx, cursor.oldy))[1])
gpu.setForeground(0x000000)
gpu.setBackground(0xFFFFFF)
gpu.set(cursor.x, cursor.y, " ")
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0x000000)
cursor.oldx, cursor.oldy = cursor.x, cursor.y
end
local function errorHandler(text)
errorn = errorn + 1
gpu.set(cursor.x, cursor.y, "sh: " .. errorn .. ": " .. command .. ": " .. text)
end
function start()
local thread = fs.open(command)
if thread == nil then
errorHandler("not found")
return
end
local file = fs.read(thread, fs.size(command))
if file == nil then
errorHandler("permission denied")
return
end
local callable, reason = load(file)
if callable == false then
errorHandler("syntax error: " .. reason)
end
local status, reason = pcall(callable)
if status == false then
errorHandler(reason)
end
fs.close(thread)
end
command = ""
x, y = gpu.getResolution()
gpu.fill(1, 1, x, y, " ")
gpu.set(1, 1, "# ")
while(true) do
redrawCursor()
local signal = table.pack(computer.pullSignal(1))
if signal[1] ~= nil then
if signal[1] == 'key_down' then
if signal[3] == 8 then
if command ~= "" then
gpu.set(cursor.oldx, cursor.oldy, " ")
command = unicode.sub(command, 1, unicode.len(command) - 1)
cursor.x = cursor.x - 1
end
elseif signal[3] == 13 then
cursor.x, cursor.y = 1, cursor.y + 1
redrawCursor()
start()
command = ""
cursor.x, cursor.y = 3, cursor.y + 1
gpu.set(1, cursor.y, "# ")
redrawCursor()
else
gpu.set(cursor.x, cursor.y, unicode.char(signal[3]))
command = command .. unicode.char(signal[3])
cursor.x = cursor.x + 1
end
end
end
end