Skip to content

Feat improve terminal - #61

Merged
muou000 merged 3 commits into
mainfrom
feat-improve-terminal
Aug 8, 2026
Merged

Feat improve terminal#61
muou000 merged 3 commits into
mainfrom
feat-improve-terminal

Conversation

@muou000

@muou000 muou000 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • 新功能

    • 改进终端输入处理,支持规范/非规范模式、回显、删除、EOF、信号字符及 VMIN/VTIME 语义。
    • 支持通过 ioctl 读取和设置终端窗口大小,并在窗口变化时通知相关进程。
    • 终端信号可发送至前台进程组。
  • 问题修复

    • 标准输入和输出路径正确显示为 /dev/tty
    • 文件状态信息现在返回正确的设备主、次设备号。

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@muou000, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ce8ee722-5782-4869-9ffd-6536869d968c

📥 Commits

Reviewing files that changed from the base of the PR and between 39a329e and 65f3412.

📒 Files selected for processing (1)
  • pulse_core/src/fd_table/tty.rs
📝 Walkthrough

Walkthrough

本次变更将 TTY 输入改为 termios 行规程,增加终端信号、窗口大小和动态设备元数据处理,并更新标准流路径、ioctl、轮询和 statx 行为。

Changes

TTY 行规程与读取流程

Layer / File(s) Summary
termios 输入与读取流程
pulse_core/src/fd_table/tty.rs
TTY 新增规范模式、非规范模式、回显、擦除、EOF、信号字符及 VMIN/VTIME 读取。输入状态统一处理信号发送、数据入队和读者唤醒。测试覆盖行提交、擦除、即时读取和信号字符。
TTY 对象与窗口大小接口
pulse_core/src/fd_table/tty.rs, pulse_syscalls/src/impls/fs/control.rs
stdin、stdout 和 VFS 回调使用统一的 TTY 输入状态。窗口大小通过 read_tty_winsizewrite_tty_winsize 持久化。TIOCGWINSZTIOCSWINSZ 使用共享接口。
标准流路径与设备元数据
pulse_core/src/task/mod.rs, pulse_syscalls/src/impls/fs/meta.rs, pulse_core/src/fd_table/mod.rs
标准输入和标准输出在缺少路径时解析为 /dev/ttysys_statx 根据 st_rdev 填充设备号。移除未使用导入。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InputSource
  participant TtyInputState
  participant ForegroundProcessGroup
  participant StdinObject
  InputSource->>TtyInputState: 处理输入字符
  TtyInputState->>ForegroundProcessGroup: 发送终端信号
  TtyInputState->>StdinObject: 写入可读数据或 EOF
  StdinObject->>TtyInputState: 按 termios、VMIN 和 VTIME 读取
Loading

Possibly related PRs

  • muou000/PulseOS#1:涉及 devfs 字符设备和设备节点注册,与 /dev/tty 及 TTY 设备元数据直接相关。
  • muou000/PulseOS#5:涉及信号排队和传递 API,与 TTY 终端信号处理直接相关。
  • muou000/PulseOS#53:引入异步 VFS 和轮询基础设施,与 TTY 的读取和轮询路径直接相关。

Poem

兔子敲键,行规程醒,
回显擦除都分明。
窗口尺寸存起来,
信号跃入前台组。
/dev/tty 路已通,
胡萝卜旁读得欢。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题明确指出终端功能改进,与本次 TTY、termios、窗口大小和终端信号处理变更一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (4)
pulse_core/src/fd_table/tty.rs (4)

259-273: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

建议在信号字符触发时清空输入缓冲。

当前实现在命中 VINTR/VQUIT/VSUSP 后直接返回,input.canonical 中已缓冲的字符保持不变。POSIX 行为是:如果未设置 NOFLSH,终端在发送信号时刷新输入队列。因此按下 Ctrl+C 后,之前输入的半行内容会在下一次提交时一并交付给应用,与真实终端不一致。

♻️ 建议的修改
         if let Some(signal) = signal {
+            if (termios_data.c_lflag & NOFLSH) == 0 {
+                input.canonical.clear();
+                input.readable.clear();
+            }
             effects.signals.push(signal);
             return effects;
         }

需要在文件顶部的 linux_raw_sys::general 导入中加入 NOFLSH

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pulse_core/src/fd_table/tty.rs` around lines 259 - 273, 在信号字符处理逻辑中检查
termios_data.c_lflag 的 NOFLSH 标志:当 VINTR、VQUIT 或 VSUSP 触发信号且未设置 NOFLSH 时,清空
input.canonical 后再返回 effects;设置 NOFLSH 时保留缓冲内容。同步在 linux_raw_sys::general 导入中加入
NOFLSH。

670-676: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

/dev/tty 查找失败时,fstat(0)/fstat(1) 会失败。

旧实现为 stdin/stdout 返回固定的 stat 值,总是成功。现在如果 devfs 尚未挂载或 /dev/tty 不存在,console_tty_stat 会把错误传播给 fstatsys_statxpulse_core/src/task/mod.rs 中的 fd_path(后者会回退为 /dev/null)。建议在查找失败时回退到一个字符设备形态的合成 stat,保持标准流的 fstat 始终可用。

另外,每次 stat() 都执行一次 lookup_location 路径解析。如果调用频繁,可以缓存该 Location

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pulse_core/src/fd_table/tty.rs` around lines 670 - 676, Update
console_tty_stat to fall back to a synthetic character-device stat when
axfs::lookup_location("/dev/tty") fails, preserving successful fstat behavior
for standard streams even before devfs is mounted; keep the existing
location_to_stat path when lookup succeeds. Do not propagate the lookup error to
fstat/sys_statx or fd_path.

