Make the terminal suck less.
This commit is contained in:
@@ -67,52 +67,79 @@ function module.init()
|
|||||||
end
|
end
|
||||||
if depth == 4 then
|
if depth == 4 then
|
||||||
return {
|
return {
|
||||||
|
-- Closest colors to the 4 bit OC pallete
|
||||||
|
-- Better than outright failure
|
||||||
["dark"] = {
|
["dark"] = {
|
||||||
[0] = 0x000000,
|
[0] = 0x000000, -- black
|
||||||
[1] = 0x800000,
|
[1] = 0x663300, -- brown (dark red)
|
||||||
[2] = 0x008000,
|
[2] = 0x336600, -- green (dark green)
|
||||||
[3] = 0x808000,
|
[3] = 0x336600, -- green (dark yellow)
|
||||||
[4] = 0x000080,
|
[4] = 0x333399, -- blue (dark blue)
|
||||||
[5] = 0x800080,
|
[5] = 0x9933CC, -- purple (dark purple)
|
||||||
[6] = 0x008080,
|
[6] = 0x333399, -- blue (dark cyan)
|
||||||
[7] = 0xC0C0C0
|
[7] = 0xCCCCCC -- silver (dark white)
|
||||||
},
|
},
|
||||||
["bright"] = {
|
["bright"] = {
|
||||||
[0] = 0x808080,
|
[0] = 0x333333, -- gray (bright black)
|
||||||
[1] = 0xFF0000,
|
[1] = 0xff3333, -- red
|
||||||
[2] = 0x00FF00,
|
[2] = 0x33cc33, -- lime (green)
|
||||||
[3] = 0xFFFF00,
|
[3] = 0xffff33, -- yellow
|
||||||
[4] = 0x0000FF,
|
[4] = 0x333399, -- blue
|
||||||
[5] = 0xFF00FF,
|
[5] = 0xcc66cc, -- magenta (purple)
|
||||||
[6] = 0x00FFFF,
|
[6] = 0x336699, -- cyan
|
||||||
[7] = 0xFFFFFF
|
[7] = 0xffffff -- white
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if depth == 8 then
|
if depth == 8 then
|
||||||
return {
|
return {
|
||||||
["dark"] = {
|
["dark"] = {
|
||||||
[0] = 0x171421,
|
[0] = 0x0f0f0f, -- black
|
||||||
[1] = 0xc01c28,
|
[1] = 0xcc2424, -- dark red
|
||||||
[2] = 0x26a269,
|
[2] = 0x339280, -- dark green
|
||||||
[3] = 0xa2734c,
|
[3] = 0x996d00, -- dark yellow
|
||||||
[4] = 0x12488b,
|
[4] = 0x004980, -- dark blue
|
||||||
[5] = 0xa347ba,
|
[5] = 0x9949c0, -- dark purple
|
||||||
[6] = 0x2aa1b3,
|
[6] = 0x33b6c0, -- dark cyan
|
||||||
[7] = 0xd0cfcc
|
[7] = 0xffcccc -- dark white
|
||||||
},
|
},
|
||||||
["bright"] = {
|
["bright"] = {
|
||||||
[0] = 0x5e5c64,
|
[0] = 0x666d80, -- brighter black
|
||||||
[1] = 0xf66151,
|
[1] = 0xff6d40, -- red
|
||||||
[2] = 0x33d17a,
|
[2] = 0x33db80, -- green
|
||||||
[3] = 0xe9ad0c,
|
[3] = 0xffb600, -- yellow
|
||||||
[4] = 0x2a7bde,
|
[4] = 0x336dff, -- blue
|
||||||
[5] = 0xc061cb,
|
[5] = 0xcc6dc0, -- purple
|
||||||
[6] = 0x33c7de,
|
[6] = 0x33dbc0, -- cyan
|
||||||
[7] = 0xffffff
|
[7] = 0xffffff -- white
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
--[[ Original color palette:
|
||||||
|
{
|
||||||
|
["dark"] = {
|
||||||
|
[0] = 0x171421,
|
||||||
|
[1] = 0xc01c28,
|
||||||
|
[2] = 0x26a269,
|
||||||
|
[3] = 0xa2734c,
|
||||||
|
[4] = 0x12488b,
|
||||||
|
[5] = 0xa347ba,
|
||||||
|
[6] = 0x2aa1b3,
|
||||||
|
[7] = 0xd0cfcc
|
||||||
|
},
|
||||||
|
["bright"] = {
|
||||||
|
[0] = 0x5e5c64,
|
||||||
|
[1] = 0xf66151,
|
||||||
|
[2] = 0x33d17a,
|
||||||
|
[3] = 0xe9ad0c,
|
||||||
|
[4] = 0x2a7bde,
|
||||||
|
[5] = 0xc061cb,
|
||||||
|
[6] = 0x33c7de,
|
||||||
|
[7] = 0xffffff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
-- Shouldn't reach here
|
||||||
error()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -133,6 +160,8 @@ function module.init()
|
|||||||
local bytes_remaining = 0
|
local bytes_remaining = 0
|
||||||
local seq = {}
|
local seq = {}
|
||||||
|
|
||||||
|
local writeBuf = {}
|
||||||
|
|
||||||
local function update_gpu_colors()
|
local function update_gpu_colors()
|
||||||
if color.reverse then
|
if color.reverse then
|
||||||
gpu.setForeground(color.bg)
|
gpu.setForeground(color.bg)
|
||||||
@@ -422,6 +451,7 @@ function module.init()
|
|||||||
|
|
||||||
function _G._PUBLIC.terminal.writec(byte)
|
function _G._PUBLIC.terminal.writec(byte)
|
||||||
if byte == 0x1b then
|
if byte == 0x1b then
|
||||||
|
_PUBLIC.terminal.flush()
|
||||||
printState = 1
|
printState = 1
|
||||||
seq = {}
|
seq = {}
|
||||||
return
|
return
|
||||||
@@ -447,6 +477,7 @@ function module.init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if byte == 0xa then
|
if byte == 0xa then
|
||||||
|
_PUBLIC.terminal.flush()
|
||||||
cursor.y = cursor.y + 1
|
cursor.y = cursor.y + 1
|
||||||
cursor.x = 1
|
cursor.x = 1
|
||||||
check_wrap_and_scroll()
|
check_wrap_and_scroll()
|
||||||
@@ -454,11 +485,13 @@ function module.init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if byte == 0xd then
|
if byte == 0xd then
|
||||||
|
_PUBLIC.terminal.flush()
|
||||||
cursor.x = 1
|
cursor.x = 1
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if byte == 0x8 then
|
if byte == 0x8 then
|
||||||
|
_PUBLIC.terminal.flush()
|
||||||
if cursor.x > 1 then
|
if cursor.x > 1 then
|
||||||
cursor.x = cursor.x - 1
|
cursor.x = cursor.x - 1
|
||||||
end
|
end
|
||||||
@@ -466,17 +499,20 @@ function module.init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if byte == 0x9 then
|
if byte == 0x9 then
|
||||||
|
_PUBLIC.terminal.flush()
|
||||||
cursor.x = ((cursor.x - 1) // 8) * 8 + 9
|
cursor.x = ((cursor.x - 1) // 8) * 8 + 9
|
||||||
if cursor.x < 1 then cursor.x = 1 end
|
if cursor.x < 1 then cursor.x = 1 end
|
||||||
if cursor.x > width then cursor.x = width end
|
if cursor.x > width then cursor.x = width end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if byte >= 0x00 and byte <= 0x7F then
|
if byte >= 0x20 and byte <= 0x7F then
|
||||||
update_gpu_colors()
|
table.insert(writeBuf, string.char(byte))
|
||||||
gpu.set(cursor.x, cursor.y, string.char(byte))
|
|
||||||
cursor.x = cursor.x + 1
|
cursor.x = cursor.x + 1
|
||||||
check_wrap_and_scroll()
|
check_wrap_and_scroll()
|
||||||
|
if cursor.y ~= writeBufY or #writeBuf >= 32 then
|
||||||
|
_PUBLIC.terminal.flush()
|
||||||
|
end
|
||||||
elseif byte >= 0xC2 and byte <= 0xDF then
|
elseif byte >= 0xC2 and byte <= 0xDF then
|
||||||
current_codepoint = (byte & 0x1F)
|
current_codepoint = (byte & 0x1F)
|
||||||
bytes_remaining = 1
|
bytes_remaining = 1
|
||||||
@@ -490,11 +526,12 @@ function module.init()
|
|||||||
current_codepoint = (current_codepoint << 6) | (byte & 0x3F)
|
current_codepoint = (current_codepoint << 6) | (byte & 0x3F)
|
||||||
bytes_remaining = bytes_remaining - 1
|
bytes_remaining = bytes_remaining - 1
|
||||||
if bytes_remaining == 0 then
|
if bytes_remaining == 0 then
|
||||||
local char = utf8.char(current_codepoint)
|
table.insert(writeBuf, utf8.char(current_codepoint))
|
||||||
update_gpu_colors()
|
|
||||||
gpu.set(cursor.x, cursor.y, char)
|
|
||||||
cursor.x = cursor.x + 1
|
cursor.x = cursor.x + 1
|
||||||
check_wrap_and_scroll()
|
check_wrap_and_scroll()
|
||||||
|
if cursor.y ~= writeBufY or #writeBuf >= 32 then
|
||||||
|
_PUBLIC.terminal.flush()
|
||||||
|
end
|
||||||
current_codepoint = 0
|
current_codepoint = 0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -513,10 +550,18 @@ function module.init()
|
|||||||
function _G._PUBLIC.terminal.clear()
|
function _G._PUBLIC.terminal.clear()
|
||||||
update_gpu_colors()
|
update_gpu_colors()
|
||||||
gpu.fill(1, 1, width, height, " ")
|
gpu.fill(1, 1, width, height, " ")
|
||||||
|
writeBuf = {}
|
||||||
cursor.x = 1
|
cursor.x = 1
|
||||||
cursor.y = 1
|
cursor.y = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function _G._PUBLIC.terminal.flush()
|
||||||
|
if #writeBuf == 0 then return end
|
||||||
|
update_gpu_colors()
|
||||||
|
gpu.set(cursor.x - #writeBuf, cursor.y, table.concat(writeBuf))
|
||||||
|
writeBuf = {}
|
||||||
|
end
|
||||||
|
|
||||||
function _G.print(...)
|
function _G.print(...)
|
||||||
local args = {...}
|
local args = {...}
|
||||||
local stringArgs = {}
|
local stringArgs = {}
|
||||||
@@ -548,6 +593,8 @@ function module.init()
|
|||||||
|
|
||||||
local text = options.defaultText or ""
|
local text = options.defaultText or ""
|
||||||
|
|
||||||
|
_G._PUBLIC.terminal.flush()
|
||||||
|
|
||||||
local historyIdx
|
local historyIdx
|
||||||
if options.readHistoryType then
|
if options.readHistoryType then
|
||||||
if not readHistory[options.readHistoryType] then
|
if not readHistory[options.readHistoryType] then
|
||||||
|
|||||||
Reference in New Issue
Block a user