Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pidcat prints nothing when run through emacs #142

Open
olegat opened this issue Apr 19, 2017 · 0 comments
Open

pidcat prints nothing when run through emacs #142

olegat opened this issue Apr 19, 2017 · 0 comments

Comments

@olegat
Copy link

olegat commented Apr 19, 2017

pidcat do not show anything if it's run through the emacs Terminal emulator.

Steps to reproduce:

  • Install Emacs and pidcat
  • Open up a terminal
  • Run emacs
  • Hit M-x (Alt+x)
  • Type shell and hit ENTER
  • Type pidcat.py and hit ENTER

Notes:

  • You can kill the python process by hitting C-c C-c (Control+C, Control+C)
  • You should see that the script is stuck in a loop in indent_wrap
  • To exit emacs, hit C-x C-c (Control+X, followed by Control+C). You may need to type yes if you're prompted to kill the active shell process
def indent_wrap(message):
  if width == -1:
    return message
  message = message.replace('\t', '    ')
  wrap_area = width - header_size
  messagebuf = ''
  current = 0
  while current < len(message):
    next = min(current + wrap_area, len(message))
    messagebuf += message[current:next]
    if next < len(message):
      messagebuf += '\n'
      messagebuf += ' ' * header_size
    current = next
  return messagebuf

The script is looping because width is 0, this causes wrap_area = width - header_size to produce a negative number, which causes next = min(current + wrap_area, len(message)) to continuously decrease in every loop iteration because the left-hand parameter of min is always negative.

There's a workaround that involves tweaking the initialisation of width:

width = -1
try:
  # Get the current terminal width                                                                                                              
  import fcntl, termios, struct
  h, width = struct.unpack('hh', fcntl.ioctl(0, termios.TIOCGWINSZ, struct.pack('hh', 0, 0)))
  # ioctl may occasionally return 0 (example, in emacs terminal)                                                                                
  if width <= 0:
    width = -1
except:
  pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant