From 6e2f8f7b34b36d511c6a33fad6b9497c72ac013f Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Fri, 18 Nov 2016 18:44:00 +0100 Subject: [PATCH] adding context-clear-screen feature with config value (#134) If enabled, this clears the whole screen before printing the context. This way stepping through the program always starts from the top-left corner and remains static in its poisition. Default value: off --- pwndbg/commands/context.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pwndbg/commands/context.py b/pwndbg/commands/context.py index d45d6b071..126c007ba 100644 --- a/pwndbg/commands/context.py +++ b/pwndbg/commands/context.py @@ -29,6 +29,16 @@ import pwndbg.ui import pwndbg.vmmap +def clear_screen(): + """ + Clear the screen by moving the cursor to top-left corner and + clear the content + """ + sys.stdout.write('\x1b[H\x1b[J') + +config_clear_screen = pwndbg.config.Parameter('context-clear-screen', False, 'whether to clear the screen before printing the context') + + # @pwndbg.events.stop @pwndbg.commands.Command @pwndbg.commands.OnlyWhenRunning @@ -54,6 +64,9 @@ def context(*args): if 'b' in args: result.extend(context_backtrace()) result.extend(context_signal()) + if config_clear_screen: + clear_screen() + for line in result: sys.stdout.write(line + '\n') sys.stdout.flush()