prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Typesetting seems to be wrong
  ![image](https://cloud.githubusercontent.com/assets/7897423/24843862/42e004bc-1dd9-11e7-8447-b8cf87ed6fe1.png)
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pwndbg/__init__.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 from __future__ import absolute_import
  4 from __future__ import division
  5 from __future__ import print_function
  6 from __future__ import unicode_literals
  7 
  8 import gdb
  9 
  10 import pwndbg.android
  11 import pwndbg.arch
  12 import pwndbg.arguments
  13 import pwndbg.argv
  14 import pwndbg.color
  15 import pwndbg.commands
  16 import pwndbg.commands.argv
  17 import pwndbg.commands.aslr
  18 import pwndbg.commands.auxv
  19 import pwndbg.commands.checksec
  20 import pwndbg.commands.config
  21 import pwndbg.commands.context
  22 import pwndbg.commands.cpsr
  23 import pwndbg.commands.dt
  24 import pwndbg.commands.dumpargs
  25 import pwndbg.commands.elf
  26 import pwndbg.commands.gdbinit
  27 import pwndbg.commands.got
  28 import pwndbg.commands.heap
  29 import pwndbg.commands.hexdump
  30 import pwndbg.commands.ida
  31 import pwndbg.commands.misc
  32 import pwndbg.commands.next
  33 import pwndbg.commands.peda
  34 import pwndbg.commands.procinfo
  35 import pwndbg.commands.radare2
  36 import pwndbg.commands.reload
  37 import pwndbg.commands.rop
  38 import pwndbg.commands.ropper
  39 import pwndbg.commands.search
  40 import pwndbg.commands.segments
  41 import pwndbg.commands.shell
  42 import pwndbg.commands.stack
  43 import pwndbg.commands.start
  44 import pwndbg.commands.telescope
  45 import pwndbg.commands.theme
  46 import pwndbg.commands.version
  47 import pwndbg.commands.vmmap
  48 import pwndbg.commands.windbg
  49 import pwndbg.commands.xor
  50 import pwndbg.constants
  51 import pwndbg.disasm
  52 import pwndbg.disasm.arm
  53 import pwndbg.disasm.jump
  54 import pwndbg.disasm.mips
  55 import pwndbg.disasm.ppc
  56 import pwndbg.disasm.sparc
  57 import pwndbg.disasm.x86
  58 import pwndbg.dt
  59 import pwndbg.elf
  60 import pwndbg.exception
  61 import pwndbg.heap
  62 import pwndbg.inthook
  63 import pwndbg.memory
  64 import pwndbg.net
  65 import pwndbg.proc
  66 import pwndbg.prompt
  67 import pwndbg.regs
  68 import pwndbg.stack
  69 import pwndbg.typeinfo
  70 import pwndbg.version
  71 import pwndbg.vmmap
  72 import pwndbg.wrappers
  73 
  74 __version__ = pwndbg.version.__version__
  75 version = __version__
  76 
  77 try:
  78     import unicorn
  79     import pwndbg.emu
  80 except:
  81     pass
  82 
  83 __all__ = [
  84 'arch',
  85 'auxv',
  86 'chain',
  87 'color',
  88 'compat',
  89 'disasm',
  90 'dt',
  91 'elf',
  92 'enhance',
  93 'events',
  94 'file',
  95 'function',
  96 'heap',
  97 'hexdump',
  98 'ida',
  99 'info',
  100 'linkmap',
  101 'malloc',
  102 'memoize',
  103 'memory',
  104 'proc',
  105 'regs',
  106 'remote',
  107 'search',
  108 'stack',
  109 'strings',
  110 'symbol',
  111 'typeinfo',
  112 'ui',
  113 'vmmap'
  114 ]
  115 
  116 prompt = "pwndbg> "
  117 prompt = "\x02" + prompt + "\x01" # STX + prompt + SOH
  118 prompt = pwndbg.color.red(prompt)
  119 prompt = pwndbg.color.bold(prompt)
  120 prompt = "\x01" + prompt + "\x02" # SOH + prompt + STX
  121 
  122 pre_commands = """
  123 set confirm off
  124 set verbose off
  125 set prompt %s
  126 set pagination off
  127 set height 0
  128 set history expansion on
  129 set history save on
  130 set follow-fork-mode child
  131 set backtrace past-main on
  132 set step-mode on
  133 set print pretty on
  134 set width 0
  135 set print elements 15
  136 handle SIGALRM nostop print nopass
  137 handle SIGBUS  stop   print nopass
  138 handle SIGPIPE nostop print nopass
  139 handle SIGSEGV stop   print nopass
  140 """.strip() % prompt
  141 
  142 for line in pre_commands.strip().splitlines():
  143     gdb.execute(line)
  144 
  145 # This may throw an exception, see pwndbg/pwndbg#27
  146 try:
  147     gdb.execute("set disassembly-flavor intel")
  148 except gdb.error:
  149     pass
  150
  ```
  
  Path: `pwndbg/ui.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 """
  4 A few helpers for making things print pretty-like.
  5 """
  6 from __future__ import absolute_import
  7 from __future__ import division
  8 from __future__ import print_function
  9 from __future__ import unicode_literals
  10 
  11 import fcntl
  12 import struct
  13 import sys
  14 import termios
  15 
  16 import pwndbg.arch
  17 import pwndbg.color.context as C
  18 import pwndbg.color.theme as theme
  19 import pwndbg.config as config
  20 
  21 theme.Parameter('banner-separator', '─', 'repeated banner separator character')
  22 
  23 def banner(title):
  24     title = title.upper()
  25     try:
  26         _height, width = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))
  27     except:
  28         width = 80
  29     width -= 2
  30     return C.banner(("[{:%s^%ss}]" % (config.banner_separator, width)).format(title))
  31 
  32 def addrsz(address):
  33     address = int(address) & pwndbg.arch.ptrmask
  34     return "%{}x".format(2*pwndbg.arch.ptrsize) % address
  35
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py
  --- a/pwndbg/__init__.py
  +++ b/pwndbg/__init__.py
  @@ -5,6 +5,8 @@
   from __future__ import print_function
   from __future__ import unicode_literals
   
  +import signal
  +
   import gdb
   
   import pwndbg.android
  @@ -67,6 +69,7 @@
   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 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 @@
       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]))
  diff --git a/pwndbg/ui.py b/pwndbg/ui.py
  --- a/pwndbg/ui.py
  +++ b/pwndbg/ui.py
  @@ -9,6 +9,7 @@
   from __future__ import unicode_literals
   
   import fcntl
  +import os
   import struct
   import sys
   import termios
  @@ -22,13 +23,21 @@
   
   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
  
