prompt-toolkit / prompt-toolkit/python-prompt-toolkit

consider tput instead of TIOCGWINSZ?

Open
#1,003 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/output/vt100.py#L369 (_get_size) currently uses TIOCGWINSZ to get the terminal size

on the particular system i use, for some reason this fails to get the correct size

stty -a
speed 38400 baud; rows 0; columns 0; line = 0;
                  ~~~~~~~~~~~~~~~~~           
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc

but asking tput gets the right answer

$ tput lines
36
$ tput cols
78

in python this can be done using

curses.setupterm()
rows = curses.tigetnum('lines')
columns = curses.tigetnum('cols')

i'm not sure if there are any downsides to this/situations where the former works and the latter doesn't but would you be interested in trying this approach instead (and/or as a fallback)

thanks,
david

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in prompt_toolkit/output/vt100.py at _get_size and compare the current TIOCGWINSZ path with the reported curses.setupterm(), tigetnum('lines'), and tigetnum('cols') approach. Check how each behaves on terminals reporting zero rows and columns; done means _get_size returns the correct dimensions without breaking cases where TIOCGWINSZ works.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.