diff --git a/ldt.lua b/ldt.lua index aac7b42..57de138 100644 --- a/ldt.lua +++ b/ldt.lua @@ -5,14 +5,11 @@ local AUTO = { } local PARENT = { } local _error = error local _assert = assert -local log = io.open('output.log', 'w') local toggle toggle = function(field, bit) if field & bit ~= 0 then - log:write(("%x ~ %x -> %x\n"):format(field, bit, field & ~bit)) return field & ~bit else - log:write(("%x ~ %x -> %x\n"):format(field, bit, field | bit)) return field | bit end end @@ -487,11 +484,18 @@ colored_repr = function(x, width, depth) return ret elseif x_type == 'string' then local ret = { - (x:match('^[^\n]*')), + (x:match('^[^\t\r\v\b\a\n]*')), TYPE_COLORS.string } - for line in x:gmatch('\n([^\n]*)') do - ret[#ret + 1] = '\\n' + for escape, line in x:gmatch('([\t\r\v\b\a\n])([^\t\r\v\b\a\n]*)') do + ret[#ret + 1] = '\\' .. ({ + ['\t'] = 't', + ['\r'] = 'r', + ['\v'] = 'v', + ['\b'] = 'b', + ['\a'] = 'a', + ['\n'] = 'n' + })[escape] ret[#ret + 1] = Color('white on black') ret[#ret + 1] = line ret[#ret + 1] = TYPE_COLORS.string @@ -1219,18 +1223,48 @@ ldb = { else local ret = run_fn() if ret ~= nil or print_nil then - output = output .. '= ' - local bits = colored_repr(ret, SCREEN_W - 2, 4) - for i = 1, #bits - 1, 2 do - output = output .. bits[i] + local value_bits = { + '= ', + Color('yellow'), + unpack(colored_repr(ret, SCREEN_W - 2, 4)) + } + local numlines = 1 + for i = 1, #value_bits - 1, 2 do + for nl in value_bits[i]:gmatch('\n') do + numlines = numlines + 1 + end end - output = output .. '\n' + for nl in output:gmatch('\n') do + numlines = numlines + 1 + end + local y, x = SCREEN_H - numlines, 0 + if output ~= "" then + stdscr:mvaddstr(SCREEN_H - numlines, 0, output) + for nl in output:gmatch('\n') do + y = y + 1 + end + end + for i = 1, #value_bits - 1, 2 do + stdscr:attrset(value_bits[i + 1]) + local first_line = value_bits[i]:match('^[^\n]*') + stdscr:mvaddstr(y, x, first_line) + x = x + #first_line + for line in value_bits[i]:gmatch('\n([^\n]*)') do + stdscr:mvaddstr(y, x, (' '):rep(SCREEN_W - x)) + y = y + 1 + x = 0 + stdscr:mvaddstr(y, x, line) + end + end + stdscr:attrset(Color()) + stdscr:mvaddstr(y, x, (' '):rep(SCREEN_W - x)) + else + local numlines = 0 + for nl in output:gmatch('\n') do + numlines = numlines + 1 + end + stdscr:mvaddstr(SCREEN_H - numlines, 0, output) end - local numlines = 0 - for nl in output:gmatch('\n') do - numlines = numlines + 1 - end - stdscr:mvaddstr(SCREEN_H - numlines, 0, output) end elseif ('o'):byte() == _exp_0 then local file = stack_locations[pads.stack.selected] diff --git a/ldt.moon b/ldt.moon index 048ae88..37fe345 100644 --- a/ldt.moon +++ b/ldt.moon @@ -7,13 +7,10 @@ PARENT = {} -- Singleton _error = error _assert = assert -log = io.open('output.log','w') toggle = (field, bit)-> if field & bit != 0 - log\write(("%x ~ %x -> %x\n")\format(field, bit, field & ~bit)) field & ~bit else - log\write(("%x ~ %x -> %x\n")\format(field, bit, field | bit)) field | bit -- Return the callstack index of the code that actually caused an error and the max index @@ -310,9 +307,9 @@ colored_repr = (x, width, depth=2)-> ret[#ret+1] = TYPE_COLORS.table return ret elseif x_type == 'string' - ret = {(x\match('^[^\n]*')), TYPE_COLORS.string} - for line in x\gmatch('\n([^\n]*)') - ret[#ret+1] = '\\n' + ret = {(x\match('^[^\t\r\v\b\a\n]*')), TYPE_COLORS.string} + for escape, line in x\gmatch('([\t\r\v\b\a\n])([^\t\r\v\b\a\n]*)') + ret[#ret+1] = '\\'..({['\t']:'t',['\r']:'r',['\v']:'v',['\b']:'b',['\a']:'a',['\n']:'n'})[escape] ret[#ret+1] = Color('white on black') ret[#ret+1] = line ret[#ret+1] = TYPE_COLORS.string @@ -834,14 +831,31 @@ ldb = { else ret = run_fn! if ret != nil or print_nil - output ..= '= ' - bits = colored_repr(ret, SCREEN_W-2, 4) - for i=1,#bits-1,2 - output ..= bits[i] - output ..= '\n' - numlines = 0 - for nl in output\gmatch('\n') do numlines += 1 - stdscr\mvaddstr(SCREEN_H-numlines, 0, output) + value_bits = {'= ', Color('yellow'), unpack(colored_repr(ret, SCREEN_W-2, 4))} + numlines = 1 + for i=1,#value_bits-1,2 + for nl in value_bits[i]\gmatch('\n') do numlines += 1 + for nl in output\gmatch('\n') do numlines += 1 + y, x = SCREEN_H-numlines, 0 + if output != "" + stdscr\mvaddstr(SCREEN_H-numlines, 0, output) + for nl in output\gmatch('\n') do y += 1 + for i=1,#value_bits-1,2 + stdscr\attrset(value_bits[i+1]) + first_line = value_bits[i]\match('^[^\n]*') + stdscr\mvaddstr(y, x, first_line) + x += #first_line + for line in value_bits[i]\gmatch('\n([^\n]*)') + stdscr\mvaddstr(y,x,(' ')\rep(SCREEN_W-x)) + y += 1 + x = 0 + stdscr\mvaddstr(y, x, line) + stdscr\attrset(Color!) + stdscr\mvaddstr(y,x,(' ')\rep(SCREEN_W-x)) + else + numlines = 0 + for nl in output\gmatch('\n') do numlines += 1 + stdscr\mvaddstr(SCREEN_H-numlines, 0, output) when ('o')\byte!