handle window resize event and set width accordingly (#291)

This fixes #215 and gives proper aligned tab-completion.
pull/311/head
Levente Polyak 9 years ago committed by Zach Riggle
parent ed2b5a7b9c
commit e38f44df70

@ -5,6 +5,8 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import signal
import gdb
import pwndbg.android
@ -67,6 +69,7 @@ import pwndbg.prompt
import pwndbg.regs
import pwndbg.stack
import pwndbg.typeinfo
import pwndbg.ui
import pwndbg.version
import pwndbg.vmmap
import pwndbg.wrappers
@ -131,13 +134,13 @@ set follow-fork-mode child
set backtrace past-main on
set step-mode on
set print pretty on
set width 0
set width %i
set print elements 15
handle SIGALRM nostop print nopass
handle SIGBUS stop print nopass
handle SIGPIPE nostop print nopass
handle SIGSEGV stop print nopass
""".strip() % prompt
""".strip() % (prompt, pwndbg.ui.get_window_size()[1])
for line in pre_commands.strip().splitlines():
gdb.execute(line)
@ -147,3 +150,7 @@ try:
gdb.execute("set disassembly-flavor intel")
except gdb.error:
pass
# handle resize event to align width and completion
signal.signal(signal.SIGWINCH, lambda signum, frame: gdb.execute("set width %i" % pwndbg.ui.get_window_size()[1]))

@ -9,6 +9,7 @@ from __future__ import print_function
from __future__ import unicode_literals
import fcntl
import os
import struct
import sys
import termios
@ -22,13 +23,21 @@ theme.Parameter('banner-separator', '─', 'repeated banner separator character'
def banner(title):
title = title.upper()
try:
_height, width = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))
except:
width = 80
_height, width = get_window_size()
width -= 2
return C.banner(("[{:%s^%ss}]" % (config.banner_separator, width)).format(title))
def addrsz(address):
address = int(address) & pwndbg.arch.ptrmask
return "%{}x".format(2*pwndbg.arch.ptrsize) % address
def get_window_size():
fallback = (int(os.environ.get('LINES', 20)), int(os.environ.get('COLUMNS', 80)))
if not sys.stdin.isatty:
return fallback
try:
# get terminal size and force ret buffer len of 4 bytes for safe unpacking by passing equally long arg
rows, cols = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))
except:
rows, cols = fallback
return rows, cols

Loading…
Cancel
Save