Cleaned up color code and rearranged panels.
This commit is contained in:
parent
3ad160a0a0
commit
0f03c6cc15
133
cursed.lua
133
cursed.lua
@ -1,6 +1,6 @@
|
|||||||
local C = require("curses")
|
local C = require("curses")
|
||||||
|
local re = require('re')
|
||||||
local repr = require('repr')
|
local repr = require('repr')
|
||||||
local COLORS = { }
|
|
||||||
local run_debugger, guard, stdscr
|
local run_debugger, guard, stdscr
|
||||||
local AUTO = { }
|
local AUTO = { }
|
||||||
local log = io.open("output.log", "w")
|
local log = io.open("output.log", "w")
|
||||||
@ -210,7 +210,6 @@ local line_tables = setmetatable({ }, {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
run_debugger = function(err_msg)
|
run_debugger = function(err_msg)
|
||||||
log:write(err_msg .. "\n\n")
|
|
||||||
stdscr = C.initscr()
|
stdscr = C.initscr()
|
||||||
SCREEN_H, SCREEN_W = stdscr:getmaxyx()
|
SCREEN_H, SCREEN_W = stdscr:getmaxyx()
|
||||||
C.cbreak()
|
C.cbreak()
|
||||||
@ -219,62 +218,106 @@ run_debugger = function(err_msg)
|
|||||||
C.curs_set(0)
|
C.curs_set(0)
|
||||||
C.start_color()
|
C.start_color()
|
||||||
C.use_default_colors()
|
C.use_default_colors()
|
||||||
local _
|
local color_index = 0
|
||||||
_, COLORS.REGULAR = C.init_pair(1, C.COLOR_WHITE, -1), C.color_pair(1)
|
local existing = { }
|
||||||
_, COLORS.INVERTED = C.init_pair(2, C.COLOR_WHITE, C.COLOR_BLACK), C.color_pair(2)
|
local make_color
|
||||||
_, COLORS.YELLOW_BG = C.init_pair(3, C.COLOR_BLACK, C.COLOR_YELLOW), C.color_pair(3)
|
make_color = function(fg, bg)
|
||||||
_, COLORS.RED = C.init_pair(4, C.COLOR_RED, -1), C.color_pair(4)
|
if fg == nil then
|
||||||
_, COLORS.BLUE = C.init_pair(5, C.COLOR_BLUE, -1), C.color_pair(5) | C.A_BOLD
|
fg = -1
|
||||||
_, COLORS.WHITE = C.init_pair(6, C.COLOR_WHITE, -1), C.color_pair(6)
|
end
|
||||||
_, COLORS.WHITE_BG = C.init_pair(7, C.COLOR_BLACK, C.COLOR_WHITE), C.color_pair(7)
|
if bg == nil then
|
||||||
_, COLORS.BROWN = C.init_pair(8, C.COLOR_BLACK, -1), C.color_pair(8) | C.A_BOLD
|
bg = -1
|
||||||
_, COLORS.RED_BG = C.init_pair(9, C.COLOR_YELLOW, C.COLOR_RED), C.color_pair(9) | C.A_BOLD | C.A_DIM
|
end
|
||||||
_, COLORS.GREEN = C.init_pair(10, C.COLOR_GREEN, -1), C.color_pair(10)
|
local key = tostring(fg) .. "," .. tostring(bg)
|
||||||
|
if not (existing[key]) then
|
||||||
|
color_index = color_index + 1
|
||||||
|
C.init_pair(color_index, fg, bg)
|
||||||
|
existing[key] = C.color_pair(color_index)
|
||||||
|
end
|
||||||
|
return existing[key]
|
||||||
|
end
|
||||||
|
local color_lang = re.compile([[ x <- {|
|
||||||
|
{:attrs: {| {attr} (" " {attr})* |} :}
|
||||||
|
/ ((({:fg: color :} (" on " {:bg: color :})?) / {:bg: "on " color :}) {:attrs: {| (" " {attr})* |} :})
|
||||||
|
|}
|
||||||
|
attr <- "blink" / "bold" / "dim" / "invis" / "normal" / "protect" / "reverse" / "standout" / "underline"
|
||||||
|
color <- "black" / "blue" / "cyan" / "green" / "magenta" / "red" / "white" / "yellow" / "default"
|
||||||
|
]])
|
||||||
|
C.COLOR_DEFAULT = -1
|
||||||
|
local color
|
||||||
|
color = function(s)
|
||||||
|
if s == nil then
|
||||||
|
s = "default"
|
||||||
|
end
|
||||||
|
local t = assert(color_lang:match(s), "Invalid color: " .. tostring(s))
|
||||||
|
if t.fg then
|
||||||
|
t.fg = C["COLOR_" .. t.fg:upper()]
|
||||||
|
end
|
||||||
|
if t.bg then
|
||||||
|
t.bg = C["COLOR_" .. t.bg:upper()]
|
||||||
|
end
|
||||||
|
local c = make_color(t.fg, t.bg)
|
||||||
|
local _list_0 = t.attrs
|
||||||
|
for _index_0 = 1, #_list_0 do
|
||||||
|
local a = _list_0[_index_0]
|
||||||
|
c = c | C["A_" .. a:upper()]
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
default_colors = {
|
default_colors = {
|
||||||
active_frame = COLORS.BLUE,
|
active_frame = color("blue"),
|
||||||
inactive_frame = COLORS.BROWN,
|
inactive_frame = color("bold black"),
|
||||||
line_colors = setmetatable({ }, {
|
line_colors = setmetatable({ }, {
|
||||||
__index = function(self, i)
|
__index = function(self, i)
|
||||||
return (i % 2 == 0 and COLORS.INVERTED or COLORS.REGULAR)
|
return (i % 2 == 0 and color("on black") or color())
|
||||||
end
|
end
|
||||||
}),
|
}),
|
||||||
highlight = COLORS.WHITE_BG,
|
highlight = color("black on white"),
|
||||||
active = COLORS.YELLOW_BG
|
active = color("black on yellow")
|
||||||
}
|
}
|
||||||
do
|
do
|
||||||
stdscr:wbkgd(COLORS.RED_BG)
|
stdscr:wbkgd(color("yellow on red bold"))
|
||||||
stdscr:clear()
|
stdscr:clear()
|
||||||
stdscr:refresh()
|
stdscr:refresh()
|
||||||
local lines = wrap_text("ERROR!\n \n " .. err_msg .. "\n \npress any key...", math.floor(SCREEN_W / 2))
|
local lines = wrap_text("ERROR!\n \n " .. err_msg .. "\n \npress any key...", math.floor(SCREEN_W / 2))
|
||||||
|
local max_line = 0
|
||||||
|
for _index_0 = 1, #lines do
|
||||||
|
local line = lines[_index_0]
|
||||||
|
max_line = math.max(max_line, #line)
|
||||||
|
end
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
stdscr:mvaddstr(math.floor(SCREEN_H / 2 - #lines / 2) + i, math.floor((SCREEN_W - #line) / 2), line)
|
if i == 1 or i == #lines then
|
||||||
|
stdscr:mvaddstr(math.floor(SCREEN_H / 2 - #lines / 2) + i, math.floor((SCREEN_W - #line) / 2), line)
|
||||||
|
else
|
||||||
|
stdscr:mvaddstr(math.floor(SCREEN_H / 2 - #lines / 2) + i, math.floor((SCREEN_W - max_line) / 2), line)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
stdscr:refresh()
|
stdscr:refresh()
|
||||||
C.doupdate()
|
C.doupdate()
|
||||||
stdscr:getch()
|
stdscr:getch()
|
||||||
end
|
end
|
||||||
stdscr:wbkgd(COLORS.REGULAR)
|
stdscr:wbkgd(color())
|
||||||
stdscr:clear()
|
stdscr:clear()
|
||||||
stdscr:refresh()
|
stdscr:refresh()
|
||||||
local pads = { }
|
local pads = { }
|
||||||
do
|
do
|
||||||
local err_msg_lines = wrap_text(err_msg, SCREEN_W - 4)
|
local err_msg_lines = wrap_text(err_msg, SCREEN_W - 4)
|
||||||
for i, line in ipairs(err_msg_lines) do
|
for i, line in ipairs(err_msg_lines) do
|
||||||
err_msg_lines[i] = (" "):rep(math.floor((SCREEN_W - 2 - #line) / 2)) .. line
|
err_msg_lines[i] = (" "):rep(2) .. line
|
||||||
end
|
end
|
||||||
pads.err = Pad(0, 0, AUTO, SCREEN_W, err_msg_lines, "Error Message", {
|
pads.err = Pad(0, 0, AUTO, SCREEN_W, err_msg_lines, "Error Message", {
|
||||||
line_colors = setmetatable({ }, {
|
line_colors = setmetatable({ }, {
|
||||||
__index = function()
|
__index = function()
|
||||||
return COLORS.RED | C.A_BOLD
|
return color("red bold")
|
||||||
end
|
end
|
||||||
}),
|
}),
|
||||||
inactive_frame = COLORS.RED | C.A_DIM
|
inactive_frame = color("red dim")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
local stack_locations = { }
|
local stack_locations = { }
|
||||||
do
|
do
|
||||||
local stack_names = { }
|
local stack_names = { }
|
||||||
local max_filename = 0
|
local max_filename, max_fn_name = 0, 0
|
||||||
local stack_min, stack_max = callstack_range()
|
local stack_min, stack_max = callstack_range()
|
||||||
for i = stack_min, stack_max do
|
for i = stack_min, stack_max do
|
||||||
local _continue_0 = false
|
local _continue_0 = false
|
||||||
@ -303,6 +346,7 @@ run_debugger = function(err_msg)
|
|||||||
end
|
end
|
||||||
table.insert(stack_locations, line)
|
table.insert(stack_locations, line)
|
||||||
max_filename = math.max(max_filename, #line)
|
max_filename = math.max(max_filename, #line)
|
||||||
|
max_fn_name = math.max(max_fn_name, #stack_names[#stack_names])
|
||||||
_continue_0 = true
|
_continue_0 = true
|
||||||
until true
|
until true
|
||||||
if not _continue_0 then
|
if not _continue_0 then
|
||||||
@ -310,12 +354,12 @@ run_debugger = function(err_msg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local callstack = { }
|
local callstack = { }
|
||||||
|
local max_line = 0
|
||||||
for i = 1, #stack_names do
|
for i = 1, #stack_names do
|
||||||
callstack[i] = stack_locations[i] .. (" "):rep(max_filename - #stack_locations[i]) .. " | " .. stack_names[i] .. " "
|
callstack[i] = ("%-" .. max_fn_name .. "s | %s"):format(stack_names[i], stack_locations[i])
|
||||||
|
max_line = math.max(max_line, #callstack[i])
|
||||||
end
|
end
|
||||||
pads.stack = Pad(pads.err.height, 0, math.max(#callstack + 2, 20), AUTO, callstack, "(C)allstack")
|
pads.stack = Pad(pads.err.height, SCREEN_W - (max_line + 2), math.max(#callstack + 2, 20), max_line + 2, callstack, "(C)allstack")
|
||||||
pads.stack:set_active(true)
|
|
||||||
pads.stack:refresh()
|
|
||||||
end
|
end
|
||||||
local show_src
|
local show_src
|
||||||
show_src = function(filename, line_no)
|
show_src = function(filename, line_no)
|
||||||
@ -340,12 +384,12 @@ run_debugger = function(err_msg)
|
|||||||
if pads.src then
|
if pads.src then
|
||||||
pads.src:erase()
|
pads.src:erase()
|
||||||
end
|
end
|
||||||
pads.src = Pad(pads.err.height, pads.stack.x + pads.stack.width, pads.stack.height, SCREEN_W - pads.stack.x - pads.stack.width - 0, src_lines, "(S)ource Code", {
|
pads.src = Pad(pads.err.height, 0, pads.stack.height, pads.stack.x, src_lines, "(S)ource Code", {
|
||||||
line_colors = setmetatable({
|
line_colors = setmetatable({
|
||||||
[err_line or -1] = COLORS.RED_BG
|
[err_line or -1] = color("yellow on red bold")
|
||||||
}, {
|
}, {
|
||||||
__index = function(self, i)
|
__index = function(self, i)
|
||||||
return (i % 2 == 0) and INVERTED or REGULAR
|
return (i % 2 == 0) and color("on black") or color()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -359,8 +403,7 @@ run_debugger = function(err_msg)
|
|||||||
if pads.values then
|
if pads.values then
|
||||||
pads.values:erase()
|
pads.values:erase()
|
||||||
end
|
end
|
||||||
local callstack_min
|
local callstack_min, _ = callstack_range()
|
||||||
callstack_min, _ = callstack_range()
|
|
||||||
local var_names, values = { }, { }
|
local var_names, values = { }, { }
|
||||||
for loc = 1, 999 do
|
for loc = 1, 999 do
|
||||||
local name, value = debug.getlocal(callstack_min + stack_index - 1, loc)
|
local name, value = debug.getlocal(callstack_min + stack_index - 1, loc)
|
||||||
@ -377,12 +420,13 @@ run_debugger = function(err_msg)
|
|||||||
end
|
end
|
||||||
local var_y = pads.stack.y + pads.stack.height
|
local var_y = pads.stack.y + pads.stack.height
|
||||||
local var_x = 0
|
local var_x = 0
|
||||||
pads.vars = Pad(var_y, var_x, math.min(2 + #var_names, SCREEN_H - pads.err.height - pads.stack.height), AUTO, var_names, "(V)ars")
|
local height = SCREEN_H - (pads.err.height + pads.stack.height)
|
||||||
|
pads.vars = Pad(var_y, var_x, height, AUTO, var_names, "(V)ars")
|
||||||
pads.vars.on_select = function(self, var_index)
|
pads.vars.on_select = function(self, var_index)
|
||||||
local value_x = pads.vars.x + pads.vars.width
|
local value_x = pads.vars.x + pads.vars.width
|
||||||
local value_w = SCREEN_W - (value_x)
|
local value_w = SCREEN_W - (value_x)
|
||||||
if var_index then
|
if var_index then
|
||||||
pads.values = Pad(var_y, value_x, pads.vars.height, value_w, wrap_text(values[var_index], value_w - 2), "Values")
|
pads.values = Pad(var_y, value_x, pads.vars.height, value_w, wrap_text(values[var_index], value_w - 2), "V(a)lue")
|
||||||
else
|
else
|
||||||
pads.values = Pad(var_y, value_x, pads.vars.height, value_w, values, "Values")
|
pads.values = Pad(var_y, value_x, pads.vars.height, value_w, values, "Values")
|
||||||
end
|
end
|
||||||
@ -392,24 +436,26 @@ run_debugger = function(err_msg)
|
|||||||
return pads.vars:select(1)
|
return pads.vars:select(1)
|
||||||
end
|
end
|
||||||
pads.stack.on_select = function(self, stack_index)
|
pads.stack.on_select = function(self, stack_index)
|
||||||
local filename, line_no = pads.stack.lines[stack_index]:match("([^:]*):(%d*).*")
|
local filename, line_no = pads.stack.lines[stack_index]:match("[^|]*| ([^:]*):(%d*).*")
|
||||||
line_no = tonumber(line_no)
|
line_no = tonumber(line_no)
|
||||||
show_src(filename, line_no)
|
show_src(filename, line_no)
|
||||||
return show_vars(stack_index)
|
return show_vars(stack_index)
|
||||||
end
|
end
|
||||||
pads.stack:select(1)
|
pads.stack:select(1)
|
||||||
pads.stack:set_active(true)
|
local selected_pad = nil
|
||||||
local selected_pad = pads.stack
|
|
||||||
local select_pad
|
local select_pad
|
||||||
select_pad = function(pad)
|
select_pad = function(pad)
|
||||||
if selected_pad ~= pad then
|
if selected_pad ~= pad then
|
||||||
selected_pad:set_active(false)
|
if selected_pad then
|
||||||
selected_pad:refresh()
|
selected_pad:set_active(false)
|
||||||
|
selected_pad:refresh()
|
||||||
|
end
|
||||||
selected_pad = pad
|
selected_pad = pad
|
||||||
selected_pad:set_active(true)
|
selected_pad:set_active(true)
|
||||||
return selected_pad:refresh()
|
return selected_pad:refresh()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
select_pad(pads.src)
|
||||||
while true do
|
while true do
|
||||||
C.doupdate()
|
C.doupdate()
|
||||||
local c = stdscr:getch()
|
local c = stdscr:getch()
|
||||||
@ -436,9 +482,12 @@ run_debugger = function(err_msg)
|
|||||||
select_pad(pads.src)
|
select_pad(pads.src)
|
||||||
elseif ('v'):byte() == _exp_0 then
|
elseif ('v'):byte() == _exp_0 then
|
||||||
select_pad(pads.vars)
|
select_pad(pads.vars)
|
||||||
|
elseif ('a'):byte() == _exp_0 then
|
||||||
|
select_pad(pads.values)
|
||||||
elseif ('o'):byte() == _exp_0 then
|
elseif ('o'):byte() == _exp_0 then
|
||||||
local file = stack_locations[pads.stack.selected]
|
local file = stack_locations[pads.stack.selected]
|
||||||
local filename, line_no = file:match("([^:]*):(.*)")
|
local filename, line_no = file:match("([^:]*):(.*)")
|
||||||
|
line_no = tostring(pads.src.selected)
|
||||||
C.endwin()
|
C.endwin()
|
||||||
os.execute((os.getenv("EDITOR") or "nano") .. " +" .. line_no .. " " .. filename)
|
os.execute((os.getenv("EDITOR") or "nano") .. " +" .. line_no .. " " .. filename)
|
||||||
stdscr = C.initscr()
|
stdscr = C.initscr()
|
||||||
@ -464,7 +513,6 @@ end
|
|||||||
guard = function(fn, ...)
|
guard = function(fn, ...)
|
||||||
local err_hand
|
local err_hand
|
||||||
err_hand = function(err)
|
err_hand = function(err)
|
||||||
log:write(err .. "\n\n\n")
|
|
||||||
C.endwin()
|
C.endwin()
|
||||||
print("Caught an error:")
|
print("Caught an error:")
|
||||||
print(debug.traceback(err, 2))
|
print(debug.traceback(err, 2))
|
||||||
@ -478,7 +526,6 @@ local breakpoint
|
|||||||
breakpoint = function()
|
breakpoint = function()
|
||||||
local err_hand
|
local err_hand
|
||||||
err_hand = function(err)
|
err_hand = function(err)
|
||||||
log:write(err .. "\n\n\n")
|
|
||||||
C.endwin()
|
C.endwin()
|
||||||
print("Caught an error:")
|
print("Caught an error:")
|
||||||
print(debug.traceback(err, 2))
|
print(debug.traceback(err, 2))
|
||||||
|
111
cursed.moon
111
cursed.moon
@ -1,6 +1,6 @@
|
|||||||
C = require "curses"
|
C = require "curses"
|
||||||
|
re = require 're'
|
||||||
repr = require 'repr'
|
repr = require 'repr'
|
||||||
COLORS = {}
|
|
||||||
local run_debugger, guard, stdscr
|
local run_debugger, guard, stdscr
|
||||||
AUTO = {}
|
AUTO = {}
|
||||||
log = io.open("output.log", "w")
|
log = io.open("output.log", "w")
|
||||||
@ -154,7 +154,6 @@ line_tables = setmetatable({}, {__index:(filename)=>
|
|||||||
})
|
})
|
||||||
|
|
||||||
run_debugger = (err_msg)->
|
run_debugger = (err_msg)->
|
||||||
log\write(err_msg.."\n\n")
|
|
||||||
export stdscr, SCREEN_H, SCREEN_W
|
export stdscr, SCREEN_H, SCREEN_W
|
||||||
stdscr = C.initscr!
|
stdscr = C.initscr!
|
||||||
SCREEN_H, SCREEN_W = stdscr\getmaxyx!
|
SCREEN_H, SCREEN_W = stdscr\getmaxyx!
|
||||||
@ -166,37 +165,59 @@ run_debugger = (err_msg)->
|
|||||||
C.start_color!
|
C.start_color!
|
||||||
C.use_default_colors!
|
C.use_default_colors!
|
||||||
|
|
||||||
_, COLORS.REGULAR = C.init_pair(1, C.COLOR_WHITE, -1), C.color_pair(1)
|
color_index = 0
|
||||||
_, COLORS.INVERTED = C.init_pair(2, C.COLOR_WHITE, C.COLOR_BLACK), C.color_pair(2)
|
existing = {}
|
||||||
_, COLORS.YELLOW_BG = C.init_pair(3, C.COLOR_BLACK, C.COLOR_YELLOW), C.color_pair(3)
|
make_color = (fg=-1, bg=-1)->
|
||||||
_, COLORS.RED = C.init_pair(4, C.COLOR_RED, -1), C.color_pair(4)
|
key = "#{fg},#{bg}"
|
||||||
_, COLORS.BLUE = C.init_pair(5, C.COLOR_BLUE, -1), C.color_pair(5) | C.A_BOLD
|
unless existing[key]
|
||||||
_, COLORS.WHITE = C.init_pair(6, C.COLOR_WHITE, -1), C.color_pair(6)
|
color_index += 1
|
||||||
_, COLORS.WHITE_BG = C.init_pair(7, C.COLOR_BLACK, C.COLOR_WHITE), C.color_pair(7)
|
C.init_pair(color_index, fg, bg)
|
||||||
_, COLORS.BROWN = C.init_pair(8, C.COLOR_BLACK, -1), C.color_pair(8) | C.A_BOLD
|
existing[key] = C.color_pair(color_index)
|
||||||
_, COLORS.RED_BG = C.init_pair(9, C.COLOR_YELLOW, C.COLOR_RED), C.color_pair(9) | C.A_BOLD | C.A_DIM
|
return existing[key]
|
||||||
_, COLORS.GREEN = C.init_pair(10, C.COLOR_GREEN, -1), C.color_pair(10)
|
color_lang = re.compile[[
|
||||||
|
x <- {|
|
||||||
|
{:attrs: {| {attr} (" " {attr})* |} :}
|
||||||
|
/ ((({:fg: color :} (" on " {:bg: color :})?) / {:bg: "on " color :}) {:attrs: {| (" " {attr})* |} :})
|
||||||
|
|}
|
||||||
|
attr <- "blink" / "bold" / "dim" / "invis" / "normal" / "protect" / "reverse" / "standout" / "underline"
|
||||||
|
color <- "black" / "blue" / "cyan" / "green" / "magenta" / "red" / "white" / "yellow" / "default"
|
||||||
|
]]
|
||||||
|
C.COLOR_DEFAULT = -1
|
||||||
|
color = (s="default")->
|
||||||
|
t = assert(color_lang\match(s), "Invalid color: #{s}")
|
||||||
|
if t.fg then t.fg = C["COLOR_"..t.fg\upper!]
|
||||||
|
if t.bg then t.bg = C["COLOR_"..t.bg\upper!]
|
||||||
|
c = make_color(t.fg, t.bg)
|
||||||
|
for a in *t.attrs
|
||||||
|
c |= C["A_"..a\upper!]
|
||||||
|
return c
|
||||||
|
|
||||||
export default_colors
|
export default_colors
|
||||||
default_colors = {
|
default_colors = {
|
||||||
active_frame: COLORS.BLUE,
|
active_frame: color"blue",
|
||||||
inactive_frame: COLORS.BROWN,
|
inactive_frame: color"bold black",
|
||||||
line_colors: setmetatable({}, __index:(i)=> (i % 2 == 0 and COLORS.INVERTED or COLORS.REGULAR))
|
line_colors: setmetatable({}, __index:(i)=> (i % 2 == 0 and color("on black") or color()))
|
||||||
highlight: COLORS.WHITE_BG,
|
highlight: color"black on white",
|
||||||
active: COLORS.YELLOW_BG,
|
active: color"black on yellow",
|
||||||
}
|
}
|
||||||
|
|
||||||
do -- Fullscreen flash
|
do -- Fullscreen flash
|
||||||
stdscr\wbkgd(COLORS.RED_BG)
|
stdscr\wbkgd(color"yellow on red bold")
|
||||||
stdscr\clear!
|
stdscr\clear!
|
||||||
stdscr\refresh!
|
stdscr\refresh!
|
||||||
lines = wrap_text("ERROR!\n \n "..err_msg.."\n \npress any key...", math.floor(SCREEN_W/2))
|
lines = wrap_text("ERROR!\n \n "..err_msg.."\n \npress any key...", math.floor(SCREEN_W/2))
|
||||||
|
max_line = 0
|
||||||
|
for line in *lines do max_line = math.max(max_line, #line)
|
||||||
for i, line in ipairs(lines)
|
for i, line in ipairs(lines)
|
||||||
stdscr\mvaddstr(math.floor(SCREEN_H/2 - #lines/2)+i, math.floor((SCREEN_W-#line)/2), line)
|
if i == 1 or i == #lines
|
||||||
|
stdscr\mvaddstr(math.floor(SCREEN_H/2 - #lines/2)+i, math.floor((SCREEN_W-#line)/2), line)
|
||||||
|
else
|
||||||
|
stdscr\mvaddstr(math.floor(SCREEN_H/2 - #lines/2)+i, math.floor((SCREEN_W-max_line)/2), line)
|
||||||
stdscr\refresh!
|
stdscr\refresh!
|
||||||
C.doupdate!
|
C.doupdate!
|
||||||
stdscr\getch!
|
stdscr\getch!
|
||||||
|
|
||||||
stdscr\wbkgd(COLORS.REGULAR)
|
stdscr\wbkgd(color!)
|
||||||
stdscr\clear!
|
stdscr\clear!
|
||||||
stdscr\refresh!
|
stdscr\refresh!
|
||||||
|
|
||||||
@ -205,16 +226,16 @@ run_debugger = (err_msg)->
|
|||||||
do -- Err pad
|
do -- Err pad
|
||||||
err_msg_lines = wrap_text(err_msg, SCREEN_W - 4)
|
err_msg_lines = wrap_text(err_msg, SCREEN_W - 4)
|
||||||
for i,line in ipairs(err_msg_lines)
|
for i,line in ipairs(err_msg_lines)
|
||||||
err_msg_lines[i] = (" ")\rep(math.floor((SCREEN_W-2-#line)/2))..line
|
err_msg_lines[i] = (" ")\rep(2)..line
|
||||||
pads.err = Pad(0,0,AUTO,SCREEN_W, err_msg_lines, "Error Message", {
|
pads.err = Pad(0,0,AUTO,SCREEN_W, err_msg_lines, "Error Message", {
|
||||||
line_colors: setmetatable({}, __index:->COLORS.RED | C.A_BOLD)
|
line_colors: setmetatable({}, __index:-> color"red bold")
|
||||||
inactive_frame: COLORS.RED | C.A_DIM
|
inactive_frame: color"red dim"
|
||||||
})
|
})
|
||||||
|
|
||||||
stack_locations = {}
|
stack_locations = {}
|
||||||
do -- Stack pad
|
do -- Stack pad
|
||||||
stack_names = {}
|
stack_names = {}
|
||||||
max_filename = 0
|
max_filename, max_fn_name = 0, 0
|
||||||
stack_min, stack_max = callstack_range!
|
stack_min, stack_max = callstack_range!
|
||||||
for i=stack_min,stack_max
|
for i=stack_min,stack_max
|
||||||
info = debug.getinfo(i)
|
info = debug.getinfo(i)
|
||||||
@ -233,13 +254,16 @@ run_debugger = (err_msg)->
|
|||||||
info.short_src..":"..info.currentline
|
info.short_src..":"..info.currentline
|
||||||
table.insert(stack_locations, line)
|
table.insert(stack_locations, line)
|
||||||
max_filename = math.max(max_filename, #line)
|
max_filename = math.max(max_filename, #line)
|
||||||
|
max_fn_name = math.max(max_fn_name, #stack_names[#stack_names])
|
||||||
callstack = {}
|
callstack = {}
|
||||||
|
max_line = 0
|
||||||
for i=1,#stack_names do
|
for i=1,#stack_names do
|
||||||
callstack[i] = stack_locations[i]..(" ")\rep(max_filename-#stack_locations[i]).." | "..stack_names[i].." "
|
--callstack[i] = stack_locations[i]..(" ")\rep(max_filename-#stack_locations[i]).." | "..stack_names[i].." "
|
||||||
|
callstack[i] = ("%-"..max_fn_name.."s | %s")\format(stack_names[i], stack_locations[i])
|
||||||
|
--callstack[i] = stack_locations[i]..(" ")\rep(max_filename-#stack_locations[i]).." | "..stack_names[i].." "
|
||||||
|
max_line = math.max(max_line, #callstack[i])
|
||||||
|
|
||||||
pads.stack = Pad(pads.err.height,0,math.max(#callstack+2, 20),AUTO, callstack, "(C)allstack")
|
pads.stack = Pad(pads.err.height,SCREEN_W-(max_line+2),math.max(#callstack+2, 20),max_line+2, callstack, "(C)allstack")
|
||||||
pads.stack\set_active(true)
|
|
||||||
pads.stack\refresh!
|
|
||||||
|
|
||||||
show_src = (filename, line_no)->
|
show_src = (filename, line_no)->
|
||||||
file = file_cache[filename]
|
file = file_cache[filename]
|
||||||
@ -263,9 +287,10 @@ run_debugger = (err_msg)->
|
|||||||
|
|
||||||
if pads.src
|
if pads.src
|
||||||
pads.src\erase!
|
pads.src\erase!
|
||||||
pads.src = Pad(pads.err.height,pads.stack.x+pads.stack.width,
|
pads.src = Pad(pads.err.height,0,
|
||||||
pads.stack.height,SCREEN_W-pads.stack.x-pads.stack.width-0, src_lines, "(S)ource Code", {
|
pads.stack.height,pads.stack.x, src_lines, "(S)ource Code", {
|
||||||
line_colors:setmetatable({[err_line or -1]:COLORS.RED_BG}, {__index:(i)=> (i % 2 == 0) and INVERTED or REGULAR})
|
line_colors:setmetatable({[err_line or -1]: color"yellow on red bold"},
|
||||||
|
{__index:(i)=> (i % 2 == 0) and color"on black" or color!})
|
||||||
})
|
})
|
||||||
pads.src\select(err_line)
|
pads.src\select(err_line)
|
||||||
|
|
||||||
@ -289,14 +314,16 @@ run_debugger = (err_msg)->
|
|||||||
|
|
||||||
var_y = pads.stack.y + pads.stack.height
|
var_y = pads.stack.y + pads.stack.height
|
||||||
var_x = 0
|
var_x = 0
|
||||||
pads.vars = Pad(var_y,var_x,math.min(2+#var_names, SCREEN_H-pads.err.height-pads.stack.height),AUTO,var_names,"(V)ars")
|
--height = math.min(2+#var_names, SCREEN_H-pads.err.height-pads.stack.height)
|
||||||
|
height = SCREEN_H-(pads.err.height+pads.stack.height)
|
||||||
|
pads.vars = Pad(var_y,var_x,height,AUTO,var_names,"(V)ars")
|
||||||
|
|
||||||
pads.vars.on_select = (var_index)=>
|
pads.vars.on_select = (var_index)=>
|
||||||
value_x = pads.vars.x+pads.vars.width
|
value_x = pads.vars.x+pads.vars.width
|
||||||
value_w = SCREEN_W-(value_x)
|
value_w = SCREEN_W-(value_x)
|
||||||
-- Show single value:
|
-- Show single value:
|
||||||
if var_index
|
if var_index
|
||||||
pads.values = Pad(var_y,value_x,pads.vars.height,value_w,wrap_text(values[var_index], value_w-2), "Values")
|
pads.values = Pad(var_y,value_x,pads.vars.height,value_w,wrap_text(values[var_index], value_w-2), "V(a)lue")
|
||||||
else
|
else
|
||||||
pads.values = Pad(var_y,value_x,pads.vars.height,value_w,values, "Values")
|
pads.values = Pad(var_y,value_x,pads.vars.height,value_w,values, "Values")
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
@ -305,22 +332,24 @@ run_debugger = (err_msg)->
|
|||||||
pads.vars\select(1)
|
pads.vars\select(1)
|
||||||
|
|
||||||
pads.stack.on_select = (stack_index)=>
|
pads.stack.on_select = (stack_index)=>
|
||||||
filename, line_no = pads.stack.lines[stack_index]\match("([^:]*):(%d*).*")
|
filename, line_no = pads.stack.lines[stack_index]\match("[^|]*| ([^:]*):(%d*).*")
|
||||||
line_no = tonumber(line_no)
|
line_no = tonumber(line_no)
|
||||||
show_src(filename, line_no)
|
show_src(filename, line_no)
|
||||||
show_vars(stack_index)
|
show_vars(stack_index)
|
||||||
|
|
||||||
pads.stack\select(1)
|
pads.stack\select(1)
|
||||||
pads.stack\set_active(true)
|
|
||||||
selected_pad = pads.stack
|
|
||||||
|
|
||||||
|
selected_pad = nil
|
||||||
select_pad = (pad)->
|
select_pad = (pad)->
|
||||||
if selected_pad != pad
|
if selected_pad != pad
|
||||||
selected_pad\set_active(false)
|
if selected_pad
|
||||||
selected_pad\refresh!
|
selected_pad\set_active(false)
|
||||||
|
selected_pad\refresh!
|
||||||
selected_pad = pad
|
selected_pad = pad
|
||||||
selected_pad\set_active(true)
|
selected_pad\set_active(true)
|
||||||
selected_pad\refresh!
|
selected_pad\refresh!
|
||||||
|
|
||||||
|
select_pad(pads.src)
|
||||||
|
|
||||||
while true
|
while true
|
||||||
C.doupdate!
|
C.doupdate!
|
||||||
@ -355,9 +384,13 @@ run_debugger = (err_msg)->
|
|||||||
when ('v')\byte!
|
when ('v')\byte!
|
||||||
select_pad(pads.vars) -- (V)ars
|
select_pad(pads.vars) -- (V)ars
|
||||||
|
|
||||||
|
when ('a')\byte!
|
||||||
|
select_pad(pads.values) -- V(a)lue
|
||||||
|
|
||||||
when ('o')\byte!
|
when ('o')\byte!
|
||||||
file = stack_locations[pads.stack.selected]
|
file = stack_locations[pads.stack.selected]
|
||||||
filename,line_no = file\match("([^:]*):(.*)")
|
filename,line_no = file\match("([^:]*):(.*)")
|
||||||
|
line_no = tostring(pads.src.selected)
|
||||||
-- Launch system editor and then redraw everything
|
-- Launch system editor and then redraw everything
|
||||||
C.endwin!
|
C.endwin!
|
||||||
os.execute((os.getenv("EDITOR") or "nano").." +"..line_no.." "..filename)
|
os.execute((os.getenv("EDITOR") or "nano").." +"..line_no.." "..filename)
|
||||||
@ -382,7 +415,6 @@ run_debugger = (err_msg)->
|
|||||||
|
|
||||||
guard = (fn, ...)->
|
guard = (fn, ...)->
|
||||||
err_hand = (err)->
|
err_hand = (err)->
|
||||||
log\write(err.."\n\n\n")
|
|
||||||
C.endwin!
|
C.endwin!
|
||||||
print "Caught an error:"
|
print "Caught an error:"
|
||||||
print(debug.traceback(err, 2))
|
print(debug.traceback(err, 2))
|
||||||
@ -392,7 +424,6 @@ guard = (fn, ...)->
|
|||||||
|
|
||||||
breakpoint = ->
|
breakpoint = ->
|
||||||
err_hand = (err)->
|
err_hand = (err)->
|
||||||
log\write(err.."\n\n\n")
|
|
||||||
C.endwin!
|
C.endwin!
|
||||||
print "Caught an error:"
|
print "Caught an error:"
|
||||||
print(debug.traceback(err, 2))
|
print(debug.traceback(err, 2))
|
||||||
|
Loading…
Reference in New Issue
Block a user