JakeWharton / JakeWharton/pidcat
pidcat prints nothing when run through emacs
- Dominant language
- Python
- Stars
- 5k
- Forks
- 517
- PR merge metrics
- No merged PRs in 30d
Description
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
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in pidcat.py at indent_wrap and the width initialization shown in the issue. Reproduce the zero-width case through Emacs's shell, then verify that pidcat no longer loops and produces output there while continuing to work in a normal terminal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100