From fdb885e3ac75f901e3d51a0bf5bcef9a8969e847 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 12 Feb 2012 19:06:50 -0800 Subject: * 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. --- ChangeLog | 8 ++++++++ debug.c | 25 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39f38b2b..fe4be800 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-02-12 Kaz Kylheku + + * 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 * lib.c (lazy_flatten): Bugfix: function was assuming that diff --git a/debug.c b/debug.c index 1e9edb2a..55e7fb4e 100644 --- a/debug.c +++ b/debug.c @@ -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; + } } -- cgit v1.2.3