made dev files (includeing tern) also fixed differnt keyboard layouts hopefully
This commit is contained in:
@@ -104,6 +104,12 @@ local ok, err = xpcall(function()
|
||||
end
|
||||
end
|
||||
|
||||
local acekeys={
|
||||
[apis.keys.enter]="\n",
|
||||
[apis.keys.tab]="\t",
|
||||
[apis.keys.backspace]="\b"
|
||||
}
|
||||
|
||||
function sleep(time)
|
||||
local stoptime = apis.os.clock() + (time)
|
||||
while stoptime > apis.os.clock() do end
|
||||
@@ -139,12 +145,10 @@ local ok, err = xpcall(function()
|
||||
local Kernel = load(getFile(BOOT_DRIVE_PATH .. "/boot/kernel.lua"),"@Kernel")
|
||||
local initFs = load(getFile(BOOT_DRIVE_PATH .. "/boot/cct/initdisks"),"@Init_disks")(apis)
|
||||
local fs = load(getFile(BOOT_DRIVE_PATH .. "/boot/initfs"), "@InitFs")()
|
||||
local key = load(getFile(BOOT_DRIVE_PATH .. "/boot/cct/keys.lua"),"@keyhelper")(apis)
|
||||
|
||||
if not Kernel then displaySuperBadError("Could not load kernel.") end
|
||||
if not initFs then displaySuperBadError("Could not load initdisks.") end
|
||||
if not fs then displaySuperBadError("Could not load initfs.") end
|
||||
if not key then displaySuperBadError("Could not load key helper.") end
|
||||
|
||||
local eventQueue = {}
|
||||
|
||||
@@ -275,10 +279,13 @@ local ok, err = xpcall(function()
|
||||
local event = {coroutine.yield()}
|
||||
if event[1] == "key" then
|
||||
queueEvent("keyPressed", 1, event[2])
|
||||
key(event, queueEvent)
|
||||
if acekeys[event[2]] then
|
||||
queueEvent("keyTyped", 1, acekeys[event[2]])
|
||||
end
|
||||
elseif event[1] == "char" then
|
||||
queueEvent("keyTyped", 1, event[2])
|
||||
elseif event[1] == "key_up" then
|
||||
queueEvent("keyReleased", 1, event[2])
|
||||
key(event, queueEvent)
|
||||
elseif event[1] == "disk" then
|
||||
queueEvent("componentAdded", "disk")
|
||||
elseif event[1] == "disk_eject" then
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
-- :Minify:--
|
||||
local apis = ...
|
||||
local keys = apis.keys
|
||||
local tKeys = {}
|
||||
tKeys[keys.space] = ' '
|
||||
tKeys[keys.grave] = '`'
|
||||
tKeys[keys.comma] = ','
|
||||
tKeys[keys.minus] = '-'
|
||||
tKeys[keys.period] = '.'
|
||||
tKeys[keys.slash] = '/'
|
||||
tKeys[keys.zero] = '0'
|
||||
tKeys[keys.one] = '1'
|
||||
tKeys[keys.two] = '2'
|
||||
tKeys[keys.three] = '3'
|
||||
tKeys[keys.four] = '4'
|
||||
tKeys[keys.five] = '5'
|
||||
tKeys[keys.six] = '6'
|
||||
tKeys[keys.seven] = '7'
|
||||
tKeys[keys.eight] = '8'
|
||||
tKeys[keys.nine] = '9'
|
||||
tKeys[keys.semicolon or keys.semiColon] = ';'
|
||||
tKeys[keys.equals] = '='
|
||||
tKeys[keys.a] = 'a'
|
||||
tKeys[keys.b] = 'b'
|
||||
tKeys[keys.c] = 'c'
|
||||
tKeys[keys.d] = 'd'
|
||||
tKeys[keys.e] = 'e'
|
||||
tKeys[keys.f] = 'f'
|
||||
tKeys[keys.g] = 'g'
|
||||
tKeys[keys.h] = 'h'
|
||||
tKeys[keys.i] = 'i'
|
||||
tKeys[keys.j] = 'j'
|
||||
tKeys[keys.k] = 'k'
|
||||
tKeys[keys.l] = 'l'
|
||||
tKeys[keys.m] = 'm'
|
||||
tKeys[keys.n] = 'n'
|
||||
tKeys[keys.o] = 'o'
|
||||
tKeys[keys.p] = 'p'
|
||||
tKeys[keys.q] = 'q'
|
||||
tKeys[keys.r] = 'r'
|
||||
tKeys[keys.s] = 's'
|
||||
tKeys[keys.t] = 't'
|
||||
tKeys[keys.u] = 'u'
|
||||
tKeys[keys.v] = 'v'
|
||||
tKeys[keys.w] = 'w'
|
||||
tKeys[keys.x] = 'x'
|
||||
tKeys[keys.y] = 'y'
|
||||
tKeys[keys.z] = 'z'
|
||||
tKeys[keys.leftBracket] = '['
|
||||
tKeys[keys.backslash] = '\\'
|
||||
tKeys[keys.rightBracket] = ']'
|
||||
tKeys[keys.apostrophe] = "'"
|
||||
tKeys[keys.enter] = '\n'
|
||||
tKeys[keys.tab] = '\t'
|
||||
tKeys[keys.backspace] = '\b'
|
||||
tKeys[keys.insert] = '\x1b[2~'
|
||||
tKeys[keys.delete] = '\x1b[3~'
|
||||
tKeys[keys.right] = '\x1b[C'
|
||||
tKeys[keys.left] = '\x1b[D'
|
||||
tKeys[keys.down] = '\x1b[B'
|
||||
tKeys[keys.up] = '\x1b[A'
|
||||
tKeys[keys.pageUp] = '\x1b[5~'
|
||||
tKeys[keys.pageDown] = '\x1b[6~'
|
||||
tKeys[keys.home] = '\x1b[1~'
|
||||
tKeys[keys["end"]] = '\x1b[4~'
|
||||
-- tKeys[keys.capsLock] = '\x1b[capsLock'
|
||||
-- tKeys[keys.scrollLock] = '\x1b[scrollLock'
|
||||
-- tKeys[keys.numLock] = '\x1b[numLock'
|
||||
-- if keys.printScreen then
|
||||
-- tKeys[keys.printScreen] = '\x1b[printScreen'
|
||||
-- end
|
||||
-- tKeys[keys.pause] = '\x1b[pause'
|
||||
tKeys[keys.f1] = '\x1b[11~'
|
||||
tKeys[keys.f2] = '\x1b[12~'
|
||||
tKeys[keys.f3] = '\x1b[13~'
|
||||
tKeys[keys.f4] = '\x1b[14~'
|
||||
tKeys[keys.f5] = '\x1b[15~'
|
||||
tKeys[keys.f6] = '\x1b[17~'
|
||||
tKeys[keys.f7] = '\x1b[18~'
|
||||
tKeys[keys.f8] = '\x1b[19~'
|
||||
tKeys[keys.f9] = '\x1b[20~'
|
||||
tKeys[keys.f10] = '\x1b[21~'
|
||||
tKeys[keys.f11] = '\x1b[23~'
|
||||
tKeys[keys.f12] = '\x1b[24~'
|
||||
-- tKeys[keys.f13] = '\x1b[25~'
|
||||
-- tKeys[keys.f14] = '\x1b[26~'
|
||||
-- tKeys[keys.f15] = '\x1b[28~'
|
||||
-- tKeys[keys.f16] = '\x1b[29~'
|
||||
-- tKeys[keys.f17] = '\x1b[31~'
|
||||
-- tKeys[keys.f18] = '\x1b[32~'
|
||||
-- tKeys[keys.f19] = '\x1b[33~'
|
||||
-- tKeys[keys.f20] = '\x1b[34~'
|
||||
-- tKeys[keys.f21] = '\x1b[42~'
|
||||
-- tKeys[keys.f22] = '\x1b[43~'
|
||||
-- tKeys[keys.f23] = '\x1b[44~'
|
||||
-- tKeys[keys.f24] = '\x1b[45~'
|
||||
-- tKeys[keys.f25] = '\x1b[46~'
|
||||
|
||||
-- Numpad
|
||||
tKeys[keys.numPad0] = '0'
|
||||
tKeys[keys.numPad1] = '1'
|
||||
tKeys[keys.numPad2] = '2'
|
||||
tKeys[keys.numPad3] = '3'
|
||||
tKeys[keys.numPad4] = '4'
|
||||
tKeys[keys.numPad5] = '5'
|
||||
tKeys[keys.numPad6] = '6'
|
||||
tKeys[keys.numPad7] = '7'
|
||||
tKeys[keys.numPad8] = '8'
|
||||
tKeys[keys.numPad9] = '9'
|
||||
|
||||
-- tKeys[340] = 'leftShift'
|
||||
-- tKeys[341] = 'leftCtrl'
|
||||
-- tKeys[342] = 'leftAlt'
|
||||
-- tKeys[343] = 'leftSuper'
|
||||
-- tKeys[344] = 'rightShift'
|
||||
-- tKeys[345] = 'rightCtrl'
|
||||
-- tKeys[346] = 'rightAlt'
|
||||
-- tKeys[347] = 'rightSuper'
|
||||
-- tKeys[348] = 'menu'
|
||||
|
||||
local shift = false
|
||||
local ctrl = false
|
||||
local alt = false
|
||||
|
||||
local function s(char)
|
||||
if not shift then return char end
|
||||
-- Letters
|
||||
if char == "a" then return "A" end
|
||||
if char == "b" then return "B" end
|
||||
if char == "c" then return "C" end
|
||||
if char == "d" then return "D" end
|
||||
if char == "e" then return "E" end
|
||||
if char == "f" then return "F" end
|
||||
if char == "g" then return "G" end
|
||||
if char == "h" then return "H" end
|
||||
if char == "i" then return "I" end
|
||||
if char == "j" then return "J" end
|
||||
if char == "k" then return "K" end
|
||||
if char == "l" then return "L" end
|
||||
if char == "m" then return "M" end
|
||||
if char == "n" then return "N" end
|
||||
if char == "o" then return "O" end
|
||||
if char == "p" then return "P" end
|
||||
if char == "q" then return "Q" end
|
||||
if char == "r" then return "R" end
|
||||
if char == "s" then return "S" end
|
||||
if char == "t" then return "T" end
|
||||
if char == "u" then return "U" end
|
||||
if char == "v" then return "V" end
|
||||
if char == "w" then return "W" end
|
||||
if char == "x" then return "X" end
|
||||
if char == "y" then return "Y" end
|
||||
if char == "z" then return "Z" end
|
||||
-- Symbols
|
||||
if char == "`" then return "~" end
|
||||
if char == "1" then return "!" end
|
||||
if char == "2" then return "@" end
|
||||
if char == "3" then return "#" end
|
||||
if char == "4" then return "$" end
|
||||
if char == "5" then return "%" end
|
||||
if char == "6" then return "^" end
|
||||
if char == "7" then return "&" end
|
||||
if char == "8" then return "*" end
|
||||
if char == "9" then return "(" end
|
||||
if char == "0" then return ")" end
|
||||
if char == "-" then return "_" end
|
||||
if char == "=" then return "+" end
|
||||
if char == "[" then return "{" end
|
||||
if char == "]" then return "}" end
|
||||
if char == "\\" then return "|" end
|
||||
if char == ";" then return ":" end
|
||||
if char == "'" then return '"' end
|
||||
if char == "," then return "<" end
|
||||
if char == "." then return ">" end
|
||||
if char == "/" then return "?" end
|
||||
return char or ""
|
||||
end
|
||||
|
||||
local function p()
|
||||
local str = ""
|
||||
if alt then str = str .. "\x1b" end
|
||||
if ctrl then str = str .. "^" end
|
||||
return str
|
||||
end
|
||||
|
||||
return function(event, q)
|
||||
if event[1] == "key" then
|
||||
if event[2] == keys.leftCtrl or event[2] == keys.rightCtrl then
|
||||
ctrl = true
|
||||
return
|
||||
elseif event[2] == keys.leftAlt or event[2] == keys.rightAlt then
|
||||
alt = true
|
||||
return
|
||||
elseif event[2] == keys.leftShift or event[2] == keys.rightCtrl then
|
||||
shift = true
|
||||
return
|
||||
end
|
||||
q("keyTyped", 1, p() .. s(tKeys[event[2]]))
|
||||
elseif event[1] == "key_up" then
|
||||
if event[2] == keys.leftCtrl or event[2] == keys.rightCtrl then
|
||||
ctrl = false
|
||||
return
|
||||
elseif event[2] == keys.leftAlt or event[2] == keys.rightAlt then
|
||||
alt = false
|
||||
return
|
||||
elseif event[2] == keys.leftShift or event[2] == keys.rightCtrl then
|
||||
shift = false
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
363
Src/Hyperion-firmware-cct/lib/modules/CC-Tweaked/25_tty.kmod
Normal file
363
Src/Hyperion-firmware-cct/lib/modules/CC-Tweaked/25_tty.kmod
Normal file
@@ -0,0 +1,363 @@
|
||||
-- :Minify:--
|
||||
local kernel = ...
|
||||
local apis = kernel.apis
|
||||
local native = apis.peripheral
|
||||
local sides = {"top", "bottom", "left", "right", "front", "back"}
|
||||
local peripheral={}
|
||||
|
||||
function peripheral.getNames()
|
||||
local results = {}
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.isPresent(side) then
|
||||
table.insert(results, side)
|
||||
if native.hasType(side, "peripheral_hub") then
|
||||
local remote = native.call(side, "getNamesRemote")
|
||||
for _, name in ipairs(remote) do
|
||||
table.insert(results, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return results
|
||||
end
|
||||
|
||||
function peripheral.isPresent(name)
|
||||
if native.isPresent(name) then
|
||||
return true
|
||||
end
|
||||
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function peripheral.getType(peripheral)
|
||||
if type(peripheral) == "string" then -- Peripheral name passed
|
||||
if native.isPresent(peripheral) then
|
||||
return native.getType(peripheral)
|
||||
end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
|
||||
return native.call(side, "getTypeRemote", peripheral)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
local mt = getmetatable(peripheral)
|
||||
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
|
||||
error("bad argument #1 (table is not a peripheral)", 2)
|
||||
end
|
||||
return table.unpack(mt.types)
|
||||
end
|
||||
end
|
||||
|
||||
function peripheral.hasType(peripheral, peripheral_type)
|
||||
if type(peripheral) == "string" then -- Peripheral name passed
|
||||
if native.isPresent(peripheral) then
|
||||
return native.hasType(peripheral, peripheral_type)
|
||||
end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
|
||||
return native.call(side, "hasTypeRemote", peripheral, peripheral_type)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
local mt = getmetatable(peripheral)
|
||||
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
|
||||
error("bad argument #1 (table is not a peripheral)", 2)
|
||||
end
|
||||
return mt.types[peripheral_type] ~= nil
|
||||
end
|
||||
end
|
||||
|
||||
function peripheral.getMethods(name)
|
||||
if native.isPresent(name) then
|
||||
return native.getMethods(name)
|
||||
end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||
return native.call(side, "getMethodsRemote", name)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function peripheral.getName(peripheral)
|
||||
local mt = getmetatable(peripheral)
|
||||
if not mt or mt.__name ~= "peripheral" or type(mt.name) ~= "string" then
|
||||
error("bad argument #1 (table is not a peripheral)", 2)
|
||||
end
|
||||
return mt.name
|
||||
end
|
||||
|
||||
function peripheral.call(name, method, ...)
|
||||
if native.isPresent(name) then
|
||||
return native.call(name, method, ...)
|
||||
end
|
||||
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
|
||||
return native.call(side, "callRemote", name, method, ...)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function peripheral.wrap(name)
|
||||
local methods = peripheral.getMethods(name)
|
||||
if not methods then
|
||||
return nil
|
||||
end
|
||||
|
||||
local types = { peripheral.getType(name) }
|
||||
for i = 1, #types do types[types[i]] = true end
|
||||
local result = setmetatable({}, {
|
||||
__name = "peripheral",
|
||||
name = name,
|
||||
type = types[1],
|
||||
types = types,
|
||||
})
|
||||
for _, method in ipairs(methods) do
|
||||
result[method] = function(...)
|
||||
return peripheral.call(name, method, ...)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function peripheral.find(ty, filter)
|
||||
local results = {}
|
||||
for _, name in ipairs(peripheral.getNames()) do
|
||||
if peripheral.hasType(name, ty) then
|
||||
local wrapped = peripheral.wrap(name)
|
||||
if filter == nil or filter(name, wrapped) then
|
||||
table.insert(results, wrapped)
|
||||
end
|
||||
end
|
||||
end
|
||||
return table.unpack(results)
|
||||
end
|
||||
|
||||
local icolors = {
|
||||
[0x1] = 1, -- #000000
|
||||
[0x2] = 2, -- #FFFFFF
|
||||
[0x4] = 3, -- #FF0000
|
||||
[0x8] = 4, -- #00FF00
|
||||
[0x10] = 5, -- #0000FF
|
||||
[0x20] = 6, -- #00FFFF
|
||||
[0x40] = 7, -- #FF00FF
|
||||
[0x80] = 8, -- #FFFF00
|
||||
[0x100] = 9, -- #FF6D00
|
||||
[0x200] = 10, -- #6DFF55
|
||||
[0x400] = 11, -- #24FFFF
|
||||
[0x800] = 12, -- #924900
|
||||
[0x1000] = 13, -- #6D6D55
|
||||
[0x2000] = 14, -- #DBDBAA
|
||||
[0x4000] = 15, -- #6D00FF
|
||||
[0x8000] = 16 -- #B6FF00
|
||||
}
|
||||
|
||||
local colors = {
|
||||
0x0001, -- #000000
|
||||
0x0002, -- #FFFFFF
|
||||
0x0004, -- #FF0000
|
||||
0x0008, -- #00FF00
|
||||
0x0010, -- #0000FF
|
||||
0x0020, -- #00FFFF
|
||||
0x0040, -- #FF00FF
|
||||
0x0080, -- #FFFF00
|
||||
0x0100, -- #FF6D00
|
||||
0x0200, -- #6DFF55
|
||||
0x0400, -- #24FFFF
|
||||
0x0800, -- #924900
|
||||
0x1000, -- #6D6D55
|
||||
0x2000, -- #DBDBAA
|
||||
0x4000, -- #6D00FF
|
||||
0x8000 -- #B6FF00
|
||||
}
|
||||
|
||||
local function write(text, term)
|
||||
local x, y = term.getCursorPos()
|
||||
local w, h = term.getSize()
|
||||
|
||||
for i = 1, #text do
|
||||
local c = text:sub(i, i)
|
||||
|
||||
if c == "\n" then
|
||||
y = y + 1
|
||||
x = 1
|
||||
elseif c == "\t" then
|
||||
local tabSize = 4
|
||||
local spaces = tabSize - ((x - 1) % tabSize)
|
||||
term.write(string.rep(" ", spaces))
|
||||
x = x + spaces
|
||||
elseif c == "\b" then
|
||||
if x > 1 then
|
||||
x = x - 1
|
||||
term.setCursorPos(x, y)
|
||||
term.write(" ")
|
||||
term.setCursorPos(x, y)
|
||||
end
|
||||
else
|
||||
if x <= w and y <= h then
|
||||
term.setCursorPos(x, y)
|
||||
term.write(c)
|
||||
x = x + 1
|
||||
end
|
||||
end
|
||||
|
||||
if x > w then
|
||||
x = 1
|
||||
y = y + 1
|
||||
end
|
||||
|
||||
if y - 1 >= h then
|
||||
term.scroll(1)
|
||||
y = h
|
||||
term.setCursorPos(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
term.setCursorPos(x, y)
|
||||
end
|
||||
|
||||
kernel.devfs.data.tty={}
|
||||
local ctrl,alt = false, false
|
||||
|
||||
local function s(bool)
|
||||
if bool then
|
||||
return "T"
|
||||
else
|
||||
return "F"
|
||||
end
|
||||
end
|
||||
|
||||
local function newtty(obj, id, ev)
|
||||
kernel.devfs.data["tty"][id] = function(op, mode)
|
||||
if op=="type" then
|
||||
return "character device"
|
||||
elseif op=="open" then
|
||||
local h = {
|
||||
read=function(amount)
|
||||
local rv=""
|
||||
for i=1, amount or 1 do
|
||||
local event = {ev()}
|
||||
if event[1] then
|
||||
rv=rv..event[1]
|
||||
end
|
||||
end
|
||||
if rv=="" then rv=nil end
|
||||
return rv
|
||||
end,
|
||||
write=function(content)
|
||||
write(content, obj)
|
||||
end,
|
||||
size=function()
|
||||
local s={obj.getSize()}
|
||||
return table.concat(s,";")
|
||||
end,
|
||||
clear=function()
|
||||
obj.clear()
|
||||
obj.setCursorPos(1,1)
|
||||
end,
|
||||
gpos=function()
|
||||
local s={obj.getCursorPos()}
|
||||
return table.concat(s,";")
|
||||
end,
|
||||
spos=function(x,y)
|
||||
return obj.setCursorPos(x,y)
|
||||
end,
|
||||
sfgc=function(c)
|
||||
return obj.setTextColor(colors[c])
|
||||
end,
|
||||
sbgc=function(c)
|
||||
return obj.setBackgroundColor(colors[c])
|
||||
end,
|
||||
gfgc=function()
|
||||
return icolors[obj.getTextColor()]
|
||||
end,
|
||||
gbgc=function()
|
||||
return icolors[obj.getBackgroundColor()]
|
||||
end,
|
||||
gctrl=function()
|
||||
return s(ctrl)..";"..s(alt)
|
||||
end
|
||||
}
|
||||
if mode=="rw" then
|
||||
return h
|
||||
elseif mode=="r" then
|
||||
h["write"]=nil
|
||||
return h
|
||||
elseif mode=="w" then
|
||||
h["read"]=nil
|
||||
return h
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local fifo = kernel.newFifo()
|
||||
|
||||
kernel.processes.cctmond = function()
|
||||
local timeout = false
|
||||
while true do
|
||||
local event = {kernel.computer:getMachineEvent()}
|
||||
|
||||
if event[1] then
|
||||
local eventType = event[1]
|
||||
local charOrKey = event[3]
|
||||
|
||||
-- Update modifier keys
|
||||
if eventType == "keyPressed" then
|
||||
if charOrKey == apis.keys.leftCtrl or charOrKey == apis.keys.rightCtrl then
|
||||
ctrl = true
|
||||
elseif charOrKey == apis.keys.leftAlt or charOrKey == apis.keys.rightAlt then
|
||||
alt = true
|
||||
end
|
||||
|
||||
-- Handle Ctrl+C
|
||||
if ctrl and charOrKey == apis.keys.c then
|
||||
for _, task in ipairs(syscall.getTasks()) do
|
||||
syscall.sigsend(task, 1) -- SIGINT
|
||||
end
|
||||
end
|
||||
|
||||
elseif eventType == "keyReleased" then
|
||||
if charOrKey == apis.keys.leftCtrl or charOrKey == apis.keys.rightCtrl then
|
||||
ctrl = false
|
||||
elseif charOrKey == apis.keys.leftAlt or charOrKey == apis.keys.rightAlt then
|
||||
alt = false
|
||||
end
|
||||
|
||||
elseif eventType == "keyTyped" then
|
||||
if charOrKey then fifo.push(charOrKey) end
|
||||
end
|
||||
|
||||
timeout = false
|
||||
else
|
||||
timeout = true
|
||||
end
|
||||
|
||||
if timeout then
|
||||
sleep(0.05)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
newtty(apis.term, "TTY1", fifo.pop)
|
||||
|
||||
for i,v in ipairs({peripheral.find("monitor")}) do
|
||||
v.setTextScale(.5)
|
||||
v.write("Initializing...")
|
||||
newtty(v,"TTY"..tostring(i+1),function () end)
|
||||
end
|
||||
@@ -1,164 +0,0 @@
|
||||
-- :Minify:--
|
||||
local kernel = ...
|
||||
local apis = kernel.apis
|
||||
local main = apis.term
|
||||
local native = apis.peripheral
|
||||
local sides = {"top", "bottom", "left", "right", "front", "back"}
|
||||
|
||||
local function getType(name)
|
||||
if native.isPresent(name) then return native.getType(name) end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and
|
||||
native.call(side, "isPresentRemote", name) then
|
||||
return native.call(side, "getTypeRemote", name)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function getNames()
|
||||
local names = {}
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.isPresent(side) then table.insert(names, side) end
|
||||
if native.hasType(side, "peripheral_hub") then
|
||||
local hubSides = native.call(side, "getConnectedSides")
|
||||
for _, hubSide in ipairs(hubSides) do
|
||||
table.insert(names, hubSide)
|
||||
end
|
||||
end
|
||||
end
|
||||
return names
|
||||
end
|
||||
|
||||
local function wrapPeripheral(name)
|
||||
if native.isPresent(name) then return wrapPeripheral(name) end
|
||||
for n = 1, #sides do
|
||||
local side = sides[n]
|
||||
if native.hasType(side, "peripheral_hub") and
|
||||
native.call(side, "isPresentRemote", name) then
|
||||
return native.call(side, "wrapRemote", name)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local icolors = {
|
||||
[0x1] = 1, -- #000000
|
||||
[0x2] = 2, -- #FFFFFF
|
||||
[0x4] = 3, -- #FF0000
|
||||
[0x8] = 4, -- #00FF00
|
||||
[0x10] = 5, -- #0000FF
|
||||
[0x20] = 6, -- #00FFFF
|
||||
[0x40] = 7, -- #FF00FF
|
||||
[0x80] = 8, -- #FFFF00
|
||||
[0x100] = 9, -- #FF6D00
|
||||
[0x200] = 10, -- #6DFF55
|
||||
[0x400] = 11, -- #24FFFF
|
||||
[0x800] = 12, -- #924900
|
||||
[0x1000] = 13, -- #6D6D55
|
||||
[0x2000] = 14, -- #DBDBAA
|
||||
[0x4000] = 15, -- #6D00FF
|
||||
[0x8000] = 16 -- #B6FF00
|
||||
}
|
||||
|
||||
local colors = {
|
||||
0x0001, -- #000000
|
||||
0x0002, -- #FFFFFF
|
||||
0x0004, -- #FF0000
|
||||
0x0008, -- #00FF00
|
||||
0x0010, -- #0000FF
|
||||
0x0020, -- #00FFFF
|
||||
0x0040, -- #FF00FF
|
||||
0x0080, -- #FFFF00
|
||||
0x0100, -- #FF6D00
|
||||
0x0200, -- #6DFF55
|
||||
0x0400, -- #24FFFF
|
||||
0x0800, -- #924900
|
||||
0x1000, -- #6D6D55
|
||||
0x2000, -- #DBDBAA
|
||||
0x4000, -- #6D00FF
|
||||
0x8000 -- #B6FF00
|
||||
}
|
||||
|
||||
local function write(text, term)
|
||||
local x, y = term.getCursorPos()
|
||||
local w, h = term.getSize()
|
||||
|
||||
for i = 1, #text do
|
||||
local c = text:sub(i, i)
|
||||
|
||||
if c == "\n" then
|
||||
y = y + 1
|
||||
x = 1
|
||||
elseif c == "\t" then
|
||||
local tabSize = 4
|
||||
local spaces = tabSize - ((x - 1) % tabSize)
|
||||
term.write(string.rep(" ", spaces))
|
||||
x = x + spaces
|
||||
elseif c == "\b" then
|
||||
if x > 1 then
|
||||
x = x - 1
|
||||
term.setCursorPos(x, y)
|
||||
term.write(" ")
|
||||
term.setCursorPos(x, y)
|
||||
end
|
||||
else
|
||||
if x <= w and y <= h then
|
||||
term.setCursorPos(x, y)
|
||||
term.write(c)
|
||||
x = x + 1
|
||||
end
|
||||
end
|
||||
|
||||
if x > w then
|
||||
x = 1
|
||||
y = y + 1
|
||||
end
|
||||
|
||||
if y - 1 >= h then
|
||||
term.scroll(1)
|
||||
y = h
|
||||
term.setCursorPos(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
term.setCursorPos(x, y)
|
||||
end
|
||||
|
||||
local function newTTY(term)
|
||||
local ret = {}
|
||||
function ret.print(text) write(text .. "\n", term) end
|
||||
function ret.printInline(text) write(text, term) end
|
||||
function ret.clear()
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
end
|
||||
function ret.setCursorPos(x, y) term.setCursorPos(x, y) end
|
||||
function ret.getCursorPos() return term.getCursorPos() end
|
||||
function ret.getSize() return term.getSize() end
|
||||
function ret.setBackgroundColor(color)
|
||||
term.setBackgroundColor(colors[color])
|
||||
end
|
||||
function ret.setTextColor(color) term.setTextColor(colors[color]) end
|
||||
function ret.getBackgroundColor()
|
||||
return icolors[term.getBackgroundColor()]
|
||||
end
|
||||
function ret.getTextColor() return icolors[term.getTextColor()] end
|
||||
return ret
|
||||
end
|
||||
|
||||
kernel.tty.register("tty0", newTTY(main))
|
||||
|
||||
for _, name in ipairs(getNames()) do
|
||||
local t = getType(name)
|
||||
if t == "monitor" then
|
||||
local monitorTerm = wrapPeripheral(name)
|
||||
if not monitorTerm then
|
||||
error("Failed to wrap monitor peripheral")
|
||||
end
|
||||
monitorTerm.setTextScale(0.5)
|
||||
kernel.tty.register(name, newTTY(monitorTerm))
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user