docs(comments): rewrite comments across all crates to the guidelines
Sweep every first-party crate source (1956 .rs files) to the project comment guidelines: delete redundant restatements, decorative banners, change narration, and end-of-line comments; keep and tighten the crucial ones (invariants, bug rationale, SAFETY blocks, ported-source attribution). No functional code changed. Every edit is proven comment-only against the prior tree by a comment-stripping lexer (string/char/raw-string aware) plus a separate doctest-fence check. Where removing a comment made rustfmt or clippy want to re-lay-out adjacent code, the minimal triggering comment is restored so code tokens stay byte-identical. Gates green: cargo fmt --all --check (0 diffs), cargo check and cargo clippy --workspace --all-targets (0 warnings). Adds scripts/check_codegen_comment_guidelines.py — the enforcement gate for these guidelines (flags banners, end-of-line comments, change narration, and commented-out code).
This commit is contained in:
@@ -45,7 +45,8 @@ fn parse_to_events(input: &str) -> Result<Vec<KeyEvent>> {
|
||||
// Try to parse a special key notation.
|
||||
let start_pos: String = chars.clone().collect();
|
||||
if let Some(end) = start_pos.find('>') {
|
||||
let notation = &start_pos[1..end]; // between < and >
|
||||
// between < and >
|
||||
let notation = &start_pos[1..end];
|
||||
// Consume chars including the >.
|
||||
for _ in 0..=end {
|
||||
chars.next();
|
||||
|
||||
@@ -10,15 +10,10 @@ use portable_pty::{CommandBuilder, MasterPty, PtySize, native_pty_system};
|
||||
/// Configuration for spawning a PTY session.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PtyConfig {
|
||||
/// Command and arguments to run.
|
||||
pub command: Vec<String>,
|
||||
/// Terminal width in columns.
|
||||
pub cols: u16,
|
||||
/// Terminal height in rows.
|
||||
pub rows: u16,
|
||||
/// Working directory.
|
||||
pub cwd: Option<PathBuf>,
|
||||
/// Additional environment variables.
|
||||
pub env: HashMap<String, String>,
|
||||
}
|
||||
|
||||
@@ -60,30 +55,25 @@ pub struct PtyChild {
|
||||
}
|
||||
|
||||
impl PtyChild {
|
||||
/// Check if the child process is still alive.
|
||||
pub fn is_alive(&mut self) -> bool {
|
||||
self.child.try_wait().ok().flatten().is_none()
|
||||
}
|
||||
|
||||
/// Get the child process ID.
|
||||
pub fn pid(&self) -> Option<u32> {
|
||||
self.child.process_id()
|
||||
}
|
||||
|
||||
/// Wait for the child to exit and return the exit code.
|
||||
pub fn wait(&mut self) -> Result<u32> {
|
||||
let status = self.child.wait().context("failed to wait for child")?;
|
||||
Ok(status.exit_code())
|
||||
}
|
||||
|
||||
/// Kill the child process.
|
||||
pub fn kill(&mut self) -> Result<()> {
|
||||
self.child.kill().context("failed to kill child process")
|
||||
}
|
||||
}
|
||||
|
||||
impl PtyHandle {
|
||||
/// Spawn a new process in a PTY.
|
||||
pub fn spawn(config: &PtyConfig) -> Result<Self> {
|
||||
let pty_system = native_pty_system();
|
||||
|
||||
@@ -106,7 +96,6 @@ impl PtyHandle {
|
||||
for (key, value) in &config.env {
|
||||
cmd.env(key, value);
|
||||
}
|
||||
// Set TERM for proper terminal detection.
|
||||
cmd.env("TERM", "xterm-256color");
|
||||
cmd.env("COLORTERM", "truecolor");
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ pub struct WaitParams {
|
||||
pub regex: Option<String>,
|
||||
/// Wait until this text is absent from the screen.
|
||||
pub gone: Option<String>,
|
||||
/// Wait until the grid has been unchanged for this many milliseconds.
|
||||
/// Wait until the grid has been `unchanged` for this many milliseconds.
|
||||
pub stable_ms: Option<u64>,
|
||||
/// Timeout in milliseconds (default 10000, capped at 120000).
|
||||
pub timeout_ms: Option<u64>,
|
||||
@@ -265,7 +265,7 @@ async fn handle_stop(State(state): State<AppState>) -> Json<serde_json::Value> {
|
||||
Json(serde_json::json!({"ok": true}))
|
||||
}
|
||||
|
||||
// -- Scrollback --
|
||||
// Scrollback
|
||||
|
||||
async fn handle_scrollback(
|
||||
State(state): State<AppState>,
|
||||
@@ -280,7 +280,7 @@ async fn handle_scrollback(
|
||||
}))
|
||||
}
|
||||
|
||||
// -- WebSocket streaming --
|
||||
// WebSocket streaming
|
||||
|
||||
/// Upgrade an HTTP request to a WebSocket connection.
|
||||
async fn handle_ws_upgrade(
|
||||
|
||||
@@ -102,7 +102,7 @@ impl PtySession {
|
||||
let alive = Arc::new(AtomicBool::new(true));
|
||||
let exit_code: Arc<std::sync::Mutex<Option<u32>>> = Arc::new(std::sync::Mutex::new(None));
|
||||
|
||||
// --- PTY Reader Thread (blocking) ---
|
||||
// PTY Reader Thread (blocking)
|
||||
let alive_reader = alive.clone();
|
||||
std::thread::Builder::new()
|
||||
.name("pty-reader".into())
|
||||
@@ -128,7 +128,7 @@ impl PtySession {
|
||||
})
|
||||
.context("failed to spawn PTY reader thread")?;
|
||||
|
||||
// --- PTY Writer Task (async) ---
|
||||
// PTY Writer Task (async)
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
tokio::select! {
|
||||
@@ -151,7 +151,7 @@ impl PtySession {
|
||||
}
|
||||
});
|
||||
|
||||
// --- Terminal Feeder Task (async) ---
|
||||
// Terminal Feeder Task (async)
|
||||
let terminal_feeder = terminal.clone();
|
||||
let output_tx_feeder = output_tx.clone();
|
||||
let raw_tail_feeder = raw_tail.clone();
|
||||
@@ -172,7 +172,7 @@ impl PtySession {
|
||||
}
|
||||
});
|
||||
|
||||
// --- Child Process Waiter ---
|
||||
// Child Process Waiter
|
||||
let alive_waiter = alive.clone();
|
||||
let exit_code_waiter = exit_code.clone();
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -91,7 +91,6 @@ pub struct TerminalModes {
|
||||
pub origin: bool,
|
||||
/// Cursor is visible.
|
||||
pub show_cursor: bool,
|
||||
/// Insert mode.
|
||||
pub insert: bool,
|
||||
/// LF/NL mode (linefeed also does carriage return).
|
||||
pub linefeed_newline: bool,
|
||||
|
||||
Reference in New Issue
Block a user