diff --git a/pretty.lua b/pretty.lua index 30e6ac4..e42d52a 100644 --- a/pretty.lua +++ b/pretty.lua @@ -237,6 +237,14 @@ local function get_full_function_str (str, start_line, end_line) return matched_function end +local function width_of_strings_in_l (l, start_i, end_i) + local width = 0 + for i = start_i or 1, (end_i or #l) do + width = width + #l[i] + end + return width +end + -------------------------------------------------------------------------------- -- Identifyer stuff @@ -333,10 +341,11 @@ local function format_key_and_value_string_map (l, key, value, options, depth) end local function format_key_and_value_arbitr_map (l, key, value, options, depth) + local index_before_key = #l+1 l[#l+1] = '[' format_value(key, options, 'max', l) l[#l+1] = ']' - l[#l+1] = #l[#l-1] + 2 + l[#l+1] = width_of_strings_in_l(l, index_before_key) l[#l+1] = ' = ' format_value(value, options, depth, l) end @@ -606,7 +615,7 @@ function format_value (value, options, depth, l) if format_func then format_func(value, options, depth, l) else - error(ERROR_UNKNOWN_TYPE:format(type(value), tostring(value))) + error(ERROR_UNKNOWN_TYPE:format(type(value), tostring(value)), 2) end end