//! focus-tools:内置的文件与 shell 工具集。 //! focus-tools: built-in file and shell tools. //! //! 每个工具都实现 [`focus_core::Tool`]:`read`、`write`、`edit`、`shell`。 //! 全部使用同步 `std` I/O(与 core 的同步 `Tool` trait 一致),并原生支持 //! Windows 与 Linux(路径用 `std::path`,shell 按平台选择)。 //! Each tool implements [`focus_core::Tool`]: `read`, `write`, `edit`, `shell`. //! All use synchronous `std` I/O (consistent with the core's sync `Tool` //! trait) and natively support both Windows and Linux (paths via `std::path`, //! the shell chosen per platform). #![forbid(unsafe_code)] /// pi 风格的精确替换编辑工具。 /// The pi-style exact-replacement edit tool. pub mod edit; /// 读取文件(支持行范围)。 /// File reading (with optional line ranges). pub mod read; /// 平台感知的 shell 执行工具。 /// Platform-aware shell execution tool. pub mod shell; /// 整文件覆盖写入。 /// Whole-file overwrite writing. pub mod write; pub use edit::EditTool; pub use read::ReadTool; pub use shell::ShellTool; pub use write::WriteTool; use std::path::{Path, PathBuf}; /// 把用户提供的路径解析为绝对路径:相对路径基于 `root`,绝对路径原样保留。 /// Resolve a user-supplied path: relative paths are based on `root`, /// absolute paths are kept as-is. pub(crate) fn resolve_path(root: &Path, input: &str) -> PathBuf { let p = Path::new(input); if p.is_absolute() { p.to_path_buf() } else { root.join(p) } }