Skip to content

fix(terminal_view): 修复 SSH 连接窗口空行的时间戳占位括号与行号 - #259

Merged
feigeCode merged 3 commits into
mainfrom
fix/terminal-timestamp-placeholder-244
Sep 20, 2026
Merged

feigeCode merged 3 commits into
mainfrom
fix/terminal-timestamp-placeholder-244

Conversation

@feigeCode

Copy link
Copy Markdown
Owner

Closes #244

Description

The per-line margin (timestamps + line numbers, introduced for #220) drew a full-width row for every on-screen line, so lines that had not produced any output yet still got a [ ] timestamp placeholder — and later, an orphan line number under the cursor. In a fresh SSH session that littered the whole window below the cursor.

This PR makes “has this line produced output yet?” the single criterion for the entire margin: a margin row is only rendered for lines that already have a timestamp in the line timeline. Rows without a label become an empty string, and the element already skips empty rows — so neither the placeholder brackets nor the line number is painted.

  • crates/terminal/src/line_timeline.rs: add SharedLineTimeline::labels(first_id, count) — one lock for the whole screen, O(log n + count), and one consistent per-frame snapshot. The single-row label() had no production caller left after the switch, so it was removed rather than kept as a parallel path.
  • crates/terminal_view/src/view/terminal_render.rs: line_margin_row_text returns an empty string when the label is None; build_line_margin now consults the timeline regardless of the timestamp toggle (it previously only queried it when timestamps were enabled, so number-only mode could not detect blank lines at all).

The margin column width is unchanged, so lines that do have output keep exactly the same alignment as before.

Screenshot

Before After
Captured in #244 ([ ] on every empty line) Not attached — needs a quick look in the running app, see below

How to Test

Automated:

cargo test -p terminal --lib line_timeline          # 8 passed
cargo test -p terminal_view --lib view::terminal_render  # 7 passed
cargo test -p terminal --lib                        # 507 passed
cargo test -p terminal_view --lib                   # 566 passed

The behavioural test is margin_blanks_rows_below_the_last_output: it drives a real Term (writes "$ one\r\ntwo\r\n"), then asserts every row below the last output is empty — for the timestamp mode and for the number-only mode. Mutation check: restoring a “render an empty label anyway” path turns that test red (["[] 4 ", "[] 5 ", "[] 6 "]), so the test pins the wiring and not just the pure helper.

Manual (not done by me — please confirm visually):

  1. Open an SSH connection with row timestamps and/or line numbers enabled.
  2. The area below the cursor stays completely clean, including the line-number column.
  3. Lines that have output still show [HH:MM:SS] and/or the line number, aligned exactly as before.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

feigeCode and others added 3 commits September 20, 2026 18:53
左边距为每一屏幕行生成时间戳文本,尚未有输出的行(光标下方的空行)
此前会画出 `[          ]` 占位括号,整屏空行看起来全是括号和空白。

改为没有时间戳时不画占位符:只显示行号时补足时间戳列宽的空白以保证
行号对齐,时间戳与行号都不显示时该行留空,由元素侧跳过绘制。列宽与
行号对齐行为不变。

Refs #244
左边距改为以“该行是否已有输出”为唯一判定:时间线里没有这一行的时间戳,
说明它还没有任何输出(光标下方的空行),此时整行留空——既不画时间戳
占位括号,也不显示行号。

原来只有显示时间戳时才查时间线,行号列会无条件铺满整屏,空行上挂着
一串孤立的行号。现在两列共用同一个判定。

行时间轴新增一次加锁的按行批量查询 `labels`,视图整帧只加锁一次、不做
逐行查询;原先仅服务视图逐行查询的单行 `label` 已无生产调用方,一并移除,
只保留批量这一条查找路径。

Refs #244
@feigeCode
feigeCode merged commit 6f0692a into main Sep 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: ssh连接窗口内每行行首输出的时间戳展示优化

1 participant