fixed an incompatibility in textgpu; fixed ctrl+KEY under OpenOS

This commit is contained in:
ocawesome101 2021-06-04 17:14:29 -04:00
parent b16fa6aeb7
commit f847f6a2ca
2 changed files with 56 additions and 30 deletions

View File

@ -62,30 +62,30 @@ local keymap = {
[0x60 + 0x01] = 0x1E, [0x60 + 0x01] = 0x1E,
[0x60 + 0x02] = 0x30, [0x60 + 0x02] = 0x30,
[0x60 + 0x04] = 0x2E, [0x60 + 0x03] = 0x2E,
[0x60 + 0x05] = 0x20, [0x60 + 0x04] = 0x20,
[0x60 + 0x06] = 0x12, [0x60 + 0x05] = 0x12,
[0x60 + 0x07] = 0x21, [0x60 + 0x06] = 0x21,
[0x60 + 0x08] = 0x22, [0x60 + 0x07] = 0x22,
[0x60 + 0x09] = 0x23, [0x60 + 0x08] = 0x23,
[0x60 + 0x0A] = 0x17, [0x60 + 0x09] = 0x17,
[0x60 + 0x0B] = 0x24, [0x60 + 0x0A] = 0x24,
[0x60 + 0x0C] = 0x25, [0x60 + 0x0B] = 0x25,
[0x60 + 0x0D] = 0x26, [0x60 + 0x0C] = 0x26,
[0x60 + 0x0E] = 0x32, [0x60 + 0x0D] = 0x32,
[0x60 + 0x0F] = 0x31, [0x60 + 0x0E] = 0x31,
[0x60 + 0x11] = 0x18, [0x60 + 0x0F] = 0x18,
[0x60 + 0x12] = 0x19, [0x60 + 0x10] = 0x19,
[0x60 + 0x13] = 0x10, [0x60 + 0x11] = 0x10,
[0x60 + 0x14] = 0x13, [0x60 + 0x12] = 0x13,
[0x60 + 0x15] = 0x1F, [0x60 + 0x13] = 0x1F,
[0x60 + 0x16] = 0x14, [0x60 + 0x13] = 0x14,
[0x60 + 0x17] = 0x16, [0x60 + 0x14] = 0x16,
[0x60 + 0x18] = 0x2F, [0x60 + 0x16] = 0x2F,
[0x60 + 0x19] = 0x11, [0x60 + 0x17] = 0x11,
[0x60 + 0x1A] = 0x2D, [0x60 + 0x18] = 0x2D,
[0x60 + 0x1B] = 0x15, [0x60 + 0x19] = 0x15,
[0x60 + 0x1C] = 0x2C, [0x60 + 0x1A] = 0x2C,
[13] = 28, --Return key [13] = 28, --Return key
[127] = 14, --backspace [127] = 14, --backspace
@ -105,21 +105,33 @@ local escmap = {
} }
local inesc_down = false local inesc_down = false
local esc_down_ctrl = false
function computer.signalTransformers.key_down(s, a, ascii, key, user) function computer.signalTransformers.key_down(s, a, ascii, key, user)
if key ~= -1 then if key ~= -1 then
return s, a, ascii, key, user return s, a, ascii, key, user
end end
if ascii == 27 then if ascii == 27 then
inesc_down = native.uptime() / 1000 inesc_down = native.uptime()
return nil return nil
elseif ascii < 27 and ascii ~= 8 and ascii ~= 13 and ascii ~= 9 then
signalQueue[#signalQueue + 1] = {s, a, 0, 29, user}
key = keymap[ascii + 96] or -1
elseif inesc_down then elseif inesc_down then
if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then
inesc_down = false inesc_down = false
key = escmap[ascii] or 0 key = escmap[ascii] or 0
ascii = 0 if not esc_down_ctrl then
--ascii = math.max(0, ascii - 96)
else
ascii = 0
end
esc_down_ctrl = false
elseif ascii == 91 then
esc_down_ctrl = true
elseif native.uptime() - inesc_down > 100 then -- 100ms timeout after {ESC} elseif native.uptime() - inesc_down > 100 then -- 100ms timeout after {ESC}
return nil return nil
else else
esc_down_ctrl = false
inesc_down = false inesc_down = false
end end
end end
@ -127,21 +139,33 @@ function computer.signalTransformers.key_down(s, a, ascii, key, user)
end end
local inesc_up = false local inesc_up = false
local esc_up_ctrl = false
function computer.signalTransformers.key_up(s, a, ascii, key, user) function computer.signalTransformers.key_up(s, a, ascii, key, user)
if key ~= -1 then if key ~= -1 then
return s, a, ascii, key, user return s, a, ascii, key, user
end end
if ascii == 27 then if ascii == 27 then
inesc_up = native.uptime() / 1000 inesc_up = native.uptime()
return nil return nil
elseif ascii < 27 and ascii ~= 8 and ascii ~= 13 and ascii ~= 9 then
signalQueue[#signalQueue+1] = {s, a, 0, 29, user}
key = keymap[ascii + 96] or 0
elseif inesc_up then elseif inesc_up then
if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then
inesc_up = false inesc_up = false
key = escmap[ascii] or 0 key = escmap[ascii] or 0
ascii = 0 if not esc_up_ctrl then
--ascii = math.max(0, ascii - 96)
else
ascii = 0
end
esc_up_ctrl = false
elseif ascii == 91 then
esc_up_ctrl = true
elseif native.uptime() - inesc_up > 100 then -- 100ms timeout after {ESC} elseif native.uptime() - inesc_up > 100 then -- 100ms timeout after {ESC}
return nil return nil
else else
esc_up_ctrl = false
inesc_up = false inesc_up = false
end end
end end

View File

@ -156,6 +156,7 @@ function textgpu.start()
function gpu.setForeground(color, ispalette) function gpu.setForeground(color, ispalette)
checkArg(1, color, "number") checkArg(1, color, "number")
checkArg(2, ispalette, "boolean", "nil") checkArg(2, ispalette, "boolean", "nil")
local ret = color
if ispalette then if ispalette then
if not palette[color] then if not palette[color] then
error("invalid palette index", 2) error("invalid palette index", 2)
@ -164,12 +165,13 @@ function textgpu.start()
end end
local index = math.floor(modules.color.nearest(color, mapping)) local index = math.floor(modules.color.nearest(color, mapping))
fg = index or fg fg = index or fg
return true return ret, ispalette
end end
function gpu.setBackground(color, ispalette) function gpu.setBackground(color, ispalette)
checkArg(1, color, "number") checkArg(1, color, "number")
checkArg(2, ispalette, "boolean", "nil") checkArg(2, ispalette, "boolean", "nil")
local ret = color
if ispalette then if ispalette then
if not palette[color] then if not palette[color] then
error("invalid palette index", 2) error("invalid palette index", 2)
@ -178,7 +180,7 @@ function textgpu.start()
end end
local index = math.floor(modules.color.nearest(color, mapping)) local index = math.floor(modules.color.nearest(color, mapping))
bg = index or bg bg = index or bg
return true return ret, ispalette
end end
function gpu.setPaletteColor(c, v) function gpu.setPaletteColor(c, v)