From 28d9895316e6029ce05f234f89a8f5814407235d Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Sun, 25 May 2025 12:40:06 -0400 Subject: [PATCH] Undo backwards-incompatible change in naming of cmd2.ansi.Cursor method. It just wasn't worth making a backwards-incompatible change which might impact people, especially since we are likely to replace the ansi module with one based on rich in the near future. Also updated the Makefile to also install prettier using npm and added the package.json file to Git to support this. --- .gitignore | 1 - CHANGELOG.md | 1 - Makefile | 6 ++++-- cmd2/ansi.py | 14 +++++++------- package.json | 6 ++++++ pyproject.toml | 2 -- tests/test_ansi.py | 10 +++++----- 7 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 1e675473e..51218eb83 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,3 @@ uv.lock # Node/npm used for installing Prettier locally to override the outdated version that is bundled with the VSCode extension node_modules/ package-lock.json -package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e98f405f..3423fe707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ - Breaking Change - `cmd2` 2.6 supports Python 3.9+ (removed support for Python 3.8) - - Renamed methods in `cmd2.ansi.Cursor` to make it clear they are intended for internal use only as was documented - Enhancements - Add support for Python 3.14 diff --git a/Makefile b/Makefile index 52de0b91d..feceebaed 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ # Simple Makefile for use with a uv-based development environment .PHONY: install -install: ## Install the virtual environment - @echo "🚀 Creating virtual environment" +install: ## Install the virtual environment with dependencies + @echo "🚀 Creating uv Python virtual environment" @uv sync + @echo "🚀 Installing Prettier using npm" + @npm install .PHONY: check check: ## Run code quality tools. diff --git a/cmd2/ansi.py b/cmd2/ansi.py index b9c3d3384..cca020188 100644 --- a/cmd2/ansi.py +++ b/cmd2/ansi.py @@ -219,27 +219,27 @@ class Cursor: """Create ANSI sequences to alter the cursor position.""" @staticmethod - def _up(count: int = 1) -> str: + def UP(count: int = 1) -> str: # noqa: N802 """Move the cursor up a specified amount of lines (Defaults to 1).""" return f"{CSI}{count}A" @staticmethod - def _down(count: int = 1) -> str: + def DOWN(count: int = 1) -> str: # noqa: N802 """Move the cursor down a specified amount of lines (Defaults to 1).""" return f"{CSI}{count}B" @staticmethod - def _forward(count: int = 1) -> str: + def FORWARD(count: int = 1) -> str: # noqa: N802 """Move the cursor forward a specified amount of lines (Defaults to 1).""" return f"{CSI}{count}C" @staticmethod - def _back(count: int = 1) -> str: + def BACK(count: int = 1) -> str: # noqa: N802 """Move the cursor back a specified amount of lines (Defaults to 1).""" return f"{CSI}{count}D" @staticmethod - def _set_pos(x: int, y: int) -> str: + def SET_POS(x: int, y: int) -> str: # noqa: N802 """Set the cursor position to coordinates which are 1-based.""" return f"{CSI}{y};{x}H" @@ -1079,11 +1079,11 @@ def async_alert_str(*, terminal_columns: int, prompt: str, line: str, cursor_off # Move the cursor down to the last input line if cursor_input_line != num_input_terminal_lines: - terminal_str += Cursor._down(num_input_terminal_lines - cursor_input_line) + terminal_str += Cursor.DOWN(num_input_terminal_lines - cursor_input_line) # Clear each line from the bottom up so that the cursor ends up on the first prompt line total_lines = num_prompt_terminal_lines + num_input_terminal_lines - terminal_str += (clear_line() + Cursor._up(1)) * (total_lines - 1) + terminal_str += (clear_line() + Cursor.UP(1)) * (total_lines - 1) # Clear the first prompt line terminal_str += clear_line() diff --git a/package.json b/package.json new file mode 100644 index 000000000..6d5accd87 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "devDependencies": { + "prettier": "^3.5.3", + "prettier-plugin-toml": "^2.0.5" + } +} diff --git a/pyproject.toml b/pyproject.toml index 1a550c401..75476f393 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -266,7 +266,6 @@ per-file-ignores."cmd2/argparse_custom.py" = [ "B010", # Do not call setattr with a constant attribute value ] - per-file-ignores."examples/*.py" = [ "ANN", # Ignore all type annotation rules in examples folder "D", # Ignore all pydocstyle rules in examples folder @@ -309,7 +308,6 @@ per-file-ignores."tests_isolated/*.py" = [ "SLF", # Ignore all warnings about private or protected member access in test folders ] - [tool.ruff.format] # Like Black, use double quotes for strings. quote-style = "preserve" diff --git a/tests/test_ansi.py b/tests/test_ansi.py index 329f7e8ed..841190724 100644 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -202,14 +202,14 @@ def test_clear_line() -> None: def test_cursor() -> None: count = 1 - assert ansi.Cursor._up(count) == f"{ansi.CSI}{count}A" - assert ansi.Cursor._down(count) == f"{ansi.CSI}{count}B" - assert ansi.Cursor._forward(count) == f"{ansi.CSI}{count}C" - assert ansi.Cursor._back(count) == f"{ansi.CSI}{count}D" + assert ansi.Cursor.UP(count) == f"{ansi.CSI}{count}A" + assert ansi.Cursor.DOWN(count) == f"{ansi.CSI}{count}B" + assert ansi.Cursor.FORWARD(count) == f"{ansi.CSI}{count}C" + assert ansi.Cursor.BACK(count) == f"{ansi.CSI}{count}D" x = 4 y = 5 - assert ansi.Cursor._set_pos(x, y) == f"{ansi.CSI}{y};{x}H" + assert ansi.Cursor.SET_POS(x, y) == f"{ansi.CSI}{y};{x}H" @pytest.mark.parametrize(