946-977: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

建议补充输入行规程的测试用例。

现有测试覆盖了规范模式的换行提交、擦除,以及非规范模式的即时可读和信号字符。以下分支仍无覆盖,且都属于易出错的逻辑:

  • VEOF:空行时置 eof_pending,非空行时提交当前行。
  • VKILL:清空整行并按 ECHOK 回显换行。
  • map_input_byteICRNLINLCRIGNCR 三种映射。
  • TtyInputState::read_into:EOF 只消费一次的语义。

read_noncanonical_input 的 VMIN/VTIME 组合依赖全局状态与等待队列,难以直接单测。如果把它重构为接受输入状态与等待原语的参数,就可以覆盖。需要我生成这些测试吗?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pulse_core/src/fd_table/tty.rs` around lines 946 - 977, 为输入行规程补充测试,覆盖 VEOF
在空行设置 eof_pending、非空行提交当前行,VKILL 清空整行并在 ECHOK 启用时回显换行,以及 map_input_byte 对
ICRNL、INLCR、IGNCR 的映射;同时验证 TtyInputState::read_into 的 EOF 只被消费一次。围绕
accept_input_byte、map_input_byte 和 read_into 添加用例,暂不重构依赖全局状态的
read_noncanonical_input。

426-433: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

TTY_TERMIOS 的读-改-写未原子化。

第 426 行获取快照后立即释放锁,update_tty_termios 在第 433 行重新加锁。两个并发的 TCSETS 可能互相覆盖字段。可以让 update_tty_termios 接受一个闭包,在单次持锁期间完成修改。影响有限,因为并发设置 termios 很少见。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pulse_core/src/fd_table/tty.rs` around lines 426 - 433, 将 TTY_TERMIOS
的读改写流程改为原子操作:修改 update_tty_termios,使其接受闭包并在同一次持锁期间读取当前
termios、执行字段更新并写回;同步调整当前调用处,避免先通过 TTY_TERMIOS.lock() 获取快照后再单独调用
update_tty_termios,从而防止并发 TCSETS 覆盖彼此的修改。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pulse_core/src/fd_table/tty.rs`:
- Around line 259-273: 在信号字符处理逻辑中检查 termios_data.c_lflag 的 NOFLSH 标志:当
VINTR、VQUIT 或 VSUSP 触发信号且未设置 NOFLSH 时,清空 input.canonical 后再返回 effects;设置 NOFLSH
时保留缓冲内容。同步在 linux_raw_sys::general 导入中加入 NOFLSH。
- Around line 670-676: Update console_tty_stat to fall back to a synthetic
character-device stat when axfs::lookup_location("/dev/tty") fails, preserving
successful fstat behavior for standard streams even before devfs is mounted;
keep the existing location_to_stat path when lookup succeeds. Do not propagate
the lookup error to fstat/sys_statx or fd_path.
- Around line 946-977: 为输入行规程补充测试,覆盖 VEOF 在空行设置 eof_pending、非空行提交当前行,VKILL
清空整行并在 ECHOK 启用时回显换行,以及 map_input_byte 对 ICRNL、INLCR、IGNCR 的映射;同时验证
TtyInputState::read_into 的 EOF 只被消费一次。围绕 accept_input_byte、map_input_byte 和
read_into 添加用例,暂不重构依赖全局状态的 read_noncanonical_input。
- Around line 426-433: 将 TTY_TERMIOS 的读改写流程改为原子操作:修改
update_tty_termios,使其接受闭包并在同一次持锁期间读取当前 termios、执行字段更新并写回;同步调整当前调用处,避免先通过
TTY_TERMIOS.lock() 获取快照后再单独调用 update_tty_termios,从而防止并发 TCSETS 覆盖彼此的修改。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0a16cf15-a837-4eb2-aece-dbff53b72c5b

📥 Commits

Reviewing files that changed from the base of the PR and between e46fc62 and 39a329e.

📒 Files selected for processing (5)
  • pulse_core/src/fd_table/mod.rs
  • pulse_core/src/fd_table/tty.rs
  • pulse_core/src/task/mod.rs
  • pulse_syscalls/src/impls/fs/control.rs
  • pulse_syscalls/src/impls/fs/meta.rs

@muou000
muou000 merged commit aa76bc1 into main Aug 8, 2026
1 check passed
@muou000
muou000 deleted the feat-improve-terminal branch August 8, 2026 14:26
muou000 added a commit that referenced this pull request Aug 11, 2026
* fix(tty): implement console line discipline

* fix(tty): expose terminal identity and window ioctls

* fix(tty): honor signal flush and stdio stat fallback
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.

1 participant