Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Terminal class with stdlib solution #175

Merged
merged 3 commits into from
Jul 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [1.0.0] - UNRELEASED

- Replaced `Terminal` class with `shutil.get_terminal_size()` from standard library
[#175](https://github.com/python-poetry/cleo/pull/175).


## [0.8.1] - 2020-04-17

### Changed
Expand Down
4 changes: 2 additions & 2 deletions cleo/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import re
import shutil
import sys

from contextlib import suppress
Expand Down Expand Up @@ -29,7 +30,6 @@
from cleo.io.io import IO
from cleo.io.outputs.output import Verbosity
from cleo.io.outputs.stream_output import StreamOutput
from cleo.terminal import Terminal
from cleo.ui.ui import UI


Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(self, name: str = "console", version: str = "") -> None:
self._name = name
self._version = version
self._display_name: str | None = None
self._terminal = Terminal()
self._terminal = shutil.get_terminal_size()
self._default_command = "list"
self._single_command = False
self._commands: dict[str, Command] = {}
Expand Down
6 changes: 3 additions & 3 deletions cleo/io/outputs/section_output.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

import math
import shutil

from typing import TYPE_CHECKING
from typing import TextIO

from cleo.io.outputs.output import Verbosity
from cleo.io.outputs.stream_output import StreamOutput
from cleo.terminal import Terminal


if TYPE_CHECKING:
Expand All @@ -31,7 +31,7 @@ def __init__(
self._lines = 0
sections.insert(0, self)
self._sections = sections
self._terminal = Terminal()
self._terminal = shutil.get_terminal_size()

@property
def content(self) -> str:
Expand Down Expand Up @@ -67,7 +67,7 @@ def add_content(self, content: str) -> None:
self._lines += (
math.ceil(
len(self.remove_format(line_content).replace("\t", " "))
/ self._terminal.width
/ self._terminal.columns
)
or 1
)
Expand Down
142 changes: 0 additions & 142 deletions cleo/terminal.py

This file was deleted.

8 changes: 4 additions & 4 deletions cleo/ui/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import math
import re
import shutil
import time

from typing import TYPE_CHECKING
Expand All @@ -11,7 +12,6 @@
from cleo.cursor import Cursor
from cleo.io.io import IO
from cleo.io.outputs.section_output import SectionOutput
from cleo.terminal import Terminal
from cleo.ui.component import Component


Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(
io = io.error_output

self._io = io
self._terminal = Terminal()
self._terminal = shutil.get_terminal_size()
self._max = 0
self._step_width = None
self._set_max_steps(max)
Expand Down Expand Up @@ -317,7 +317,7 @@ def _overwrite(self, message: str) -> None:
int(
math.floor(
len(self._io.remove_format(message))
/ self._terminal.width
/ self._terminal.columns
)
)
+ self._format_line_count
Expand Down Expand Up @@ -443,7 +443,7 @@ def _build_line(self) -> str:

lines_width = max(lines_length)

terminal_width = self._terminal.width
terminal_width = self._terminal.columns

if lines_width <= terminal_width:
return line
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ module = [
"cleo.io.inputs.input",
"cleo.io.inputs.token_parser",
"cleo.io.outputs.stream_output",
"cleo.terminal",
"cleo.testers.application_tester",
"cleo.testers.command_tester",
"cleo.ui.choice_question",
Expand Down