mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
## Summary - remove protocol and core support for discovering and listing custom prompts - simplify the TUI slash-command flow and command popup to built-in commands only - delete obsolete custom prompt tests, helpers, and docs references - clean up downstream event handling for the removed protocol events
26 lines
1.1 KiB
Rust
26 lines
1.1 KiB
Rust
/// Parse a first-line slash command of the form `/name <rest>`.
|
|
/// Returns `(name, rest_after_name, rest_offset)` if the line begins with `/`
|
|
/// and contains a non-empty name; otherwise returns `None`.
|
|
///
|
|
/// `rest_offset` is the byte index into the original line where `rest_after_name`
|
|
/// starts after trimming leading whitespace (so `line[rest_offset..] == rest_after_name`).
|
|
pub fn parse_slash_name(line: &str) -> Option<(&str, &str, usize)> {
|
|
let stripped = line.strip_prefix('/')?;
|
|
let mut name_end_in_stripped = stripped.len();
|
|
for (idx, ch) in stripped.char_indices() {
|
|
if ch.is_whitespace() {
|
|
name_end_in_stripped = idx;
|
|
break;
|
|
}
|
|
}
|
|
let name = &stripped[..name_end_in_stripped];
|
|
if name.is_empty() {
|
|
return None;
|
|
}
|
|
let rest_untrimmed = &stripped[name_end_in_stripped..];
|
|
let rest = rest_untrimmed.trim_start();
|
|
let rest_start_in_stripped = name_end_in_stripped + (rest_untrimmed.len() - rest.len());
|
|
let rest_offset = rest_start_in_stripped + 1;
|
|
Some((name, rest, rest_offset))
|
|
}
|