about summary refs log tree commit diff stats
path: root/003trace.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-06-16 16:56:29 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-06-16 16:56:29 -0700
commit1441e507b63f2c48c201c76bc991f7818ab1c987 (patch)
treed72be726d362cb8c4168dc0bd99b20717cfd191c /003trace.cc
parent960e75d0c69287c13202c9843c968a01ecf54f15 (diff)
downloadmu-1441e507b63f2c48c201c76bc991f7818ab1c987.tar.gz
3917
Redo commit 3905 to always shutdown cleanly on any error raised.
Diffstat (limited to '003trace.cc')
-rw-r--r--003trace.cc14
1 files changed, 13 insertions, 1 deletions
diff --git a/003trace.cc b/003trace.cc
index eb4513d5..390a2b5e 100644
--- a/003trace.cc
+++ b/003trace.cc
@@ -165,11 +165,23 @@ int Trace_errors = 0;  // used only when Trace_stream is NULL
 #define DUMP(label)  if (Trace_stream) cerr << Trace_stream->readable_contents(label);
 
 // Errors are a special layer.
-#define raise  (!Trace_stream ? (++Trace_errors,cerr) /*do print*/ : Trace_stream->stream(Error_depth, "error"))
+#define raise  (!Trace_stream ? (scroll_to_bottom_and_close_console(),++Trace_errors,cerr) /*do print*/ : Trace_stream->stream(Error_depth, "error"))
 // If we aren't yet sure how to deal with some corner case, use assert_for_now
 // to indicate that it isn't an inviolable invariant.
 #define assert_for_now assert
 
+//: Automatically close the console in some situations.
+:(before "End One-time Setup")
+atexit(scroll_to_bottom_and_close_console);
+:(code)
+void scroll_to_bottom_and_close_console() {
+  if (!tb_is_active()) return;
+  // leave the screen in a relatively clean state
+  tb_set_cursor(tb_width()-1, tb_height()-1);
+  cout << "\r\n";
+  tb_shutdown();
+}
+
 // Inside tests, fail any tests that displayed (unexpected) errors.
 // Expected errors in tests should always be hidden and silently checked for.
 :(before "End Test Teardown")