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
use ;
use Once;
static DISABLE_BRACKETED_PASTE: Once = new;
/// Disables bracketed paste mode to work around inquire dropping paste events.
///
/// When bracketed paste mode is enabled (common in zsh/fish, tmux/zellij, and some terminals),
/// paste events are sent as `Event::Paste(String)` by crossterm. However, inquire's event
/// handler only processes `Event::Key(...)` and drops all other events, causing paste to
/// appear broken.
///
/// This function sends the ANSI escape sequence `CSI ?2004 l` to disable bracketed paste mode,
/// causing the terminal to send paste content as regular character events that inquire can handle.
///
/// **Side effects:**
/// - This changes terminal state and may affect bracketed paste behavior after the program exits.
/// - Most shells (zsh/fish) will re-enable it on the next prompt, but this is not guaranteed.
///
/// **Implementation notes:**
/// - Uses `Once` to ensure the sequence is only sent once per process.
/// - This is a best-effort operation that silently fails if stderr is not a terminal.
/// - On Windows, the ANSI sequence may appear as garbage in legacy consoles that don't support VT.