Skip to content

Commit

Permalink
Simplified clear_screen command (#1148)
Browse files Browse the repository at this point in the history
## Description

Simplify `clear_screen` API  by sending directly the clear screen sequence to `sys.stdout` by default.
Fixes #1147
  • Loading branch information
hugsy authored Nov 10, 2024
1 parent 5376d78 commit 4dccd78
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -3898,19 +3898,12 @@ def get_memory_alignment(in_bits: bool = False) -> int:

def clear_screen(tty: str = "") -> None:
"""Clear the screen."""
global gef
if not tty:
gdb.execute("shell clear -x")
return
clean_sequence = "\x1b[H\x1b[J"
if tty:
pathlib.Path(tty).write_text(clean_sequence)
else:
sys.stdout.write(clean_sequence)

# Since the tty can be closed at any time, a PermissionError exception can
# occur when `clear_screen` is called. We handle this scenario properly
try:
with open(tty, "wt") as f:
f.write("\x1b[H\x1b[J")
except PermissionError:
gef.ui.redirect_fd = None
gef.config["context.redirect"] = ""
return


Expand Down

0 comments on commit 4dccd78

Please sign in to comment.