Commit bd32b9ea by Branch Vincent Committed by GitHub

refactor: replace cleo's removed `Terminal` class (#6224)

`cleo.terminal.Terminal` was replaced in https://github.com/python-poetry/cleo/pull/175 in favor of `shutil.get_terminal_size`
parent a4903861
...@@ -68,8 +68,9 @@ lists all packages available.""" ...@@ -68,8 +68,9 @@ lists all packages available."""
colors = ["cyan", "yellow", "green", "magenta", "blue"] colors = ["cyan", "yellow", "green", "magenta", "blue"]
def handle(self) -> int: def handle(self) -> int:
import shutil
from cleo.io.null_io import NullIO from cleo.io.null_io import NullIO
from cleo.terminal import Terminal
from poetry.puzzle.solver import Solver from poetry.puzzle.solver import Solver
from poetry.repositories.installed_repository import InstalledRepository from poetry.repositories.installed_repository import InstalledRepository
...@@ -209,8 +210,7 @@ lists all packages available.""" ...@@ -209,8 +210,7 @@ lists all packages available."""
show_latest = self.option("latest") show_latest = self.option("latest")
show_all = self.option("all") show_all = self.option("all")
terminal = Terminal() width = shutil.get_terminal_size().columns
width = terminal.width
name_length = version_length = latest_length = required_by_length = 0 name_length = version_length = latest_length = required_by_length = 0
latest_packages = {} latest_packages = {}
latest_statuses = {} latest_statuses = {}
......
from __future__ import annotations from __future__ import annotations
import os import os
import shutil
import signal import signal
import subprocess import subprocess
import sys import sys
...@@ -11,7 +12,6 @@ from typing import Any ...@@ -11,7 +12,6 @@ from typing import Any
import pexpect import pexpect
from cleo.terminal import Terminal
from shellingham import ShellDetectionFailure from shellingham import ShellDetectionFailure
from shellingham import detect_shell from shellingham import detect_shell
...@@ -87,10 +87,10 @@ class Shell: ...@@ -87,10 +87,10 @@ class Shell:
import shlex import shlex
terminal = Terminal() terminal = shutil.get_terminal_size()
with env.temp_environ(): with env.temp_environ():
c = pexpect.spawn( c = pexpect.spawn(
self._path, ["-i"], dimensions=(terminal.height, terminal.width) self._path, ["-i"], dimensions=(terminal.lines, terminal.columns)
) )
if self._name in ["zsh", "nu"]: if self._name in ["zsh", "nu"]:
...@@ -99,8 +99,8 @@ class Shell: ...@@ -99,8 +99,8 @@ class Shell:
c.sendline(f"{self._get_source_command()} {shlex.quote(str(activate_path))}") c.sendline(f"{self._get_source_command()} {shlex.quote(str(activate_path))}")
def resize(sig: Any, data: Any) -> None: def resize(sig: Any, data: Any) -> None:
terminal = Terminal() terminal = shutil.get_terminal_size()
c.setwinsize(terminal.height, terminal.width) c.setwinsize(terminal.lines, terminal.columns)
signal.signal(signal.SIGWINCH, resize) signal.signal(signal.SIGWINCH, resize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment