diff --git a/src/lua/core/computer.lua b/src/lua/core/computer.lua index 4e32102..f90c173 100644 --- a/src/lua/core/computer.lua +++ b/src/lua/core/computer.lua @@ -62,30 +62,30 @@ local keymap = { [0x60 + 0x01] = 0x1E, [0x60 + 0x02] = 0x30, - [0x60 + 0x04] = 0x2E, - [0x60 + 0x05] = 0x20, - [0x60 + 0x06] = 0x12, - [0x60 + 0x07] = 0x21, - [0x60 + 0x08] = 0x22, - [0x60 + 0x09] = 0x23, - [0x60 + 0x0A] = 0x17, - [0x60 + 0x0B] = 0x24, - [0x60 + 0x0C] = 0x25, - [0x60 + 0x0D] = 0x26, - [0x60 + 0x0E] = 0x32, - [0x60 + 0x0F] = 0x31, - [0x60 + 0x11] = 0x18, - [0x60 + 0x12] = 0x19, - [0x60 + 0x13] = 0x10, - [0x60 + 0x14] = 0x13, - [0x60 + 0x15] = 0x1F, - [0x60 + 0x16] = 0x14, - [0x60 + 0x17] = 0x16, - [0x60 + 0x18] = 0x2F, - [0x60 + 0x19] = 0x11, - [0x60 + 0x1A] = 0x2D, - [0x60 + 0x1B] = 0x15, - [0x60 + 0x1C] = 0x2C, + [0x60 + 0x03] = 0x2E, + [0x60 + 0x04] = 0x20, + [0x60 + 0x05] = 0x12, + [0x60 + 0x06] = 0x21, + [0x60 + 0x07] = 0x22, + [0x60 + 0x08] = 0x23, + [0x60 + 0x09] = 0x17, + [0x60 + 0x0A] = 0x24, + [0x60 + 0x0B] = 0x25, + [0x60 + 0x0C] = 0x26, + [0x60 + 0x0D] = 0x32, + [0x60 + 0x0E] = 0x31, + [0x60 + 0x0F] = 0x18, + [0x60 + 0x10] = 0x19, + [0x60 + 0x11] = 0x10, + [0x60 + 0x12] = 0x13, + [0x60 + 0x13] = 0x1F, + [0x60 + 0x13] = 0x14, + [0x60 + 0x14] = 0x16, + [0x60 + 0x16] = 0x2F, + [0x60 + 0x17] = 0x11, + [0x60 + 0x18] = 0x2D, + [0x60 + 0x19] = 0x15, + [0x60 + 0x1A] = 0x2C, [13] = 28, --Return key [127] = 14, --backspace @@ -105,21 +105,33 @@ local escmap = { } local inesc_down = false +local esc_down_ctrl = false function computer.signalTransformers.key_down(s, a, ascii, key, user) if key ~= -1 then return s, a, ascii, key, user end if ascii == 27 then - inesc_down = native.uptime() / 1000 + inesc_down = native.uptime() 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 if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then inesc_down = false 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} return nil else + esc_down_ctrl = false inesc_down = false end end @@ -127,21 +139,33 @@ function computer.signalTransformers.key_down(s, a, ascii, key, user) end local inesc_up = false +local esc_up_ctrl = false function computer.signalTransformers.key_up(s, a, ascii, key, user) if key ~= -1 then return s, a, ascii, key, user end if ascii == 27 then - inesc_up = native.uptime() / 1000 + inesc_up = native.uptime() 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 if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then inesc_up = false 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} return nil else + esc_up_ctrl = false inesc_up = false end end diff --git a/src/lua/core/textgpu.lua b/src/lua/core/textgpu.lua index f66946b..096bd6f 100644 --- a/src/lua/core/textgpu.lua +++ b/src/lua/core/textgpu.lua @@ -156,6 +156,7 @@ function textgpu.start() function gpu.setForeground(color, ispalette) checkArg(1, color, "number") checkArg(2, ispalette, "boolean", "nil") + local ret = color if ispalette then if not palette[color] then error("invalid palette index", 2) @@ -164,12 +165,13 @@ function textgpu.start() end local index = math.floor(modules.color.nearest(color, mapping)) fg = index or fg - return true + return ret, ispalette end function gpu.setBackground(color, ispalette) checkArg(1, color, "number") checkArg(2, ispalette, "boolean", "nil") + local ret = color if ispalette then if not palette[color] then error("invalid palette index", 2) @@ -178,7 +180,7 @@ function textgpu.start() end local index = math.floor(modules.color.nearest(color, mapping)) bg = index or bg - return true + return ret, ispalette end function gpu.setPaletteColor(c, v)