zsh/extensions/bash_complete.rs
1//! Rust-original types for the bash-style `complete` builtin extension.
2//!
3//! These types back the `complete` / `compopt` / `compgen` builtins
4//! that `src/extensions/ext_builtins.rs` exposes. They are NOT ports
5//! of any zsh C source — zsh's native `compdef` / `compctl` / `compsys`
6//! uses completely different types (`Cmatch` at comp_h.rs:334,
7//! `Cmgroup` at comp_h.rs:269, `Compctl` at compctl_h.rs:198).
8//!
9//! Previous home was `src/ported/zle/computil.rs` which violated the
10//! "no Rust-only types in ported files" invariant; moved here so the
11//! ported zle/ tree stays a faithful C-source mirror.
12
13/// `complete` builtin per-command spec (bash-style).
14#[derive(Debug, Clone, Default)]
15pub struct CompSpec {
16 pub actions: Vec<String>, // -a, -b, -c, etc.
17 pub wordlist: Option<String>, // -W wordlist
18 pub function: Option<String>, // -F function
19 pub command: Option<String>, // -C command
20 pub globpat: Option<String>, // -G glob
21 pub prefix: Option<String>, // -P prefix
22 pub suffix: Option<String>, // -S suffix
23}
24
25/// One completion-match candidate surfaced by the `complete` builtin.
26#[derive(Debug, Clone, Default)]
27pub struct CompMatch {
28 pub word: String, // The actual completion word
29 pub display: Option<String>, // Display string (-d)
30 pub prefix: Option<String>, // -P prefix (inserted but not part of match)
31 pub suffix: Option<String>, // -S suffix (inserted but not part of match)
32 pub hidden_prefix: Option<String>, // -p hidden prefix
33 pub hidden_suffix: Option<String>, // -s hidden suffix
34 pub ignored_prefix: Option<String>, // -i ignored prefix
35 pub ignored_suffix: Option<String>, // -I ignored suffix
36 pub group: Option<String>, // -J/-V group name
37 pub description: Option<String>, // -X explanation
38 pub remove_suffix: Option<String>, // -r remove chars
39 pub file_match: bool, // -f flag
40 pub quote_match: bool, // -q flag
41}
42
43/// Completion group bundling multiple match candidates.
44#[derive(Debug, Clone, Default)]
45pub struct CompGroup {
46 pub name: String,
47 pub matches: Vec<CompMatch>,
48 pub explanation: Option<String>,
49 pub sorted: bool,
50}
51
52/// Per-completion state tracked across `complete` builtin invocations.
53#[derive(Debug, Clone, Default)]
54pub struct CompState {
55 pub context: String, // completion context
56 pub exact: String, // exact match handling
57 pub exact_string: String, // the exact string if matched
58 pub ignored: i32, // number of ignored matches
59 pub insert: String, // what to insert
60 pub insert_positions: String, // cursor positions after insert
61 pub last_prompt: String, // whether to return to last prompt
62 pub list: String, // listing style
63 pub list_lines: i32, // number of lines for listing
64 pub list_max: i32, // max matches to list
65 pub nmatches: i32, // number of matches
66 pub old_insert: String, // previous insert value
67 pub old_list: String, // previous list value
68 pub parameter: String, // parameter being completed
69 pub pattern_insert: String, // pattern insert mode
70 pub matchpat: String, // pattern matching mode
71 pub bslashquote: String, // quoting type
72 pub quoting: String, // current quoting
73 pub redirect: String, // redirection type
74 pub restore: String, // restore mode
75 pub to_end: String, // move to end mode
76 pub unambiguous: String, // unambiguous prefix
77 pub unambiguous_cursor: i32, // cursor pos in unambiguous
78 pub unambiguous_positions: String, // positions in unambiguous
79 pub vared: String, // vared context
80}