Skip to content

Commit ce224e0

Browse files
committed
Fix issue with line clearing on Windows
1 parent 6bad455 commit ce224e0

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

pyckify/utils.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
import sys
2+
import os
3+
import platform
24

35
def clear_previous_lines(num_lines: int):
4-
"""Clear previous lines more reliably by moving cursor up and clearing each line"""
5-
sys.stdout.write(f'\033[{num_lines}F') # Move cursor up n lines
6-
for _ in range(num_lines):
7-
sys.stdout.write('\033[K') # Clear current line
8-
sys.stdout.write('\033[1E') # Move to next line
9-
sys.stdout.write(f'\033[{num_lines}F') # Move cursor back up
6+
"""Clear previous lines with Windows CMD compatibility"""
7+
if platform.system() == "Windows":
8+
# For Windows, use a more compatible approach
9+
try:
10+
# Enable ANSI escape sequences on Windows 10+
11+
import ctypes
12+
kernel32 = ctypes.windll.kernel32
13+
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
14+
15+
# Move cursor up and clear lines
16+
for i in range(num_lines):
17+
sys.stdout.write('\033[1A') # Move cursor up one line
18+
sys.stdout.write('\033[2K') # Clear entire line
19+
sys.stdout.flush()
20+
21+
except:
22+
# Fallback for older Windows or if ctypes fails
23+
# Simply print enough newlines to push content up
24+
os.system('cls' if os.name == 'nt' else 'clear')
25+
else:
26+
# Unix/Linux/Mac - original approach should work
27+
sys.stdout.write(f'\033[{num_lines}A') # Move cursor up n lines
28+
for _ in range(num_lines):
29+
sys.stdout.write('\033[2K') # Clear entire line
30+
sys.stdout.write('\033[1B') # Move cursor down one line
31+
sys.stdout.write(f'\033[{num_lines}A') # Move cursor back up
32+
sys.stdout.flush()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyckify"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "A modern interactive terminal picker for creating interactive command-line selection interfaces"
55
authors = ["ReiDoBrega <pedro94782079@gmail.com>"]
66
license = "MIT"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="pyckify",
8-
version="0.1.0",
8+
version="0.1.2",
99
author="ReiDoBrega",
1010
author_email="pedro94782079@gmail.com",
1111
description="A modern interactive terminal picker for creating interactive command-line selection interfaces",

0 commit comments

Comments
 (0)