diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | debug.c | 25 |
2 files changed, 29 insertions, 4 deletions
@@ -1,5 +1,13 @@ 2012-02-12 Kaz Kylheku <kaz@kylheku.com> + * debug.c (breakpoints, last_command): linkage changed to static. + (cols): New static variable. + (debug): Print context intelligently, fitting into the width of + the screen. + (debug_init): Try to get terminal width, from the COLUMNS variable. + +2012-02-12 Kaz Kylheku <kaz@kylheku.com> + * lib.c (lazy_flatten): Bugfix: function was assuming that the input is a list, and not handling the case atom -> (atom) like its non-lazy counterpart. @@ -19,8 +19,9 @@ int debug_depth; val debug_block_s; static int step_mode; static int next_depth = -1; -val breakpoints; -val last_command; +static val breakpoints; +static val last_command; +static int cols = 80; static void help(val stream) { @@ -81,8 +82,17 @@ val debug(val form, val bindings, val data, val line, val pos, val base) if (print_data) { if (data && pos) { - val prefix = sub_str(data, zero, pos); - val suffix = sub_str(data, pos, nil); + val half = num((cols - 8) / 2); + val full = num((cols - 8)); + val prefix, suffix; + + if (lt(pos, half)) { + prefix = sub_str(data, zero, pos); + suffix = sub_str(data, pos, full); + } else { + prefix = sub_str(data, minus(pos, half), pos); + suffix = sub_str(data, pos, plus(pos, half)); + } format(std_output, lit("data (~s:~s):\n~s . ~s\n"), line, plus(pos, base), prefix, suffix, nao); @@ -169,4 +179,11 @@ void debug_init(void) step_mode = 1; protect(&breakpoints, &last_command, (val *) 0); debug_block_s = intern(lit("debug-block"), system_package); + { + char *columns = getenv("COLUMNS"); + if (columns) + cols = atoi(columns); + if (cols < 40) + cols = 40; + } } |