Skip to content

Commit c836f40

Browse files
Fix the size of terminal
1 parent 124fb97 commit c836f40

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

moler/io/raw/pty_process_unicode.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import pty
1111
import shlex
12+
import termios
1213
import subprocess
1314

1415
from typing import Optional, Tuple, Union
@@ -71,6 +72,24 @@ def create_pty_process(self) -> None:
7172
self.process = process
7273
self._closed = False
7374

75+
# Apply initial terminal dimensions configured for this PTY.
76+
self.setwinsize(*self.dimensions)
77+
78+
def setwinsize(self, rows: int, cols: int) -> None:
79+
"""
80+
Set terminal dimensions of the pty process.
81+
:param rows: terminal rows
82+
:param cols: terminal columns
83+
:return: None
84+
"""
85+
if rows <= 0 or cols <= 0:
86+
raise ValueError("Terminal dimensions must be positive")
87+
if self.fd < 0:
88+
raise MolerException("Cannot resize closed pty process")
89+
90+
termios.tcsetwinsize(self.fd, (rows, cols))
91+
self.dimensions = (rows, cols)
92+
7493
def write(self, data: Union[str, bytes]) -> int:
7594
"""
7695
Write data to pty process.

0 commit comments

Comments
 (0)