Skip to content

Commit 78d00db

Browse files
committed
build(inquirer_console): 更新项目版本号
- 将 pyproject.toml 文件中的版本号从 1.0.5 修改为 1.0.6 - 此更新统一了项目的版本号,确保版本一致性
1 parent 6e11e00 commit 78d00db

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

inquirer_console/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
inquirer = Inquirer()
4242
inquirer.register_prompt('input', Input)
4343
inquirer.register_prompt('confirm', Confirm)
44-
inquirer.register_prompt('list', Select)
44+
inquirer.register_prompt('select', Select)
4545
inquirer.register_prompt('checkbox', Checkbox)
4646
inquirer.register_prompt('password', Password)
4747
inquirer.register_prompt('text', Text)

inquirer_console/prompts/select.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@ class Select(BasePrompt[Any]):
3838
print(f"你选择了: {favorite_lang}")
3939
```
4040
"""
41-
42-
def __init__(self, message: str, choices: List[Union[str, Dict[str, Any]]],
43-
default: Optional[Any] = None,
44-
validate: Optional[Callable[[Any], Union[bool, str]]] = None,
45-
**kwargs):
41+
42+
def __init__(
43+
self,
44+
message: str,
45+
choices: List[Union[str, Dict[str, Any]]],
46+
default: Optional[Any] = None,
47+
validate: Optional[Callable[[Any], Union[bool, str]]] = None,
48+
**kwargs
49+
):
4650
"""
4751
初始化列表选择提示。
4852
"""
4953
super().__init__(message, default=default, **kwargs)
5054
self.validate = validate
51-
55+
5256
# 标准化选项列表
5357
self.choices = []
5458
for i, choice in enumerate(choices):
@@ -60,16 +64,16 @@ def __init__(self, message: str, choices: List[Union[str, Dict[str, Any]]],
6064
if 'value' not in choice:
6165
choice['value'] = choice['name']
6266
self.choices.append(choice)
63-
67+
6468
# 找到默认选项的索引
6569
self.selected_index = 0
6670
if default is not None:
6771
for i, choice in enumerate(self.choices):
6872
if (isinstance(default, int) and i == default) or \
69-
choice['value'] == default:
73+
choice['value'] == default:
7074
self.selected_index = i
7175
break
72-
76+
7377
def _clear_screen(self, num_lines: int):
7478
"""
7579
清除屏幕上的指定行数。
@@ -82,19 +86,19 @@ def _clear_screen(self, num_lines: int):
8286
sys.stdout.write("\033[K\033[A") # 清除当前行并上移一行
8387
sys.stdout.write("\033[K") # 清除最后一行
8488
sys.stdout.flush()
85-
89+
8690
def _render_choices(self):
8791
"""渲染选项列表。"""
8892
# 先显示提示信息
8993
sys.stdout.write(f"{self.message}\n")
90-
94+
9195
# 显示选项列表
9296
for i, choice in enumerate(self.choices):
9397
prefix = ">" if i == self.selected_index else " "
9498
sys.stdout.write(f"{prefix} {choice['name']}\n")
95-
99+
96100
sys.stdout.flush()
97-
101+
98102
def _prompt(self) -> Any:
99103
"""
100104
执行提示并返回用户选择的选项值。
@@ -104,32 +108,32 @@ def _prompt(self) -> Any:
104108
"""
105109
# 渲染初始选项列表
106110
self._render_choices()
107-
111+
108112
while True:
109113
key = get_key()
110-
114+
111115
if key == 'UP' and self.selected_index > 0:
112116
# 清除当前渲染
113117
self._clear_screen(len(self.choices) + 1)
114-
118+
115119
# 更新选中项并重新渲染
116120
self.selected_index -= 1
117121
self._render_choices()
118-
122+
119123
elif key == 'DOWN' and self.selected_index < len(self.choices) - 1:
120124
# 清除当前渲染
121125
self._clear_screen(len(self.choices) + 1)
122-
126+
123127
# 更新选中项并重新渲染
124128
self.selected_index += 1
125129
self._render_choices()
126-
130+
127131
elif key in ('\r', '\n'): # Enter键
128132
# 清除当前渲染
129133
self._clear_screen(len(self.choices) + 1)
130-
134+
131135
selected_value = self.choices[self.selected_index]['value']
132-
136+
133137
# 验证选择
134138
if self.validate:
135139
try:
@@ -147,12 +151,12 @@ def _prompt(self) -> Any:
147151
# 重新渲染选项列表
148152
self._render_choices()
149153
continue
150-
154+
151155
# 显示最终选择
152156
sys.stdout.write(f"{self.message} {self.choices[self.selected_index]['name']}\n")
153157
sys.stdout.flush()
154-
158+
155159
return selected_value
156-
160+
157161
# 为了避免CPU使用率过高,加入短暂的延迟
158-
time.sleep(0.1)
162+
time.sleep(0.1)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "inquirer_console"
33

4-
version = "1.0.5"
4+
version = "1.0.6"
55

66
description = "Elegant interactive command-line interface tool library, Python implementation of Inquirer.js"
77

0 commit comments

Comments
 (0)