Skip to content

Undo backwards-incompatible change in naming of cmd2.ansi.Cursor method. #1430

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

Merged
merged 1 commit into from
May 25, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 7 additions & 7 deletions cmd2/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"prettier": "^3.5.3",
"prettier-plugin-toml": "^2.0.5"
}
}
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading