Skip to content

Commit ecbe66f

Browse files
committed
support plugin search mode with start char
1 parent dcd8f91 commit ecbe66f

File tree

6 files changed

+97
-64
lines changed

6 files changed

+97
-64
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ test_PluginsPy.py PluginExample
6969
<<< end call Plugin run or CmdMaps method
7070
```
7171

72-
## 五、发行PyPi处理流程
72+
## 五、快捷键
73+
74+
* j:选择上一个
75+
* k:选择下一个
76+
* /:进入首字母快速选择模式,边框会变成绿色
77+
* a-z,0-9:跳转到首字母为该字符的插件位置,便于快速选择,目前支持一个字符
78+
79+
## 六、发行PyPi处理流程
7380

7481
* pip3 install twine
7582
* https://pypi.org/
-5.72 KB
Binary file not shown.
-6.07 KB
Binary file not shown.
-6.12 KB
Binary file not shown.

setup.py

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

66
setuptools.setup(
77
name="PluginsPy",
8-
version="0.0.7",
8+
version="0.0.8",
99
author="zengjf",
1010
author_email="zengjf42@163.com",
1111
description="Plugins Framework",

src/PluginsPy/__init__.py

Lines changed: 88 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def _showPlugins(plugins, helpList):
117117
KEY_BOARD_K = 107
118118
KEY_BOARD_Q = 113
119119
KEY_BOARD_H = 104
120+
KEY_BOARD_Search = 47
120121

121122
# 初始化一个窗口
122123
mainScreen = curses.initscr()
@@ -161,6 +162,8 @@ def _showPlugins(plugins, helpList):
161162
topIndex = 0
162163
# 进入Help模式
163164
inHelpStatus = False
165+
# Search模式
166+
inSearchMode = False
164167

165168
_drawPlugins(mainScreen, plugins, topIndex, index, pluginsMaxLen, maxRows, maxCols, FG_GREEN_COLOR)
166169

@@ -172,78 +175,101 @@ def _showPlugins(plugins, helpList):
172175
(maxRows - 2 - 2 + 1) // 2, # 主屏上下边框 + 帮助屏上下边框 + 取整补充1
173176
2 # 主屏左边框 + 左空列
174177
)
175-
178+
176179
while True:
177180
# 等待按键事件
178181
ch = mainScreen.getch()
179-
180-
if ch == curses.KEY_RESIZE or inHelpStatus:
181-
mainScreen.clear()
182-
mainScreen.border(0)
183-
maxRows, maxCols = mainScreen.getmaxyx()
184-
185-
helpScreen.resize(
186-
3, # 上下边框 + 内容
187-
maxCols - 4 # 左右边框 + 左右空列
188-
)
189182

190-
if maxRows < MIN_ROWS:
191-
curses.endwin()
192-
print("terminal rows must more than " + str(MIN_ROWS))
193-
exit(0)
194-
195-
_drawPlugins(mainScreen, plugins, topIndex, index, pluginsMaxLen, maxRows, maxCols, FG_GREEN_COLOR)
196-
197-
inHelpStatus = False
198-
# show help
199-
elif ch == KEY_BOARD_H:
200-
inHelpStatus = True
201-
202-
helpScreen.mvwin(
203-
(maxRows - 2 - 2 + 1) // 2, # 主屏上下边框 + 帮助屏上下边框 + 取整补充1
204-
2 # 主屏左边框 + 左空列
205-
)
206-
helpScreen.clear()
207-
# 主屏左右边框 + 左右空列 + 帮助屏左右边框
208-
helpScreenWidth = maxCols - 4 - 2
209-
if helpScreenWidth > _strWidth(helpList[index]):
210-
helpScreen.addstr(1, (helpScreenWidth) // 2 - _strWidth(helpList[index]) // 2, helpList[index])
183+
if not inSearchMode:
184+
if ch == curses.KEY_RESIZE or inHelpStatus:
185+
mainScreen.clear()
186+
mainScreen.border(0)
187+
maxRows, maxCols = mainScreen.getmaxyx()
188+
189+
helpScreen.resize(
190+
3, # 上下边框 + 内容
191+
maxCols - 4 # 左右边框 + 左右空列
192+
)
193+
194+
if maxRows < MIN_ROWS:
195+
curses.endwin()
196+
print("terminal rows must more than " + str(MIN_ROWS))
197+
exit(0)
198+
199+
_drawPlugins(mainScreen, plugins, topIndex, index, pluginsMaxLen, maxRows, maxCols, FG_GREEN_COLOR)
200+
201+
inHelpStatus = False
202+
# show help
203+
elif ch == KEY_BOARD_H:
204+
inHelpStatus = True
205+
206+
helpScreen.mvwin(
207+
(maxRows - 2 - 2 + 1) // 2, # 主屏上下边框 + 帮助屏上下边框 + 取整补充1
208+
2 # 主屏左边框 + 左空列
209+
)
210+
helpScreen.clear()
211+
# 主屏左右边框 + 左右空列 + 帮助屏左右边框
212+
helpScreenWidth = maxCols - 4 - 2
213+
if helpScreenWidth > _strWidth(helpList[index]):
214+
helpScreen.addstr(1, (helpScreenWidth) // 2 - _strWidth(helpList[index]) // 2, helpList[index])
215+
else:
216+
# 可显示字符区域小于字符串实际宽度,只截取一半显示,以后有需求,把这里改成加上三个点表示省略部分
217+
helpScreen.addstr(1, 1, helpList[index][0:(helpScreenWidth // 2)])
218+
helpScreen.border(0)
219+
helpScreen.refresh()
220+
# 退出按键
221+
elif ch == KEY_BOARD_ESC or ch == KEY_BOARD_Q:
222+
index = -1
223+
break
224+
elif ch == KEY_BOARD_UP or ch == KEY_BOARD_K:
225+
index -= 1
226+
if index <= 0:
227+
index = 0
228+
229+
# 处理上边缘
230+
if topIndex == (index + 1):
231+
topIndex -= 1
232+
233+
mainScreen.clear()
234+
mainScreen.border(0)
235+
_drawPlugins(mainScreen, plugins, topIndex, index, pluginsMaxLen, maxRows, maxCols, FG_GREEN_COLOR)
236+
elif ch == KEY_BOARD_DOWN or ch == KEY_BOARD_J:
237+
index += 1
238+
if index >= len(plugins):
239+
index = len(plugins) - 1
240+
else:
241+
# 处理下边缘
242+
# 上下两个边框占用2行
243+
if (topIndex + (maxRows - 2)) == index :
244+
topIndex += 1
245+
246+
mainScreen.clear()
247+
mainScreen.border(0)
248+
_drawPlugins(mainScreen, plugins, topIndex, index, pluginsMaxLen, maxRows, maxCols, FG_GREEN_COLOR)
249+
elif ch == KEY_BOARD_ENTER:
250+
break
251+
elif ch == KEY_BOARD_Search:
252+
inSearchMode = True
253+
254+
mainScreen.attron(curses.color_pair(FG_GREEN_COLOR))
255+
mainScreen.border(0)
256+
mainScreen.refresh()
257+
mainScreen.attroff(curses.color_pair(FG_GREEN_COLOR))
211258
else:
212-
# 可显示字符区域小于字符串实际宽度,只截取一半显示,以后有需求,把这里改成加上三个点表示省略部分
213-
helpScreen.addstr(1, 1, helpList[index][0:(helpScreenWidth // 2)])
214-
helpScreen.border(0)
215-
helpScreen.refresh()
216-
# 退出按键
217-
elif ch == KEY_BOARD_ESC or ch == KEY_BOARD_Q:
218-
index = -1
219-
break
220-
elif ch == KEY_BOARD_UP or ch == KEY_BOARD_K:
221-
index -= 1
222-
if index <= 0:
223-
index = 0
224-
225-
# 处理上边缘
226-
if topIndex == (index + 1):
227-
topIndex -= 1
259+
pass
260+
# 允许使用首字母进行快速定位选择
261+
elif (ch >= ord("A") and ch <= ord("z")) or (ch >= ord("0") and (ch <= ord("9"))) and inSearchMode:
262+
for i in range(len(plugins)):
263+
if plugins[i].lower().startswith(chr(ch).lower()):
264+
index = i
265+
topIndex = index
266+
break
228267

229268
mainScreen.clear()
230269
mainScreen.border(0)
231270
_drawPlugins(mainScreen, plugins, topIndex, index, pluginsMaxLen, maxRows, maxCols, FG_GREEN_COLOR)
232-
elif ch == KEY_BOARD_DOWN or ch == KEY_BOARD_J:
233-
index += 1
234-
if index >= len(plugins):
235-
index = len(plugins) - 1
236-
else:
237-
# 处理下边缘
238-
# 上下两个边框占用2行
239-
if (topIndex + (maxRows - 2)) == index :
240-
topIndex += 1
241271

242-
mainScreen.clear()
243-
mainScreen.border(0)
244-
_drawPlugins(mainScreen, plugins, topIndex, index, pluginsMaxLen, maxRows, maxCols, FG_GREEN_COLOR)
245-
elif ch == KEY_BOARD_ENTER:
246-
break
272+
inSearchMode = False
247273
else:
248274
pass
249275

0 commit comments

Comments
 (0)