1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//! p10k transient prompt — port of the `POWERLEVEL9K_TRANSIENT_PROMPT`
//! machinery: the option declaration (p10k.zsh:7214-7215), the
//! `_p9k_transient_prompt` string construction (p10k.zsh:8313-8335)
//! and the condense decision inside `_p9k_on_widget_zle-line-finish`
//! (p10k.zsh:7623-7658).
//!
//! This file is PURE config + render — it wires no hook.
//!
//! # Integration contract (for the accept-line / zle-line-finish site)
//!
//! What zsh p10k does at line finish (p10k:7634-7653): when a transient
//! prompt is configured and the condense condition holds, it runs
//! `RPROMPT= PROMPT=$_p9k_transient_prompt _p9k_reset_prompt` — i.e.
//! `zle .reset-prompt` repaints the WHOLE just-accepted prompt block
//! (every PROMPT line plus the right prompt, not just the last line)
//! with the one-line transient string; the accepted command text stays
//! on that line and command output begins below it.
//!
//! The native site must therefore, at accept time and BEFORE any
//! command output:
//!
//! 1. `let Some(mode) = transient_enabled() else { return }` —
//! engine active and mode != off (p10k:7634 `-n $_p9k_transient_prompt`).
//! 2. `should_condense(&recorded_pwd, &cwd, mode)` where `recorded_pwd`
//! is the integration's own `_p9k__last_prompt_pwd` slot
//! (p10k:7180, starts empty → first accept never condenses under
//! same-dir). When it returns FALSE under SameDir, store `cwd` into
//! the slot (p10k:7639 `_p9k__last_prompt_pwd=$_p9k__cwd`); when it
//! returns TRUE the slot is left untouched (p10k:7636-7637 only set
//! `optimized=1`, no pwd write).
//! 3. On TRUE: `let (left, right) = render_transient();` — `right` is
//! always "" (p10k:7653 `RPROMPT=`). Repaint in place: the previous
//! live refresh left the cursor on the prompt's LAST physical row
//! and recorded the block height in
//! `crate::ported::zle::zle_refresh::LAST_PAINT_ROWS`
//! (zle_refresh.rs:4998, stored at zle_refresh.rs:1247). Move the
//! cursor up `LAST_PAINT_ROWS - 1` rows, `\r`, clear to end of
//! screen (`\x1b[J`), then print the prompt-expanded `left` followed
//! by the accepted buffer — exactly the repaint-anchor dance the
//! live refresh does at zle_refresh.rs:1242-1247, with `left` in
//! place of PROMPT.
//! 4. Reentrancy: p10k:7625 guards with `_p9k__line_finished` so a
//! second line-finish for the same line is a no-op — the integration
//! needs the same one-shot latch per accepted line (send-break also
//! funnels here, p10k:7660-7662).
use crate;
use crategetsparam;
use Path;
/// p10k:7214-7215 — `_p9k_declare -s POWERLEVEL9K_TRANSIENT_PROMPT off`
/// validated against `(off|always|same-dir)`; anything else falls back
/// to `off`.
/// p10k:7215 — `[[ $_POWERLEVEL9K_TRANSIENT_PROMPT == (off|always|same-dir) ]]
/// || _POWERLEVEL9K_TRANSIENT_PROMPT=off`: exact-string match, invalid
/// and unset both mean off. Pure so the parse is testable without the
/// global engine flag.
/// Read `POWERLEVEL9K_TRANSIENT_PROMPT` from the live paramtab.
/// `None` = transient prompt disabled (mode off / invalid / engine not
/// active — with the engine off `_p9k_transient_prompt` was never
/// built, matching p10k:7634's `-n $_p9k_transient_prompt` gate).
/// Condense decision of `_p9k_on_widget_zle-line-finish`
/// (p10k:7635 — `[[ $_POWERLEVEL9K_TRANSIENT_PROMPT == always ||
/// $_p9k__cwd == $_p9k__last_prompt_pwd ]]`).
///
/// `pwd_at_accept` is the caller's `_p9k__last_prompt_pwd` slot (the
/// cwd recorded at the previous NON-condensed accept; p10k:7180 —
/// starts empty, so pass e.g. `Path::new("")` before the first accept),
/// `pwd_now` is `_p9k__cwd` at this accept. On a `false` result under
/// [`TransientMode::SameDir`] the caller must record `pwd_now` into its
/// slot (p10k:7639); on `true` the slot stays untouched (p10k:7636-7637).
/// p10k:532-541 (`_p9k_translate_color`) — minimal local translation:
/// decimal codes are zero-padded to 3 digits (p10k:534
/// `${(l.3..0.)1}`), `#hex` is lowercased (p10k:536); everything else
/// passes through unchanged. The full `__p9k_colors` name table lives
/// privately in render.rs; prompt_char foregrounds are numeric in
/// every stock config (76/196), and the zsh prompt expander resolves
/// basic color NAMES in `%F{...}` natively, so the table is not
/// duplicated here.
/// One `%(?...)` branch of the transient string (p10k:8316-8328): the
/// prompt_char foreground for the given state + the glyph.
///
/// p10k:8316/8323 — `_p9k_color prompt_prompt_char_<STATE> FOREGROUND
/// 76|196` then `_p9k_foreground` (`%F{c}`, or `%f` when the resolved
/// color is empty — p10k:590-595).
///
/// p10k:8319/8326 — content is `${${P9K_CONTENT::="❯"}+}` (assign, emit
/// nothing) followed by the CONTENT_EXPANSION param (default
/// `'${P9K_CONTENT}'`, p10k:8320/8327) wrapped in `${:-"..."}`. Same
/// phase-1 CONTENT_EXPANSION policy as render.rs: default passthrough
/// → the glyph, empty → hide; any other custom zsh expansion is logged
/// and rendered as the default glyph.
/// Build the condensed prompt pair `(PROMPT, RPROMPT)` — port of the
/// `_p9k_transient_prompt` construction (p10k:8313-8335) evaluated
/// eagerly.
///
/// The zsh string is
/// `%b%k%s%u%(?<sep><OK branch><sep><ERROR branch>)%b%k%f%s%u ` — a
/// runtime `%(?...)` ternary. At the accept-time repaint `$?` is still
/// the status of the command BEFORE the accepted line, which is exactly
/// [`crate::p10k::last_status`] (mod.rs snapshots it pre-precmd), so
/// the ternary collapses at render time — same eager philosophy as
/// render.rs. Both branches hardcode the VIINS states (p10k:8316
/// `prompt_prompt_char_OK_VIINS`, p10k:8323
/// `prompt_prompt_char_ERROR_VIINS`) — the transient char never shows
/// vicmd/visual shapes.
///
/// RPROMPT is always empty: p10k:7653 —
/// `RPROMPT= PROMPT=$_p9k_transient_prompt _p9k_reset_prompt`.
// !!! PLACEHOLDER STUB — the concurrent p10k session owns this file and is
// writing the real body (zle_main.rs:1273 already calls it). `None` =
// transient prompt disabled this accept. Replace wholesale. !!!
/// Returns the (PROMPT, RPROMPT) template pair to repaint the accepted
/// line with, when the transient prompt is enabled.