修复 TUI 界面闪烁问题
- 移除 clear() 调用,避免瞬间清空屏幕 - 添加 _clear_line() 辅助方法,逐行清除残留内容 - 每个面板在写入前先清空对应行,确保无残留字符
This commit is contained in:
+21
-1
@@ -135,7 +135,6 @@ class TuiApp:
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
self.height, self.width = self.stdscr.getmaxyx()
|
self.height, self.width = self.stdscr.getmaxyx()
|
||||||
self.stdscr.clear()
|
|
||||||
self._draw()
|
self._draw()
|
||||||
self.stdscr.refresh()
|
self.stdscr.refresh()
|
||||||
|
|
||||||
@@ -224,6 +223,14 @@ class TuiApp:
|
|||||||
y = self._draw_status_panel(y)
|
y = self._draw_status_panel(y)
|
||||||
self._draw_bottombar()
|
self._draw_bottombar()
|
||||||
|
|
||||||
|
def _clear_line(self, y: int):
|
||||||
|
"""清空指定行,防止残留内容。"""
|
||||||
|
if 0 <= y < self.height:
|
||||||
|
try:
|
||||||
|
self.stdscr.addstr(y, 0, " " * self.width)
|
||||||
|
except curses.error:
|
||||||
|
pass
|
||||||
|
|
||||||
def _draw_titlebar(self):
|
def _draw_titlebar(self):
|
||||||
h, w = self.height, self.width
|
h, w = self.height, self.width
|
||||||
title = " padsleep 配置工具 "
|
title = " padsleep 配置工具 "
|
||||||
@@ -258,6 +265,7 @@ class TuiApp:
|
|||||||
periods = (self.config or {}).get("screen_on_periods", [])
|
periods = (self.config or {}).get("screen_on_periods", [])
|
||||||
if not periods:
|
if not periods:
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "(暂无时间段 — 按 A 新增)")
|
self.stdscr.addstr(y, 4, "(暂无时间段 — 按 A 新增)")
|
||||||
except curses.error:
|
except curses.error:
|
||||||
@@ -266,6 +274,7 @@ class TuiApp:
|
|||||||
else:
|
else:
|
||||||
# 表头
|
# 表头
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, " # │ 开始 │ 结束 │", curses.A_UNDERLINE)
|
self.stdscr.addstr(y, 4, " # │ 开始 │ 结束 │", curses.A_UNDERLINE)
|
||||||
except curses.error:
|
except curses.error:
|
||||||
@@ -274,6 +283,7 @@ class TuiApp:
|
|||||||
for i, p in enumerate(periods):
|
for i, p in enumerate(periods):
|
||||||
if y >= h:
|
if y >= h:
|
||||||
break
|
break
|
||||||
|
self._clear_line(y)
|
||||||
sel = "▸" if i == self.selected else " "
|
sel = "▸" if i == self.selected else " "
|
||||||
line = f"{sel}{i+1:>2} │ {p['start']} │ {p['end']} "
|
line = f"{sel}{i+1:>2} │ {p['start']} │ {p['end']} "
|
||||||
try:
|
try:
|
||||||
@@ -286,6 +296,7 @@ class TuiApp:
|
|||||||
y += 1
|
y += 1
|
||||||
|
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "[A]新增 [E]编辑 [D]删除 ↑↓选择", curses.A_DIM)
|
self.stdscr.addstr(y, 4, "[A]新增 [E]编辑 [D]删除 ↑↓选择", curses.A_DIM)
|
||||||
except curses.error:
|
except curses.error:
|
||||||
@@ -298,6 +309,7 @@ class TuiApp:
|
|||||||
|
|
||||||
if self.status:
|
if self.status:
|
||||||
dev = self.status.get("device") or "未选择"
|
dev = self.status.get("device") or "未选择"
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, f"当前设备: {dev}")
|
self.stdscr.addstr(y, 4, f"当前设备: {dev}")
|
||||||
except curses.error:
|
except curses.error:
|
||||||
@@ -308,6 +320,7 @@ class TuiApp:
|
|||||||
for d in self.devices:
|
for d in self.devices:
|
||||||
if y >= h:
|
if y >= h:
|
||||||
break
|
break
|
||||||
|
self._clear_line(y)
|
||||||
icon = "✓" if d["status"] == "device" else "✗"
|
icon = "✓" if d["status"] == "device" else "✗"
|
||||||
pair = 3 if d["status"] == "device" else 2
|
pair = 3 if d["status"] == "device" else 2
|
||||||
try:
|
try:
|
||||||
@@ -318,6 +331,7 @@ class TuiApp:
|
|||||||
y += 1
|
y += 1
|
||||||
else:
|
else:
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "(无设备 — 请连接平板)")
|
self.stdscr.addstr(y, 4, "(无设备 — 请连接平板)")
|
||||||
except curses.error:
|
except curses.error:
|
||||||
@@ -325,6 +339,7 @@ class TuiApp:
|
|||||||
y += 1
|
y += 1
|
||||||
|
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "[S]选择设备 [R]刷新", curses.A_DIM)
|
self.stdscr.addstr(y, 4, "[S]选择设备 [R]刷新", curses.A_DIM)
|
||||||
except curses.error:
|
except curses.error:
|
||||||
@@ -348,6 +363,7 @@ class TuiApp:
|
|||||||
wf = s.get("wakefulness", "?")
|
wf = s.get("wakefulness", "?")
|
||||||
|
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "屏幕: ")
|
self.stdscr.addstr(y, 4, "屏幕: ")
|
||||||
self.stdscr.addstr(f"{sc}", curses.color_pair(sc_color) | curses.A_BOLD)
|
self.stdscr.addstr(f"{sc}", curses.color_pair(sc_color) | curses.A_BOLD)
|
||||||
@@ -356,6 +372,7 @@ class TuiApp:
|
|||||||
pass
|
pass
|
||||||
y += 1
|
y += 1
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "时段内: ")
|
self.stdscr.addstr(y, 4, "时段内: ")
|
||||||
self.stdscr.addstr(f"{wp}", curses.color_pair(wp_color) | curses.A_BOLD)
|
self.stdscr.addstr(f"{wp}", curses.color_pair(wp_color) | curses.A_BOLD)
|
||||||
@@ -364,6 +381,7 @@ class TuiApp:
|
|||||||
pass
|
pass
|
||||||
y += 1
|
y += 1
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "ADB: ")
|
self.stdscr.addstr(y, 4, "ADB: ")
|
||||||
self.stdscr.addstr(f"{ar}", curses.color_pair(ar_color) | curses.A_BOLD)
|
self.stdscr.addstr(f"{ar}", curses.color_pair(ar_color) | curses.A_BOLD)
|
||||||
@@ -372,6 +390,7 @@ class TuiApp:
|
|||||||
y += 1
|
y += 1
|
||||||
else:
|
else:
|
||||||
if y < h:
|
if y < h:
|
||||||
|
self._clear_line(y)
|
||||||
try:
|
try:
|
||||||
self.stdscr.addstr(y, 4, "(未连接守护进程 — 按 T 重连)")
|
self.stdscr.addstr(y, 4, "(未连接守护进程 — 按 T 重连)")
|
||||||
except curses.error:
|
except curses.error:
|
||||||
@@ -398,6 +417,7 @@ class TuiApp:
|
|||||||
bar_y += 1
|
bar_y += 1
|
||||||
if bar_y >= h:
|
if bar_y >= h:
|
||||||
return
|
return
|
||||||
|
self._clear_line(bar_y)
|
||||||
msg = self.message
|
msg = self.message
|
||||||
if msg and time.time() - self.msg_time < 5:
|
if msg and time.time() - self.msg_time < 5:
|
||||||
pass # show message below separator
|
pass # show message below separator
|
||||||
|
|||||||
Reference in New Issue
Block a user