Skip to content

Commit

Permalink
refactor: replace cleo's removed Terminal class (python-poetry#6224)
Browse files Browse the repository at this point in the history
`cleo.terminal.Terminal` was replaced in python-poetry/cleo#175 in favor of `shutil.get_terminal_size`
  • Loading branch information
branchvincent committed Sep 1, 2022
1 parent a412613 commit 8083974
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ class ShowCommand(GroupCommand):
colors = ["cyan", "yellow", "green", "magenta", "blue"]

def handle(self) -> int:
import shutil

from cleo.io.null_io import NullIO
from cleo.terminal import Terminal

from poetry.puzzle.solver import Solver
from poetry.repositories.installed_repository import InstalledRepository
Expand Down Expand Up @@ -209,8 +210,7 @@ def handle(self) -> int:

show_latest = self.option("latest")
show_all = self.option("all")
terminal = Terminal()
width = terminal.width
width = shutil.get_terminal_size().columns
name_length = version_length = latest_length = required_by_length = 0
latest_packages = {}
latest_statuses = {}
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/utils/shell.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import shutil
import signal
import subprocess
import sys
Expand All @@ -11,7 +12,6 @@

import pexpect

from cleo.terminal import Terminal
from shellingham import ShellDetectionFailure
from shellingham import detect_shell

Expand Down Expand Up @@ -87,10 +87,10 @@ def activate(self, env: VirtualEnv) -> int | None:

import shlex

terminal = Terminal()
terminal = shutil.get_terminal_size()
with env.temp_environ():
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"]:
Expand All @@ -99,8 +99,8 @@ def activate(self, env: VirtualEnv) -> int | None:
c.sendline(f"{self._get_source_command()} {shlex.quote(str(activate_path))}")

def resize(sig: Any, data: Any) -> None:
terminal = Terminal()
c.setwinsize(terminal.height, terminal.width)
terminal = shutil.get_terminal_size()
c.setwinsize(terminal.lines, terminal.columns)

signal.signal(signal.SIGWINCH, resize)

Expand Down

0 comments on commit 8083974

Please sign in to comment.