verification_info: {"golden_diff": "diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py\n--- a/pwndbg/__init__.py\n+++ b/pwndbg/__init__.py\n@@ -5,6 +5,8 @@\n from __future__ import print_function\n from __future__ import unicode_literals\n \n+import signal\n+\n import gdb\n \n import pwndbg.android\n@@ -67,6 +69,7 @@\n import pwndbg.regs\n import pwndbg.stack\n import pwndbg.typeinfo\n+import pwndbg.ui\n import pwndbg.version\n import pwndbg.vmmap\n import pwndbg.wrappers\n@@ -131,13 +134,13 @@\n set backtrace past-main on\n set step-mode on\n set print pretty on\n-set width 0\n+set width %i\n set print elements 15\n handle SIGALRM nostop print nopass\n handle SIGBUS  stop   print nopass\n handle SIGPIPE nostop print nopass\n handle SIGSEGV stop   print nopass\n-\"\"\".strip() % prompt\n+\"\"\".strip() % (prompt, pwndbg.ui.get_window_size()[1])\n \n for line in pre_commands.strip().splitlines():\n     gdb.execute(line)\n@@ -147,3 +150,7 @@\n     gdb.execute(\"set disassembly-flavor intel\")\n except gdb.error:\n     pass\n+\n+\n+# handle resize event to align width and completion\n+signal.signal(signal.SIGWINCH, lambda signum, frame: gdb.execute(\"set width %i\" % pwndbg.ui.get_window_size()[1]))\ndiff --git a/pwndbg/ui.py b/pwndbg/ui.py\n--- a/pwndbg/ui.py\n+++ b/pwndbg/ui.py\n@@ -9,6 +9,7 @@\n from __future__ import unicode_literals\n \n import fcntl\n+import os\n import struct\n import sys\n import termios\n@@ -22,13 +23,21 @@\n \n def banner(title):\n     title = title.upper()\n-    try:\n-        _height, width = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))\n-    except:\n-        width = 80\n+    _height, width = get_window_size()\n     width -= 2\n     return C.banner((\"[{:%s^%ss}]\" % (config.banner_separator, width)).format(title))\n \n def addrsz(address):\n     address = int(address) & pwndbg.arch.ptrmask\n     return \"%{}x\".format(2*pwndbg.arch.ptrsize) % address\n+\n+def get_window_size():\n+    fallback = (int(os.environ.get('LINES', 20)), int(os.environ.get('COLUMNS', 80)))\n+    if not sys.stdin.isatty:\n+        return fallback\n+    try:\n+        # get terminal size and force ret buffer len of 4 bytes for safe unpacking by passing equally long arg\n+        rows, cols = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))\n+    except:\n+        rows, cols = fallback\n+    return rows, cols\n", "issue": "Typesetting seems to be wrong\n![image](https://cloud.githubusercontent.com/assets/7897423/24843862/42e004bc-1dd9-11e7-8447-b8cf87ed6fe1.png)\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport gdb\n\nimport pwndbg.android\nimport pwndbg.arch\nimport pwndbg.arguments\nimport pwndbg.argv\nimport pwndbg.color\nimport pwndbg.commands\nimport pwndbg.commands.argv\nimport pwndbg.commands.aslr\nimport pwndbg.commands.auxv\nimport pwndbg.commands.checksec\nimport pwndbg.commands.config\nimport pwndbg.commands.context\nimport pwndbg.commands.cpsr\nimport pwndbg.commands.dt\nimport pwndbg.commands.dumpargs\nimport pwndbg.commands.elf\nimport pwndbg.commands.gdbinit\nimport pwndbg.commands.got\nimport pwndbg.commands.heap\nimport pwndbg.commands.hexdump\nimport pwndbg.commands.ida\nimport pwndbg.commands.misc\nimport pwndbg.commands.next\nimport pwndbg.commands.peda\nimport pwndbg.commands.procinfo\nimport pwndbg.commands.radare2\nimport pwndbg.commands.reload\nimport pwndbg.commands.rop\nimport pwndbg.commands.ropper\nimport pwndbg.commands.search\nimport pwndbg.commands.segments\nimport pwndbg.commands.shell\nimport pwndbg.commands.stack\nimport pwndbg.commands.start\nimport pwndbg.commands.telescope\nimport pwndbg.commands.theme\nimport pwndbg.commands.version\nimport pwndbg.commands.vmmap\nimport pwndbg.commands.windbg\nimport pwndbg.commands.xor\nimport pwndbg.constants\nimport pwndbg.disasm\nimport pwndbg.disasm.arm\nimport pwndbg.disasm.jump\nimport pwndbg.disasm.mips\nimport pwndbg.disasm.ppc\nimport pwndbg.disasm.sparc\nimport pwndbg.disasm.x86\nimport pwndbg.dt\nimport pwndbg.elf\nimport pwndbg.exception\nimport pwndbg.heap\nimport pwndbg.inthook\nimport pwndbg.memory\nimport pwndbg.net\nimport pwndbg.proc\nimport pwndbg.prompt\nimport pwndbg.regs\nimport pwndbg.stack\nimport pwndbg.typeinfo\nimport pwndbg.version\nimport pwndbg.vmmap\nimport pwndbg.wrappers\n\n__version__ = pwndbg.version.__version__\nversion = __version__\n\ntry:\n    import unicorn\n    import pwndbg.emu\nexcept:\n    pass\n\n__all__ = [\n'arch',\n'auxv',\n'chain',\n'color',\n'compat',\n'disasm',\n'dt',\n'elf',\n'enhance',\n'events',\n'file',\n'function',\n'heap',\n'hexdump',\n'ida',\n'info',\n'linkmap',\n'malloc',\n'memoize',\n'memory',\n'proc',\n'regs',\n'remote',\n'search',\n'stack',\n'strings',\n'symbol',\n'typeinfo',\n'ui',\n'vmmap'\n]\n\nprompt = \"pwndbg> \"\nprompt = \"\\x02\" + prompt + \"\\x01\" # STX + prompt + SOH\nprompt = pwndbg.color.red(prompt)\nprompt = pwndbg.color.bold(prompt)\nprompt = \"\\x01\" + prompt + \"\\x02\" # SOH + prompt + STX\n\npre_commands = \"\"\"\nset confirm off\nset verbose off\nset prompt %s\nset pagination off\nset height 0\nset history expansion on\nset history save on\nset follow-fork-mode child\nset backtrace past-main on\nset step-mode on\nset print pretty on\nset width 0\nset print elements 15\nhandle SIGALRM nostop print nopass\nhandle SIGBUS  stop   print nopass\nhandle SIGPIPE nostop print nopass\nhandle SIGSEGV stop   print nopass\n\"\"\".strip() % prompt\n\nfor line in pre_commands.strip().splitlines():\n    gdb.execute(line)\n\n# This may throw an exception, see pwndbg/pwndbg#27\ntry:\n    gdb.execute(\"set disassembly-flavor intel\")\nexcept gdb.error:\n    pass\n", "path": "pwndbg/__init__.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"\nA few helpers for making things print pretty-like.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport fcntl\nimport struct\nimport sys\nimport termios\n\nimport pwndbg.arch\nimport pwndbg.color.context as C\nimport pwndbg.color.theme as theme\nimport pwndbg.config as config\n\ntheme.Parameter('banner-separator', '\u2500', 'repeated banner separator character')\n\ndef banner(title):\n    title = title.upper()\n    try:\n        _height, width = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))\n    except:\n        width = 80\n    width -= 2\n    return C.banner((\"[{:%s^%ss}]\" % (config.banner_separator, width)).format(title))\n\ndef addrsz(address):\n    address = int(address) & pwndbg.arch.ptrmask\n    return \"%{}x\".format(2*pwndbg.arch.ptrsize) % address\n", "path": "pwndbg/ui.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport signal\n\nimport gdb\n\nimport pwndbg.android\nimport pwndbg.arch\nimport pwndbg.arguments\nimport pwndbg.argv\nimport pwndbg.color\nimport pwndbg.commands\nimport pwndbg.commands.argv\nimport pwndbg.commands.aslr\nimport pwndbg.commands.auxv\nimport pwndbg.commands.checksec\nimport pwndbg.commands.config\nimport pwndbg.commands.context\nimport pwndbg.commands.cpsr\nimport pwndbg.commands.dt\nimport pwndbg.commands.dumpargs\nimport pwndbg.commands.elf\nimport pwndbg.commands.gdbinit\nimport pwndbg.commands.got\nimport pwndbg.commands.heap\nimport pwndbg.commands.hexdump\nimport pwndbg.commands.ida\nimport pwndbg.commands.misc\nimport pwndbg.commands.next\nimport pwndbg.commands.peda\nimport pwndbg.commands.procinfo\nimport pwndbg.commands.radare2\nimport pwndbg.commands.reload\nimport pwndbg.commands.rop\nimport pwndbg.commands.ropper\nimport pwndbg.commands.search\nimport pwndbg.commands.segments\nimport pwndbg.commands.shell\nimport pwndbg.commands.stack\nimport pwndbg.commands.start\nimport pwndbg.commands.telescope\nimport pwndbg.commands.theme\nimport pwndbg.commands.version\nimport pwndbg.commands.vmmap\nimport pwndbg.commands.windbg\nimport pwndbg.commands.xor\nimport pwndbg.constants\nimport pwndbg.disasm\nimport pwndbg.disasm.arm\nimport pwndbg.disasm.jump\nimport pwndbg.disasm.mips\nimport pwndbg.disasm.ppc\nimport pwndbg.disasm.sparc\nimport pwndbg.disasm.x86\nimport pwndbg.dt\nimport pwndbg.elf\nimport pwndbg.exception\nimport pwndbg.heap\nimport pwndbg.inthook\nimport pwndbg.memory\nimport pwndbg.net\nimport pwndbg.proc\nimport pwndbg.prompt\nimport pwndbg.regs\nimport pwndbg.stack\nimport pwndbg.typeinfo\nimport pwndbg.ui\nimport pwndbg.version\nimport pwndbg.vmmap\nimport pwndbg.wrappers\n\n__version__ = pwndbg.version.__version__\nversion = __version__\n\ntry:\n    import unicorn\n    import pwndbg.emu\nexcept:\n    pass\n\n__all__ = [\n'arch',\n'auxv',\n'chain',\n'color',\n'compat',\n'disasm',\n'dt',\n'elf',\n'enhance',\n'events',\n'file',\n'function',\n'heap',\n'hexdump',\n'ida',\n'info',\n'linkmap',\n'malloc',\n'memoize',\n'memory',\n'proc',\n'regs',\n'remote',\n'search',\n'stack',\n'strings',\n'symbol',\n'typeinfo',\n'ui',\n'vmmap'\n]\n\nprompt = \"pwndbg> \"\nprompt = \"\\x02\" + prompt + \"\\x01\" # STX + prompt + SOH\nprompt = pwndbg.color.red(prompt)\nprompt = pwndbg.color.bold(prompt)\nprompt = \"\\x01\" + prompt + \"\\x02\" # SOH + prompt + STX\n\npre_commands = \"\"\"\nset confirm off\nset verbose off\nset prompt %s\nset pagination off\nset height 0\nset history expansion on\nset history save on\nset follow-fork-mode child\nset backtrace past-main on\nset step-mode on\nset print pretty on\nset width %i\nset print elements 15\nhandle SIGALRM nostop print nopass\nhandle SIGBUS  stop   print nopass\nhandle SIGPIPE nostop print nopass\nhandle SIGSEGV stop   print nopass\n\"\"\".strip() % (prompt, pwndbg.ui.get_window_size()[1])\n\nfor line in pre_commands.strip().splitlines():\n    gdb.execute(line)\n\n# This may throw an exception, see pwndbg/pwndbg#27\ntry:\n    gdb.execute(\"set disassembly-flavor intel\")\nexcept gdb.error:\n    pass\n\n\n# handle resize event to align width and completion\nsignal.signal(signal.SIGWINCH, lambda signum, frame: gdb.execute(\"set width %i\" % pwndbg.ui.get_window_size()[1]))\n", "path": "pwndbg/__init__.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"\nA few helpers for making things print pretty-like.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport fcntl\nimport os\nimport struct\nimport sys\nimport termios\n\nimport pwndbg.arch\nimport pwndbg.color.context as C\nimport pwndbg.color.theme as theme\nimport pwndbg.config as config\n\ntheme.Parameter('banner-separator', '\u2500', 'repeated banner separator character')\n\ndef banner(title):\n    title = title.upper()\n    _height, width = get_window_size()\n    width -= 2\n    return C.banner((\"[{:%s^%ss}]\" % (config.banner_separator, width)).format(title))\n\ndef addrsz(address):\n    address = int(address) & pwndbg.arch.ptrmask\n    return \"%{}x\".format(2*pwndbg.arch.ptrsize) % address\n\ndef get_window_size():\n    fallback = (int(os.environ.get('LINES', 20)), int(os.environ.get('COLUMNS', 80)))\n    if not sys.stdin.isatty:\n        return fallback\n    try:\n        # get terminal size and force ret buffer len of 4 bytes for safe unpacking by passing equally long arg\n        rows, cols = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))\n    except:\n        rows, cols = fallback\n    return rows, cols\n", "path": "pwndbg/ui.py"}]}