Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/polysh/dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,12 @@ def update_terminal_size() -> None:
place taken by the longest name"""
w, h = terminal_size()
w = max(w - display_names.max_display_name_length - 2, min(w, 10))
# python bug http://python.org/sf/1112949 on amd64
# from ajaxterm.py
bug = struct.unpack('i', struct.pack('I', termios.TIOCSWINSZ))[0]
packed_size = struct.pack('HHHH', h, w, 0, 0)
term_size = w, h
for i in all_instances():
if i.enabled and i.term_size != term_size:
i.term_size = term_size
fcntl.ioctl(i.fd, bug, packed_size)
fcntl.ioctl(i.fd, termios.TIOCSWINSZ, packed_size)


def format_info(info_list: List[List[bytes]]) -> List[bytes]:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import fcntl
import os
import struct
import termios
from types import SimpleNamespace

import pytest

from polysh import dispatchers
from polysh.dispatchers import _split_port, format_info


Expand Down Expand Up @@ -48,3 +55,22 @@ def test_format_info_pads_all_but_the_last_column():
])
def test_split_port(host, split):
assert _split_port(host) == split


def test_update_terminal_size_uses_unsigned_request(monkeypatch):
"""TIOCSWINSZ does not fit in a signed int on macOS: passing it
converted to a negative number makes the ioctl fail with ENOTTY"""
master, slave = os.openpty()
remote = SimpleNamespace(enabled=True, term_size=(-1, -1), fd=master)
monkeypatch.setattr(dispatchers, 'all_instances', lambda: [remote])
monkeypatch.setattr(dispatchers, 'terminal_size', lambda: (80, 24))
monkeypatch.setattr(dispatchers.display_names, 'max_display_name_length', 0)
try:
dispatchers.update_terminal_size()
rows, cols, _, _ = struct.unpack(
'HHHH', fcntl.ioctl(slave, termios.TIOCGWINSZ, b'\0' * 8)
)
finally:
os.close(master)
os.close(slave)
assert (cols, rows) == (78, 24)
Loading