Skip to content

Commit 7549c93

Browse files
authored
Undo backwards-incompatible change in naming of cmd2.ansi.Cursor method. (#1430)
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.
1 parent 42247ba commit 7549c93

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,3 @@ uv.lock
5454
# Node/npm used for installing Prettier locally to override the outdated version that is bundled with the VSCode extension
5555
node_modules/
5656
package-lock.json
57-
package.json

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
- Breaking Change
44
- `cmd2` 2.6 supports Python 3.9+ (removed support for Python 3.8)
5-
- Renamed methods in `cmd2.ansi.Cursor` to make it clear they are intended for internal use only as was documented
65
- Enhancements
76
- Add support for Python 3.14
87

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Simple Makefile for use with a uv-based development environment
22
.PHONY: install
3-
install: ## Install the virtual environment
4-
@echo "🚀 Creating virtual environment"
3+
install: ## Install the virtual environment with dependencies
4+
@echo "🚀 Creating uv Python virtual environment"
55
@uv sync
6+
@echo "🚀 Installing Prettier using npm"
7+
@npm install
68

79
.PHONY: check
810
check: ## Run code quality tools.

cmd2/ansi.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,27 @@ class Cursor:
219219
"""Create ANSI sequences to alter the cursor position."""
220220

221221
@staticmethod
222-
def _up(count: int = 1) -> str:
222+
def UP(count: int = 1) -> str: # noqa: N802
223223
"""Move the cursor up a specified amount of lines (Defaults to 1)."""
224224
return f"{CSI}{count}A"
225225

226226
@staticmethod
227-
def _down(count: int = 1) -> str:
227+
def DOWN(count: int = 1) -> str: # noqa: N802
228228
"""Move the cursor down a specified amount of lines (Defaults to 1)."""
229229
return f"{CSI}{count}B"
230230

231231
@staticmethod
232-
def _forward(count: int = 1) -> str:
232+
def FORWARD(count: int = 1) -> str: # noqa: N802
233233
"""Move the cursor forward a specified amount of lines (Defaults to 1)."""
234234
return f"{CSI}{count}C"
235235

236236
@staticmethod
237-
def _back(count: int = 1) -> str:
237+
def BACK(count: int = 1) -> str: # noqa: N802
238238
"""Move the cursor back a specified amount of lines (Defaults to 1)."""
239239
return f"{CSI}{count}D"
240240

241241
@staticmethod
242-
def _set_pos(x: int, y: int) -> str:
242+
def SET_POS(x: int, y: int) -> str: # noqa: N802
243243
"""Set the cursor position to coordinates which are 1-based."""
244244
return f"{CSI}{y};{x}H"
245245

@@ -1079,11 +1079,11 @@ def async_alert_str(*, terminal_columns: int, prompt: str, line: str, cursor_off
10791079

10801080
# Move the cursor down to the last input line
10811081
if cursor_input_line != num_input_terminal_lines:
1082-
terminal_str += Cursor._down(num_input_terminal_lines - cursor_input_line)
1082+
terminal_str += Cursor.DOWN(num_input_terminal_lines - cursor_input_line)
10831083

10841084
# Clear each line from the bottom up so that the cursor ends up on the first prompt line
10851085
total_lines = num_prompt_terminal_lines + num_input_terminal_lines
1086-
terminal_str += (clear_line() + Cursor._up(1)) * (total_lines - 1)
1086+
terminal_str += (clear_line() + Cursor.UP(1)) * (total_lines - 1)
10871087

10881088
# Clear the first prompt line
10891089
terminal_str += clear_line()

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"devDependencies": {
3+
"prettier": "^3.5.3",
4+
"prettier-plugin-toml": "^2.0.5"
5+
}
6+
}

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ per-file-ignores."cmd2/argparse_custom.py" = [
266266
"B010", # Do not call setattr with a constant attribute value
267267
]
268268

269-
270269
per-file-ignores."examples/*.py" = [
271270
"ANN", # Ignore all type annotation rules in examples folder
272271
"D", # Ignore all pydocstyle rules in examples folder
@@ -309,7 +308,6 @@ per-file-ignores."tests_isolated/*.py" = [
309308
"SLF", # Ignore all warnings about private or protected member access in test folders
310309
]
311310

312-
313311
[tool.ruff.format]
314312
# Like Black, use double quotes for strings.
315313
quote-style = "preserve"

tests/test_ansi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ def test_clear_line() -> None:
202202

203203
def test_cursor() -> None:
204204
count = 1
205-
assert ansi.Cursor._up(count) == f"{ansi.CSI}{count}A"
206-
assert ansi.Cursor._down(count) == f"{ansi.CSI}{count}B"
207-
assert ansi.Cursor._forward(count) == f"{ansi.CSI}{count}C"
208-
assert ansi.Cursor._back(count) == f"{ansi.CSI}{count}D"
205+
assert ansi.Cursor.UP(count) == f"{ansi.CSI}{count}A"
206+
assert ansi.Cursor.DOWN(count) == f"{ansi.CSI}{count}B"
207+
assert ansi.Cursor.FORWARD(count) == f"{ansi.CSI}{count}C"
208+
assert ansi.Cursor.BACK(count) == f"{ansi.CSI}{count}D"
209209

210210
x = 4
211211
y = 5
212-
assert ansi.Cursor._set_pos(x, y) == f"{ansi.CSI}{y};{x}H"
212+
assert ansi.Cursor.SET_POS(x, y) == f"{ansi.CSI}{y};{x}H"
213213

214214

215215
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)