From 09f6ab22efcabb409754efc1c4c26c52a761fbbc Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 13 Mar 2018 15:51:28 -0700 Subject: [PATCH] Fixed bug. --- cursed.lua | 18 +++++++++--------- cursed.moon | 16 +++++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cursed.lua b/cursed.lua index 1965fb7..39afefa 100644 --- a/cursed.lua +++ b/cursed.lua @@ -56,7 +56,7 @@ do local _base_0 = { select = function(self, i) if i == self.selected or #self.lines == 0 then - return + return self.selected end if i ~= nil then i = math.max(1, math.min(#self.lines, i)) @@ -124,7 +124,7 @@ do self.offset = 0 self.selected = nil self._height = #self.lines + 2 - self._width = 2 + self._width = self.width == AUTO and 2 or self.width local _list_0 = self.lines for _index_0 = 1, #_list_0 do local x = _list_0[_index_0] @@ -185,6 +185,9 @@ local file_cache = setmetatable({ }, { local line_tables = setmetatable({ }, { __index = function(self, filename) local file = file_cache[filename] + if not file then + return nil + end local line_table ok, line_table = to_lua(file) if ok then @@ -195,9 +198,6 @@ local line_tables = setmetatable({ }, { }) local err_pad, stack_pad, var_names, var_values = nil, nil, nil, nil main_loop = function(err_msg, stack_index, var_index, value_index) - if stack_index == nil then - stack_index = 1 - end local stack_names = { } local stack_locations = { } local max_filename = 0 @@ -248,9 +248,9 @@ main_loop = function(err_msg, stack_index, var_index, value_index) }), RED) end if not stack_pad then - stack_pad = Pad(err_pad.height, 0, AUTO, AUTO, callstack, nil, BLUE) - stack_index = stack_pad:select(stack_index) + stack_pad = Pad(err_pad.height, 0, AUTO, SCREEN_W, callstack, nil, BLUE) end + stack_index = stack_pad:select(stack_index) if var_names then var_names:erase() end @@ -279,7 +279,7 @@ main_loop = function(err_msg, stack_index, var_index, value_index) var_index = var_names:select(var_index) end local value_x = var_names.x + var_names.width - local value_w = SCREEN_W - (value_x + 1) + local value_w = SCREEN_W - (value_x) if value_index then var_values = Pad(var_y, value_x, AUTO, value_w, wrap_text(_var_values[var_index], value_w - 2), nil, BLUE) value_index = var_values:select(value_index) @@ -369,7 +369,7 @@ run_debugger = function(err_msg) _, BLUE = C.init_pair(5, C.COLOR_BLUE, -1), C.color_pair(5) | C.A_BOLD stdscr:clear() stdscr:refresh() - return main_loop(err_msg) + return main_loop(err_msg, 1) end guard = function(fn, ...) local err_hand diff --git a/cursed.moon b/cursed.moon index c6cbe8f..18b9de2 100644 --- a/cursed.moon +++ b/cursed.moon @@ -42,7 +42,7 @@ class Pad @selected = nil @_height = #@lines + 2 - @_width = 2 + @_width = @width == AUTO and 2 or @width for x in *@lines do @_width = math.max(@_width, #x+2) if @height == AUTO @@ -66,7 +66,7 @@ class Pad @refresh! select: (i)=> - if i == @selected or #@lines == 0 then return + if i == @selected or #@lines == 0 then return @selected if i != nil i = math.max(1, math.min(#@lines, i)) if @selected @@ -128,6 +128,8 @@ file_cache = setmetatable({}, {__index:(filename)=> }) line_tables = setmetatable({}, {__index:(filename)=> file = file_cache[filename] + if not file + return nil ok, line_table = to_lua(file) if ok @[filename] = line_table @@ -136,7 +138,7 @@ line_tables = setmetatable({}, {__index:(filename)=> err_pad, stack_pad, var_names, var_values = nil, nil, nil, nil -main_loop = (err_msg, stack_index=1, var_index, value_index)-> +main_loop = (err_msg, stack_index, var_index, value_index)-> export err_pad, stack_pad, var_names, var_values stack_names = {} stack_locations = {} @@ -168,8 +170,8 @@ main_loop = (err_msg, stack_index=1, var_index, value_index)-> err_pad = Pad(0,0,AUTO,SCREEN_W, err_msg_lines,setmetatable({}, __index:->RED), RED) if not stack_pad - stack_pad = Pad(err_pad.height,0,AUTO,AUTO, callstack, nil, BLUE) - stack_index = stack_pad\select(stack_index) + stack_pad = Pad(err_pad.height,0,AUTO,SCREEN_W, callstack, nil, BLUE) + stack_index = stack_pad\select(stack_index) if var_names var_names\erase! @@ -196,7 +198,7 @@ main_loop = (err_msg, stack_index=1, var_index, value_index)-> var_index = var_names\select(var_index) value_x = var_names.x+var_names.width - value_w = SCREEN_W-(value_x+1) + value_w = SCREEN_W-(value_x) if value_index var_values = Pad(var_y,value_x,AUTO,value_w,wrap_text(_var_values[var_index], value_w-2), nil, BLUE) value_index = var_values\select(value_index) @@ -291,7 +293,7 @@ run_debugger = (err_msg)-> stdscr\clear! stdscr\refresh! - return main_loop(err_msg) + return main_loop(err_msg, 1) guard = (fn, ...)->