diff --git a/padsleep_tui.py b/padsleep_tui.py index 8e4f117..1e508f1 100644 --- a/padsleep_tui.py +++ b/padsleep_tui.py @@ -135,7 +135,6 @@ class TuiApp: while True: self.height, self.width = self.stdscr.getmaxyx() - self.stdscr.clear() self._draw() self.stdscr.refresh() @@ -224,6 +223,14 @@ class TuiApp: y = self._draw_status_panel(y) 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): h, w = self.height, self.width title = " padsleep 配置工具 " @@ -258,6 +265,7 @@ class TuiApp: periods = (self.config or {}).get("screen_on_periods", []) if not periods: if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "(暂无时间段 — 按 A 新增)") except curses.error: @@ -266,6 +274,7 @@ class TuiApp: else: # 表头 if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, " # │ 开始 │ 结束 │", curses.A_UNDERLINE) except curses.error: @@ -274,6 +283,7 @@ class TuiApp: for i, p in enumerate(periods): if y >= h: break + self._clear_line(y) sel = "▸" if i == self.selected else " " line = f"{sel}{i+1:>2} │ {p['start']} │ {p['end']} " try: @@ -286,6 +296,7 @@ class TuiApp: y += 1 if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "[A]新增 [E]编辑 [D]删除 ↑↓选择", curses.A_DIM) except curses.error: @@ -298,6 +309,7 @@ class TuiApp: if self.status: dev = self.status.get("device") or "未选择" + self._clear_line(y) try: self.stdscr.addstr(y, 4, f"当前设备: {dev}") except curses.error: @@ -308,6 +320,7 @@ class TuiApp: for d in self.devices: if y >= h: break + self._clear_line(y) icon = "✓" if d["status"] == "device" else "✗" pair = 3 if d["status"] == "device" else 2 try: @@ -318,6 +331,7 @@ class TuiApp: y += 1 else: if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "(无设备 — 请连接平板)") except curses.error: @@ -325,6 +339,7 @@ class TuiApp: y += 1 if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "[S]选择设备 [R]刷新", curses.A_DIM) except curses.error: @@ -348,6 +363,7 @@ class TuiApp: wf = s.get("wakefulness", "?") if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "屏幕: ") self.stdscr.addstr(f"{sc}", curses.color_pair(sc_color) | curses.A_BOLD) @@ -356,6 +372,7 @@ class TuiApp: pass y += 1 if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "时段内: ") self.stdscr.addstr(f"{wp}", curses.color_pair(wp_color) | curses.A_BOLD) @@ -364,6 +381,7 @@ class TuiApp: pass y += 1 if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "ADB: ") self.stdscr.addstr(f"{ar}", curses.color_pair(ar_color) | curses.A_BOLD) @@ -372,6 +390,7 @@ class TuiApp: y += 1 else: if y < h: + self._clear_line(y) try: self.stdscr.addstr(y, 4, "(未连接守护进程 — 按 T 重连)") except curses.error: @@ -398,6 +417,7 @@ class TuiApp: bar_y += 1 if bar_y >= h: return + self._clear_line(bar_y) msg = self.message if msg and time.time() - self.msg_time < 5: pass # show message below separator