Debian Codegraph @

src/lib.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 //! Cross-platform terminal screen clearing.
2 //!
3 //! This library provides a set of ways to clear a screen, plus a “best effort” convenience function
4 //! to do the right thing most of the time.
5 //!
6 //! Unlike many cross-platform libraries, this one exposes every available choice all the time, and
7 //! only the convenience function varies based on compilation target or environmental factors.
8 //!
9 //! 90% of the time, you’ll want to use the convenience short-hand:
10 //!
11 //! ```no_run
12 //! clearscreen::clear().expect("failed to clear screen");
13 //! ```
14 //!
15 //! For anything else, refer to the [`ClearScreen`] enum.
16 //!
17 //! If you are supporting Windows in any capacity, the [`is_windows_10()`] documentation is
18 //! **required reading**.
19
20 #![doc(html_favicon_url = "https://watchexec.github.io/logo:clearscreen.svg")]
21 #![doc(html_logo_url = "https://watchexec.github.io/logo:clearscreen.svg")]
22 #![warn(missing_docs)]
23
24 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
25 borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#,
26 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/,
27 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#},
28 processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::{Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#, ExitStatusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitStatus#},
29 };
30
31 use terminforust-analyzer cargo terminfo 0.9.0 crate/::{
32 capabilityrust-analyzer cargo terminfo 0.9.0 capability/::{selfrust-analyzer cargo terminfo 0.9.0 capability/, Expansionrust-analyzer cargo terminfo 0.9.0 capability/Expansion#},
33 expandrust-analyzer cargo terminfo 0.9.0 expand/::{Contextrust-analyzer cargo terminfo 0.9.0 expand/Context#, Parameterrust-analyzer cargo terminfo 0.9.0 expand/Parameter#},
34 Capabilityrust-analyzer cargo terminfo 0.9.0 capability/Capability#, Databaserust-analyzer cargo terminfo 0.9.0 database/Database#, Valuerust-analyzer cargo terminfo 0.9.0 capability/Value#,
35 };
36 use thiserrorrust-analyzer cargo thiserror 2.0.11 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.11 Error:;
37 use whichrust-analyzer cargo which 8.0.0 crate/::whichrust-analyzer cargo which 8.0.0 which().;
38
39 /// Ways to clear the screen.
40 ///
41 /// There isn’t a single way to clear the (terminal/console) screen. Not only are there several
42 /// techniques to achieve the outcome, there are differences in the way terminal emulators intepret
43 /// some of these techniques, as well as platform particularities.
44 ///
45 /// In addition, there are other conditions a screen can be in that might be beneficial to reset,
46 /// such as when a TUI application crashes and leaves the terminal in a less than useful state.
47 ///
48 /// Finally, a terminal may have scrollback, and this can be kept as-is or cleared as well.
49 ///
50 /// Your application may need one particular clearing method, or it might offer several options to
51 /// the user, such as “hard” and “soft” clearing. This library makes no assumption and no judgement
52 /// on what is considered hard, soft, or something else: that is your responsibility to determine in
53 /// your context.
54 ///
55 /// For most cases, you should use [`ClearScreen::default()`] to select the most appropriate method.
56 ///
57 /// In any event, once a way is selected, call [`clear()`][ClearScreen::clear()] to apply it.
58 ///
59 /// # Example
60 ///
61 /// ```no_run
62 /// # use clearscreen::ClearScreen;
63 /// ClearScreen::default().clear().expect("failed to clear the screen");
64 /// ```
65 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
66 #[non_exhaustive]
67 pub enum ClearScreenrust-analyzer cargo clearscreen 4.0.2 ClearScreen# {
68 /// Does both [`TerminfoScreen`][ClearScreen::TerminfoScreen] and
69 /// [`TerminfoScrollback`][ClearScreen::TerminfoScrollback], in this order, but skips the
70 /// scrollback reset if the capability isn’t available.
71 ///
72 /// This is essentially what the [`clear`] command on unix does.
73 /// [`clear`]: https://invisible-island.net/ncurses/man/clear.1.html
74 Terminforust-analyzer cargo clearscreen 4.0.2 ClearScreen#Terminfo#,
75
76 /// Looks up the `clear` capability in the terminfo (from the TERM env var), and applies it.
77 ///
78 /// A non-hashed terminfo database is required (this is a [terminfo crate] limitation), such as
79 /// the one provided with ncurses.
80 ///
81 /// [terminfo crate]: https://lib.rs/crates/terminfo
82 TerminfoScreenrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TerminfoScreen#,
83
84 /// Looks up the `E3` (Erase Scrollback) capability in the terminfo (from the TERM env var), and applies it.
85 ///
86 /// The same terminfo limitation applies as for [`TerminfoScreen`][ClearScreen::TerminfoScreen].
87 TerminfoScrollbackrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TerminfoScrollback#,
88
89 /// Performs a terminfo-driven terminal reset sequence.
90 ///
91 /// This prints whichever are available of the **rs1**, **rs2**, **rs3**, and **rf** sequences.
92 /// If none of these are available, it prints whichever are available of the **is1**, **is2**,
93 /// **is3**, and **if** sequences. If none are available, an error is returned.
94 ///
95 /// This generally issues at least an `ESC c` sequence, which resets all terminal state to
96 /// default values, and then may issue more sequences to reset other things or enforce a
97 /// particular kind of state. See [`XtermReset`][ClearScreen::XtermReset] for a description of
98 /// what XTerm does, as an example.
99 ///
100 /// Note that this is _not_ analogous to what `tput reset` does: to emulate that, issuing first
101 /// one of VtCooked/VtWellDone/WindowsCooked followed by this variant will come close.
102 ///
103 /// The same terminfo limitation applies as for [`TerminfoScreen`][ClearScreen::TerminfoScreen].
104 TerminfoResetrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TerminfoReset#,
105
106 /// Prints clear screen and scrollback sequence as if TERM=xterm.
107 ///
108 /// This does not look up the correct sequence in the terminfo database, but rather prints:
109 ///
110 /// - `CSI H` (Cursor Position 0,0), which sets the cursor position to 0,0.
111 /// - `CSI 2J` (Erase Screen), which erases the whole screen.
112 /// - `CSI 3J` (Erase Scrollback), which erases the scrollback (xterm extension).
113 XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear#,
114
115 /// Prints the terminal reset sequence as if TERM=xterm.
116 ///
117 /// This does not look up the correct sequence in the terminfo database, but rather prints:
118 ///
119 /// - `ESC c` (Reset to Initial State), which nominally resets all terminal state to initial
120 /// values, but see the documentation for [`VtRis`][ClearScreen::VtRis].
121 /// - `CSI !p` (Soft Terminal Reset), which nominally does the same thing as RIS, but without
122 /// disconnecting the terminal data lines… which matters when you’re living in 1970.
123 /// - `CSI ?3l` (Reset to 80 Columns), which resets the terminal width to 80 columns, or more
124 /// accurately, resets the option that selects 132 column mode, to its default value of no.
125 /// I don’t know, man.
126 /// - `CSI ?4l` (Reset to Jump Scrolling), which sets the scrolling mode to jump. This is naught
127 /// to do with what we think of as “scrolling,” but rather it’s about the speed at which the
128 /// terminal will add lines to the screen. Jump mode means “give it to me as fast as it comes”
129 /// and Smooth mode means to do some buffering and output lines “at a moderate, smooth rate.”
130 /// - `CSI 4l` (Reset to Replace Mode), which sets the cursor writing mode to Replace, i.e.
131 /// overwriting characters at cursor position, instead of Insert, which pushes characters
132 /// under the cursor to the right.
133 /// - `ESC >` (Set Key Pad to Normal), which sets the keyboard’s numeric keypad to send “what’s
134 /// printed on the keys” i.e. numbers and the arithmetic symbols.
135 /// - `CSI ?69l` (Reset Left and Right Margins to the page), which sets the horizontal margins
136 /// to coincide with the page’s margins: nowadays, no margins.
137 XtermResetrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermReset#,
138
139 /// Calls the command `tput clear`.
140 ///
141 /// That command most likely does what [`Terminfo`][ClearScreen::Terminfo] does internally, but
142 /// may work better in some cases, such as when the terminfo database on the system is hashed or
143 /// in a non-standard location that the terminfo crate does not find.
144 ///
145 /// However, it relies on the `tput` command being available, and on being able to run commands.
146 TputClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TputClear#,
147
148 /// Calls the command `tput reset`.
149 ///
150 /// See the documentation above on [`TputClear`][ClearScreen::TputClear] for more details, save
151 /// that the equivalent is [`TerminfoReset`][ClearScreen::TerminfoReset].
152 TputResetrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TputReset#,
153
154 /// Calls the command `cls`.
155 ///
156 /// This is the Windows command to clear the screen. It has the same caveats as
157 /// [`TputClear`][ClearScreen::TputClear] does, but its internal mechanism is not known. Prefer
158 /// [`WindowsClear`][ClearScreen::WindowsClear] instead to avoid relying on an external command.
159 ///
160 /// This will always attempt to run the command, regardless of compile target, which may have
161 /// unintended effects if the `cls` executable does something different on the platform.
162 Clsrust-analyzer cargo clearscreen 4.0.2 ClearScreen#Cls#,
163
164 /// Sets the Windows Console to support VT escapes.
165 ///
166 /// This sets the `ENABLE_VIRTUAL_TERMINAL_PROCESSING` bit in the console mode, which enables
167 /// support for the terminal escape sequences every other terminal uses. This is supported since
168 /// Windows 10, from the Threshold 2 Update in November 2015.
169 ///
170 /// Does nothing on non-Windows targets.
171 WindowsVtrust-analyzer cargo clearscreen 4.0.2 ClearScreen#WindowsVt#,
172
173 /// Sets the Windows Console to support VT escapes and prints the clear sequence.
174 ///
175 /// This runs [`WindowsVt`][ClearScreen::WindowsVt] and [`XtermClear`][ClearScreen::XtermClear],
176 /// in this order. This is described here:
177 /// https://docs.microsoft.com/en-us/windows/console/clearing-the-screen#example-1 as the
178 /// recommended clearing method for all new development, although we also reset the cursor
179 /// position.
180 ///
181 /// While `WindowsVt` will do nothing on non-Windows targets, `XtermClear` will still run.
182 WindowsVtClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#WindowsVtClear#,
183
184 /// Uses Windows Console function to scroll the screen buffer and fill it with white space.
185 ///
186 /// - Scrolls up one screenful
187 /// - Fills the buffer with whitespace and attributes set to default.
188 /// - Flushes the input buffer
189 /// - Sets the cursor position to 0,0
190 ///
191 /// This is described here: https://docs.microsoft.com/en-us/windows/console/clearing-the-screen#example-2
192 /// as the equivalent to CMD.EXE's `cls` command.
193 ///
194 /// Does nothing on non-Windows targets.
195 #[cfg(feature = "windows-console")]
196 WindowsConsoleClear,
197
198 /// Uses Windows Console function to blank the screen state.
199 ///
200 /// - Fills the screen buffer with ` ` (space) characters
201 /// - Resets cell attributes over the entire buffer
202 /// - Flushes the input buffer
203 /// - Sets the cursor position to 0,0
204 ///
205 /// This is described here: https://docs.microsoft.com/en-us/windows/console/clearing-the-screen#example-3
206 ///
207 /// Does nothing on non-Windows targets.
208 #[cfg(feature = "windows-console")]
209 WindowsConsoleBlank,
210
211 /// Uses Windows Console function to disable raw mode.
212 ///
213 /// Does nothing on non-Windows targets.
214 WindowsCookedrust-analyzer cargo clearscreen 4.0.2 ClearScreen#WindowsCooked#,
215
216 /// Prints the RIS VT100 escape code: Reset to Initial State.
217 ///
218 /// This is the `ESC c` or `1b 63` escape, which by spec is defined to reset the terminal state
219 /// to all initial values, which may be a range of things, for example as described in the VT510
220 /// manual: https://vt100.net/docs/vt510-rm/RIS
221 ///
222 /// However, the exact behaviour is highly dependent on the terminal emulator, and some modern
223 /// terminal emulators do not always clear scrollback, for example Tmux and GNOME VTE.
224 VtRisrust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtRis#,
225
226 /// Prints the CSI sequence to leave the Alternate Screen mode.
227 ///
228 /// If the screen is in alternate screen mode, like how vim or a pager or another such rich TUI
229 /// application would do, this sequence will clear the alternate screen buffer, then revert the
230 /// terminal to normal mode, and restore the position of the cursor to what it was before
231 /// Alternate Screen mode was entered, assuming the proper sequence was used.
232 ///
233 /// It will not clear the normal mode buffer.
234 ///
235 /// This is useful when recovering from a TUI application which crashed without resetting state.
236 VtLeaveAltrust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtLeaveAlt#,
237
238 /// Sets the terminal to cooked mode.
239 ///
240 /// This attempts to switch the terminal to “cooked” mode, which can be thought of as the
241 /// opposite of “raw” mode, where the terminal does not respond to line discipline (which makes
242 /// carriage return, line feed, and general typing display out to screen, and translates Ctrl-C
243 /// to sending the SIGINT signal, etc) but instead passes all input to the controlling program
244 /// and only displays what it outputs explicitly.
245 ///
246 /// There’s also an intermediate “cbreak” or “rare” mode which behaves like “cooked” but sends
247 /// each character one at a time immediately rather buffering and sending lines.
248 ///
249 /// TUI applications such as editors and pagers often set raw mode to gain precise control of
250 /// the terminal state. If such a program crashes, it may not reset the terminal mode back to
251 /// the mode it found it in, which can leave the terminal behaving oddly or rendering it
252 /// completely unusable.
253 ///
254 /// In truth, these terminal modes are a set of configuration bits that are given to the
255 /// `termios(3)` libc API, and control a variety of terminal modes. “Cooked” mode sets:
256 ///
257 /// - Input BRKINT set: on BREAK, flush i/o queues and send a SIGINT to any running process.
258 /// - Input ICRNL set: translate Carriage Returns to New Lines on input.
259 /// - Input IGNPAR set: ignore framing and parity errors.
260 /// - Input ISTRIP set: strip off eigth bit.
261 /// - Input IXON set: enable XON/XOFF flow control on output.
262 /// - Output OPOST set: enable output processing.
263 /// - Local ICANON set: enable canonical mode (see below).
264 /// - Local ISIG set: when Ctrl-C, Ctrl-Q, etc are received, send the appropriate signal.
265 ///
266 /// Canonical mode is really the core of “cooked” mode and enables:
267 ///
268 /// - line buffering, so input is only sent to the underlying program when a line delimiter
269 /// character is entered (usually a newline);
270 /// - line editing, so ERASE (backspace) and KILL (remove entire line) control characters edit
271 /// the line before it is sent to the program;
272 /// - a maximum line length of 4096 characters (bytes).
273 ///
274 /// When canonical mode is unset (when the bit is cleared), all input processing is disabled.
275 ///
276 /// Due to how the underlying [`tcsetattr`] function is defined in POSIX, this may complete
277 /// without error if _any part_ of the configuration is applied, not just when all of it is set.
278 ///
279 /// Note that you generally want [`VtWellDone`][ClearScreen::VtWellDone] instead.
280 ///
281 /// Does nothing on non-Unix targets.
282 ///
283 /// [`tcsetattr`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetattr.html
284 VtCookedrust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtCooked#,
285
286 /// Sets the terminal to “well done” mode.
287 ///
288 /// This is similar to [`VtCooked`][ClearScreen::VtCooked], but with a different, broader, mode
289 /// configuration which approximates a terminal’s initial state, such as is expected by a shell,
290 /// and clears many bits that should probably never be set (like the translation/mapping modes).
291 ///
292 /// “Well done” mode is an invention of this library, inspired by several other sources such as
293 /// Golang’s goterm, the termios(3) and tput(1) manual pages, but not identical to any.
294 ///
295 /// Notably most implementations read the terminal configuration bits and only modify that set,
296 /// whereas this library authoritatively writes the entire configuration from scratch.
297 ///
298 /// It is a strict superset of [`VtCooked`][ClearScreen::VtCooked].
299 ///
300 /// - Input BRKINT set: on BREAK, flush i/o queues and send a SIGINT to any running process.
301 /// - Input ICRNL set: translate Carriage Return to New Line on input.
302 /// - Input IUTF8 set: input is UTF-8 (Linux only, since 2.6.4).
303 /// - Input IGNPAR set: ignore framing and parity errors.
304 /// - Input IMAXBEL set: ring terminal bell when input queue is full (not implemented in Linux).
305 /// - Input ISTRIP set: strip off eigth bit.
306 /// - Input IXON set: enable XON/XOFF flow control on output.
307 /// - Output ONLCR set: do not translate Carriage Return to CR NL.
308 /// - Output OPOST set: enable output processing.
309 /// - Control CREAD set: enable receiver.
310 /// - Local ICANON set: enable canonical mode (see [`VtCooked`][ClearScreen::VtCooked]).
311 /// - Local ISIG set: when Ctrl-C, Ctrl-Q, etc are received, send the appropriate signal.
312 ///
313 /// Does nothing on non-Unix targets.
314 VtWellDonerust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtWellDone#,
315 }
316
317 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ClearScreenrust-analyzer cargo clearscreen 4.0.2 ClearScreen# {
318 /// Detects the environment and makes its best guess as how to clear the screen.
319 ///
320 /// This function’s behaviour (but not its type signature) may change without notice, as better
321 /// techniques appear. However, it will always strive to provide the best method. It will also
322 /// never have side-effects, and finding any such behaviour should be reported as a bug.
323 ///
324 /// If you wish to make your own, the [`is_microsoft_terminal()`] and [`is_windows_10()`]
325 /// functions may be useful.
326 ///
327 /// The [`ClearScreen`] variant selected is always in the “clear” behaviour side of things. If
328 /// you wish to only clear the screen and not the scrollback, or to perform a terminal reset, or
329 /// apply the other available clearing strategies, you’ll need to select what’s best yourself.
330 ///
331 /// See the [TERMINALS.md file in the repo][TERMINALS.md] for research on many terminals as well
332 /// as the current result of this function for each terminal.
333 ///
334 /// [TERMINALS.md]: https://github.com/watchexec/clearscreen/blob/main/TERMINALS.md
335 fn defaultrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]default().() -> Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default] {
336 use envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().;
337 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#;
338
339 fn varfullrust-analyzer cargo clearscreen 4.0.2 varfull().(key: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>) -> bool {
340 varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(key).map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_or().(false, |s| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().())
341 }
342
343 let term = varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("TERM").okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
344 let term = term.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().();
345
346 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(windows) {
347 return if is_microsoft_terminalrust-analyzer cargo clearscreen 4.0.2 is_microsoft_terminal().() {
348 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear#
349 } else if is_windows_10rust-analyzer cargo clearscreen 4.0.2 is_windows_10().() {
350 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::WindowsVtClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#WindowsVtClear#
351 } else if term.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && varfullrust-analyzer cargo clearscreen 4.0.2 varfull().("TERMINFO") {
352 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::Terminforust-analyzer cargo clearscreen 4.0.2 ClearScreen#Terminfo#
353 } else if term.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && whichrust-analyzer cargo which 8.0.0 which().("tput").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
354 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::TputClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TputClear#
355 } else {
356 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::Clsrust-analyzer cargo clearscreen 4.0.2 ClearScreen#Cls#
357 };
358 }
359
360 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(term) = term {
361 // These VTE-based terminals support CSI 3J but their own terminfos don’t have E3
362 if (term.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("gnome")
363 && varfullrust-analyzer cargo clearscreen 4.0.2 varfull().("GNOME_TERMINAL_SCREEN")
364 && varfullrust-analyzer cargo clearscreen 4.0.2 varfull().("GNOME_TERMINAL_SERVICE"))
365 || term rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."xfce"
366 || term.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("termite")
367 {
368 return Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear#;
369 }
370
371 // - SyncTERM does support the XtermClear sequence but does not clear the scrollback,
372 // and does not have a terminfo, so VtRis is the only option.
373 // - rxvt, when using its own terminfos, erases the screen instead of clearing and
374 // doesn’t clear scrollback. It supports and behave properly for the entire XtermClear
375 // sequence, but it also does the right thing with VtRis, and that seems more reliable.
376 // - Other variants of (u)rxvt do the same.
377 // - Kitty does as rxvt does here.
378 // - Tess does support the XtermClear sequence but has a weird scrollbar behaviour,
379 // which does not happen with VtRis.
380 // - Zutty does not support E3, and erases the buffer on clear like rxvt, but does work
381 // properly with VtRis.
382 // - Same behaviour with the multiplexer Zellij.
383 if term rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."syncterm"
384 || term.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("rxvt")
385 || term.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("kitty")
386 || varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("CHROME_DESKTOP").map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_or().(false, |cd| cd rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."tess.desktop")
387 || varfullrust-analyzer cargo clearscreen 4.0.2 varfull().("ZUTTY_VERSION")
388 || varfullrust-analyzer cargo clearscreen 4.0.2 varfull().("ZELLIJ")
389 {
390 return Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::VtRisrust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtRis#;
391 }
392
393 // - screen supports CSI 3J only within the XtermClear sequence, without E3 capability.
394 // - Konsole handles CSI 3J correctly only within the XtermClear sequence.
395 // - Wezterm handles CSI 3J correctly only within the XtermClear sequence.
396 // - assume tmux TERMs are only used within tmux, and avoid the requirement for a functioning terminfo then
397 if term.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("screen")
398 || term.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("konsole")
399 || term rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."wezterm"
400 || term.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("tmux")
401 {
402 return Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear#;
403 }
404
405 // Default xterm* terminfo on macOS does not include E3, but many terminals support it.
406 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_os = "macos")
407 && term.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("xterm")
408 && Databaserust-analyzer cargo terminfo 0.9.0 database/Database#::from_envrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]from_env().()
409 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|info| info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#>().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().())
410 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(true)
411 {
412 return Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear#;
413 }
414
415 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().term.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() && Databaserust-analyzer cargo terminfo 0.9.0 database/Database#::from_envrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]from_env().().is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() {
416 return Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::Terminforust-analyzer cargo clearscreen 4.0.2 ClearScreen#Terminfo#;
417 }
418 }
419
420 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]::XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear#
421 }
422 }
423
424 const ESCrust-analyzer cargo clearscreen 4.0.2 ESC.: &[u8] = b"\x1b";
425 const CSIrust-analyzer cargo clearscreen 4.0.2 CSI.: &[u8] = b"\x1b[";
426 const RISrust-analyzer cargo clearscreen 4.0.2 RIS.: &[u8] = b"c";
427
428 impl ClearScreenrust-analyzer cargo clearscreen 4.0.2 ClearScreen# {
429 /// Performs the clearing action, printing to stdout.
430 pub fn clearrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]clear().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
431 let mut stdout = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().();
432 self.clear_torust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]clear_to().(&mut stdout)
433 }
434
435 /// Performs the clearing action, printing to a given writer.
436 ///
437 /// This allows to capture any escape sequences that might be printed, for example, but note
438 /// that it will not prevent actions taken via system APIs, such as the Windows, VtCooked, and
439 /// VtWellDone variants do.
440 ///
441 /// For normal use, prefer [`clear()`].
442 pub fn clear_torust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]clear_to().(self, mut w: &mut impl Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
443 match self {
444 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::Terminforust-analyzer cargo clearscreen 4.0.2 ClearScreen#Terminfo# => {
445 let info = Databaserust-analyzer cargo terminfo 0.9.0 database/Database#::from_envrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]from_env().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
446 let mut ctx = Contextrust-analyzer cargo terminfo 0.9.0 expand/Context#::defaultrust-analyzer cargo terminfo 0.9.0 expand/impl#[Context][Default]default().();
447
448 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::ClearScreenrust-analyzer cargo terminfo 0.9.0 capability/ClearScreen#>() {
449 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`ClearScreen<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
450 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
451 } else {
452 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::TerminfoCaprust-analyzer cargo clearscreen 4.0.2 Error#TerminfoCap#("clear"));
453 }
454
455 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#>() {
456 seq.expandrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'_>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
457 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
458 }
459 }
460 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::TerminfoScreenrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TerminfoScreen# => {
461 let info = Databaserust-analyzer cargo terminfo 0.9.0 database/Database#::from_envrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]from_env().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
462 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::ClearScreenrust-analyzer cargo terminfo 0.9.0 capability/ClearScreen#>() {
463 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`ClearScreen<'a>`]expand().().torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
464 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
465 } else {
466 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::TerminfoCaprust-analyzer cargo clearscreen 4.0.2 Error#TerminfoCap#("clear"));
467 }
468 }
469 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::TerminfoScrollbackrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TerminfoScrollback# => {
470 let info = Databaserust-analyzer cargo terminfo 0.9.0 database/Database#::from_envrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]from_env().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
471 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#>() {
472 seq.expandrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'_>`]expand().().torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
473 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
474 } else {
475 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::TerminfoCaprust-analyzer cargo clearscreen 4.0.2 Error#TerminfoCap#("E3"));
476 }
477 }
478 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::TerminfoResetrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TerminfoReset# => {
479 let info = Databaserust-analyzer cargo terminfo 0.9.0 database/Database#::from_envrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]from_env().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
480 let mut ctx = Contextrust-analyzer cargo terminfo 0.9.0 expand/Context#::defaultrust-analyzer cargo terminfo 0.9.0 expand/impl#[Context][Default]default().();
481 let mut reset = false;
482
483 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::Reset1Stringrust-analyzer cargo terminfo 0.9.0 capability/Reset1String#>() {
484 reset = true;
485 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Reset1String<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
486 }
487 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::Reset2Stringrust-analyzer cargo terminfo 0.9.0 capability/Reset2String#>() {
488 reset = true;
489 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Reset2String<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
490 }
491 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::Reset3Stringrust-analyzer cargo terminfo 0.9.0 capability/Reset3String#>() {
492 reset = true;
493 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Reset3String<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
494 }
495 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::ResetFilerust-analyzer cargo terminfo 0.9.0 capability/ResetFile#>() {
496 reset = true;
497 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`ResetFile<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
498 }
499
500 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
501
502 if reset {
503 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
504 }
505
506 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::Init1Stringrust-analyzer cargo terminfo 0.9.0 capability/Init1String#>() {
507 reset = true;
508 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Init1String<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
509 }
510 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::Init2Stringrust-analyzer cargo terminfo 0.9.0 capability/Init2String#>() {
511 reset = true;
512 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Init2String<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
513 }
514 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::Init3Stringrust-analyzer cargo terminfo 0.9.0 capability/Init3String#>() {
515 reset = true;
516 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Init3String<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
517 }
518 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seq) = info.getrust-analyzer cargo terminfo 0.9.0 database/impl#[Database]get().::<capabilityrust-analyzer cargo terminfo 0.9.0 capability/::InitFilerust-analyzer cargo terminfo 0.9.0 capability/InitFile#>() {
519 reset = true;
520 seq.expandrust-analyzer cargo terminfo 0.9.0 capability/impl#[`InitFile<'a>`]expand().().withrust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]with().(&mut ctx).torust-analyzer cargo terminfo 0.9.0 capability/impl#[`Expansion<'a, T>`]to().(&mut w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
521 }
522
523 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
524
525 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reset {
526 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::TerminfoCaprust-analyzer cargo clearscreen 4.0.2 Error#TerminfoCap#("reset"));
527 }
528 }
529 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear# => {
530 const CURSOR_HOMErust-analyzer cargo clearscreen 4.0.2 CURSOR_HOME.: &[u8] = b"H";
531 const ERASE_SCREENrust-analyzer cargo clearscreen 4.0.2 ERASE_SCREEN.: &[u8] = b"2J";
532 const ERASE_SCROLLBACKrust-analyzer cargo clearscreen 4.0.2 ERASE_SCROLLBACK.: &[u8] = b"3J";
533
534 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
535 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CURSOR_HOMErust-analyzer cargo clearscreen 4.0.2 CURSOR_HOME.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
536
537 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
538 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(ERASE_SCREENrust-analyzer cargo clearscreen 4.0.2 ERASE_SCREEN.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
539
540 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
541 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(ERASE_SCROLLBACKrust-analyzer cargo clearscreen 4.0.2 ERASE_SCROLLBACK.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
542
543 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
544 }
545 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::XtermResetrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermReset# => {
546 const STRrust-analyzer cargo clearscreen 4.0.2 STR.: &[u8] = b"!p";
547 const RESET_WIDTH_AND_SCROLLrust-analyzer cargo clearscreen 4.0.2 RESET_WIDTH_AND_SCROLL.: &[u8] = b"?3;4l";
548 const RESET_REPLACErust-analyzer cargo clearscreen 4.0.2 RESET_REPLACE.: &[u8] = b"4l";
549 const RESET_KEYPADrust-analyzer cargo clearscreen 4.0.2 RESET_KEYPAD.: &[u8] = b">";
550 const RESET_MARGINSrust-analyzer cargo clearscreen 4.0.2 RESET_MARGINS.: &[u8] = b"?69l";
551
552 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(ESCrust-analyzer cargo clearscreen 4.0.2 ESC.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
553 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(RISrust-analyzer cargo clearscreen 4.0.2 RIS.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
554
555 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
556 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(STRrust-analyzer cargo clearscreen 4.0.2 STR.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
557
558 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
559 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(RESET_WIDTH_AND_SCROLLrust-analyzer cargo clearscreen 4.0.2 RESET_WIDTH_AND_SCROLL.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
560
561 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
562 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(RESET_REPLACErust-analyzer cargo clearscreen 4.0.2 RESET_REPLACE.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
563
564 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(ESCrust-analyzer cargo clearscreen 4.0.2 ESC.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
565 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(RESET_KEYPADrust-analyzer cargo clearscreen 4.0.2 RESET_KEYPAD.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
566
567 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
568 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(RESET_MARGINSrust-analyzer cargo clearscreen 4.0.2 RESET_MARGINS.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
569
570 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
571 }
572 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::TputClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TputClear# => {
573 let status = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("tput").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("clear").statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]status().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
574 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().status.successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().() {
575 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::Commandrust-analyzer cargo clearscreen 4.0.2 Error#Command#("tput clear", status));
576 }
577 }
578 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::TputResetrust-analyzer cargo clearscreen 4.0.2 ClearScreen#TputReset# => {
579 let status = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("tput").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("reset").statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]status().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
580 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().status.successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().() {
581 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::Commandrust-analyzer cargo clearscreen 4.0.2 Error#Command#("tput reset", status));
582 }
583 }
584 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::Clsrust-analyzer cargo clearscreen 4.0.2 ClearScreen#Cls# => {
585 let status = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("cmd.exe").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("/C").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("cls").statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]status().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
586 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().status.successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().() {
587 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::Commandrust-analyzer cargo clearscreen 4.0.2 Error#Command#("cls", status));
588 }
589 }
590 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::WindowsVtrust-analyzer cargo clearscreen 4.0.2 ClearScreen#WindowsVt# => winrust-analyzer cargo clearscreen 4.0.2 win/::vtrust-analyzer cargo clearscreen 4.0.2 win/vt().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
591 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::WindowsVtClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#WindowsVtClear# => {
592 let vtres = winrust-analyzer cargo clearscreen 4.0.2 win/::vtrust-analyzer cargo clearscreen 4.0.2 win/vt().();
593 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::XtermClearrust-analyzer cargo clearscreen 4.0.2 ClearScreen#XtermClear#.clear_torust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]clear_to().(w)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
594 vtres?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
595 }
596 #[cfg(feature = "windows-console")]
597 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::WindowsConsoleClear => winrust-analyzer cargo clearscreen 4.0.2 win/::clear()?,
598 #[cfg(feature = "windows-console")]
599 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::WindowsConsoleBlank => winrust-analyzer cargo clearscreen 4.0.2 win/::blank()?,
600 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::WindowsCookedrust-analyzer cargo clearscreen 4.0.2 ClearScreen#WindowsCooked# => winrust-analyzer cargo clearscreen 4.0.2 win/::cookedrust-analyzer cargo clearscreen 4.0.2 win/cooked().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
601 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::VtRisrust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtRis# => {
602 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(ESCrust-analyzer cargo clearscreen 4.0.2 ESC.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
603 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(RISrust-analyzer cargo clearscreen 4.0.2 RIS.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
604 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
605 }
606 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::VtLeaveAltrust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtLeaveAlt# => {
607 const LEAVE_ALTrust-analyzer cargo clearscreen 4.0.2 LEAVE_ALT.: &[u8] = b"?1049l";
608 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(CSIrust-analyzer cargo clearscreen 4.0.2 CSI.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
609 w.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(LEAVE_ALTrust-analyzer cargo clearscreen 4.0.2 LEAVE_ALT.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
610 w.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
611 }
612 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::VtCookedrust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtCooked# => unixrust-analyzer cargo clearscreen 4.0.2 unix/::vt_cookedrust-analyzer cargo clearscreen 4.0.2 unix/vt_cooked().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
613 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]::VtWellDonerust-analyzer cargo clearscreen 4.0.2 ClearScreen#VtWellDone# => unixrust-analyzer cargo clearscreen 4.0.2 unix/::vt_well_donerust-analyzer cargo clearscreen 4.0.2 unix/vt_well_done().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
614 }
615
616 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
617 }
618 }
619
620 /// Shorthand for `ClearScreen::default().clear()`.
621 pub fn clearrust-analyzer cargo clearscreen 4.0.2 clear().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
622 ClearScreenrust-analyzer cargo clearscreen 4.0.2 ClearScreen#::defaultrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen][Default]default().().clearrust-analyzer cargo clearscreen 4.0.2 impl#[ClearScreen]clear().()
623 }
624
625 /// Detects Microsoft Terminal.
626 ///
627 /// Note that this is only provided to write your own clearscreen logic and _should not_ be relied
628 /// on for other purposes, as it makes no guarantees of reliable detection, and its internal
629 /// behaviour may change without notice.
630 pub fn is_microsoft_terminalrust-analyzer cargo clearscreen 4.0.2 is_microsoft_terminal().() -> bool {
631 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("WT_SESSION").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()
632 }
633
634 /// Detects Windows ≥10.
635 ///
636 /// As mentioned in the [`WindowsVt`][ClearScreen::WindowsVt] documentation, Windows 10 from the
637 /// Threshold 2 Update in November 2015 supports the `ENABLE_VIRTUAL_TERMINAL_PROCESSING` console
638 /// mode bit, which enables VT100/ECMA-48 escape sequence processing in the console. This in turn
639 /// makes clearing the console vastly easier and is the recommended mode of operation by Microsoft.
640 ///
641 /// However, detecting Windows ≥10 is not trivial. To mitigate broken programs that incorrectly
642 /// perform version shimming, Microsoft has deprecated most ways to obtain the version of Windows by
643 /// making the relevant APIs _lie_ unless the calling executable [embeds a manifest that explicitely
644 /// opts-in to support Windows 10][manifesting].
645 ///
646 /// To be clear, **this is the proper way to go**, and while this function tries, it may return
647 /// false under some Win10s if you don't manifest. If you are writing an application which uses this
648 /// library, or indeed any application targeting Windows at all, you should embed such a manifest
649 /// (and take that opportunity to opt-in to long path support, see e.g. [watchexec#163]). If you are
650 /// writing a library on top of this one, it is your responsibility to communicate this requirement
651 /// to your users.
652 ///
653 /// It is important to remark that it is not possible to manifest twice. In plainer words,
654 /// **libraries _must not_ embed a manifest** as that will make it impossible for applications which
655 /// depend on them to embed their own manifest.
656 ///
657 /// This function tries its best to detect Windows ≥10, and specifically, whether the mentioned mode
658 /// bit can be used. Critically, it leaves trying to set the bit as feature detection as a last
659 /// resort, such that _an error setting the bit_ is not confunded with _the bit not being supported_.
660 ///
661 /// Note that this is only provided to write your own clearscreen logic and _should not_ be relied
662 /// on for other purposes, as it makes no guarantees of reliable detection, and its internal
663 /// behaviour may change without notice. Additionally, this will always return false if the library
664 /// was compiled for a non-Windows target, even if e.g. it’s running under WSL in a Windows 10 host.
665 ///
666 /// TL;DR:
667 ///
668 /// - Runs on Windows ≥10 without manifest and returns `true`: good, expected behaviour.
669 /// - Runs on Windows ≥10 without manifest and returns `false`: **not a bug**, please manifest.
670 /// - Runs on Windows ≥10 with manifest and returns `true`: good, expected behaviour.
671 /// - Runs on Windows ≥10 with manifest and returns `false`: **is a bug**, please report it.
672 /// - Runs on Windows <10 and returns `true`: **is a bug**, please report it. [ex #5]
673 /// - Runs on Windows <10 and returns `false`: good, expected behaviour.
674 ///
675 /// [ex #5]: https://github.com/watchexec/clearscreen/issues/5
676 /// [manifesting]: https://docs.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1
677 /// [watchexec#163]: https://github.com/watchexec/watchexec/issues/163
678 pub fn is_windows_10rust-analyzer cargo clearscreen 4.0.2 is_windows_10().() -> bool {
679 winrust-analyzer cargo clearscreen 4.0.2 win/::is_windows_10rust-analyzer cargo clearscreen 4.0.2 win/is_windows_10().()
680 }
681
682 /// Error type.
683 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Errorrust-analyzer cargo thiserror-impl 2.0.11 Error:)]
684 pub enum Errorrust-analyzer cargo clearscreen 4.0.2 Error# {
685 /// Any I/O error.
686 #[errorrust-analyzer cargo thiserror-impl 2.0.11 error:("io: {0}")]
687 Iorust-analyzer cargo clearscreen 4.0.2 Error#Io#(#[from] iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#),
688
689 /// A non-success exit status from a command.
690 #[errorrust-analyzer cargo thiserror-impl 2.0.11 error:("command: {0}: {1}")]
691 Commandrust-analyzer cargo clearscreen 4.0.2 Error#Command#(&'static str, ExitStatusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/ExitStatus#),
692
693 /// Any nix (libc) error.
694 #[cfg(unix)]
695 #[errorrust-analyzer cargo thiserror-impl 2.0.11 error:("unix: {0}")]
696 Nixrust-analyzer cargo clearscreen 4.0.2 Error#Nix#(#[from] NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#),
697
698 /// Any terminfo error.
699 #[errorrust-analyzer cargo thiserror-impl 2.0.11 error:("terminfo: {0}")]
700 Terminforust-analyzer cargo clearscreen 4.0.2 Error#Terminfo#(#[from] TerminfoErrorrust-analyzer cargo clearscreen 4.0.2 TerminfoError#),
701
702 /// A missing terminfo capability.
703 #[errorrust-analyzer cargo thiserror-impl 2.0.11 error:("terminfo: capability not available: {0}")]
704 TerminfoCaprust-analyzer cargo clearscreen 4.0.2 Error#TerminfoCap#(&'static str),
705
706 /// A null-pointer error.
707 #[errorrust-analyzer cargo thiserror-impl 2.0.11 error:("ffi: encountered a null pointer while reading {0}")]
708 NullPtrrust-analyzer cargo clearscreen 4.0.2 Error#NullPtr#(&'static str),
709 }
710
711 /// Nix error type.
712 ///
713 /// This wraps a [`nix::Error`] to avoid directly exposing the type in the public API, which
714 /// required a breaking change every time `clearscreen` updated its `nix` version.
715 ///
716 /// To obtain a nix error, convert this error to an `i32` then use [`nix::Error::from_raw`]:
717 ///
718 /// Creating a [`NixError`] is explicitly not possible from the public API.
719 ///
720 /// ```no_compile
721 /// let nix_error = nix::Error::from_raw(error.into());
722 /// assert_eq!(nix_error, nix::Error::EINVAL);
723 /// ```
724 #[cfg(unix)]
725 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Errorrust-analyzer cargo thiserror-impl 2.0.11 Error:)]
726 #[error(transparent)]
727 pub struct NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#(nixrust-analyzer cargo nix 0.30.1 crate/::Errorrust-analyzer cargo nix 0.30.1 Error#);
728
729 #[cfg(unix)]
730 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#> for i32 {
731 fn fromrust-analyzer cargo clearscreen 4.0.2 impl#[i32][`From<NixError>`]from().(err: NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#) -> Selfrust-analyzer cargo clearscreen 4.0.2 impl#[i32][`From<NixError>`] {
732 err.0rust-analyzer cargo clearscreen 4.0.2 NixError#0. as _
733 }
734 }
735
736 /// Terminfo error type.
737 ///
738 /// This wraps a [`terminfo::Error`] to avoid directly exposing the type in the public API, which
739 /// required a breaking change every time `clearscreen` updated its `terminfo` version.
740 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Errorrust-analyzer cargo thiserror-impl 2.0.11 Error:)]
741 #[error("{description}")]
742 pub struct TerminfoErrorrust-analyzer cargo clearscreen 4.0.2 TerminfoError# {
743 innerrust-analyzer cargo clearscreen 4.0.2 TerminfoError#inner.: terminforust-analyzer cargo terminfo 0.9.0 crate/::Errorrust-analyzer cargo terminfo 0.9.0 error/Error#,
744 descriptionrust-analyzer cargo clearscreen 4.0.2 TerminfoError#description.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
745 }
746
747 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<terminforust-analyzer cargo terminfo 0.9.0 crate/::Errorrust-analyzer cargo terminfo 0.9.0 error/Error#> for TerminfoErrorrust-analyzer cargo clearscreen 4.0.2 TerminfoError# {
748 fn fromrust-analyzer cargo clearscreen 4.0.2 impl#[TerminfoError][`From<terminfo::Error>`]from().(inner: terminforust-analyzer cargo terminfo 0.9.0 crate/::Errorrust-analyzer cargo terminfo 0.9.0 error/Error#) -> Selfrust-analyzer cargo clearscreen 4.0.2 impl#[TerminfoError][`From<terminfo::Error>`] {
749 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[TerminfoError][`From<terminfo::Error>`] {
750 descriptionrust-analyzer cargo clearscreen 4.0.2 TerminfoError#description.: inner.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
751 innerrust-analyzer cargo clearscreen 4.0.2 TerminfoError#inner.,
752 }
753 }
754 }
755
756 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<terminforust-analyzer cargo terminfo 0.9.0 crate/::Errorrust-analyzer cargo terminfo 0.9.0 error/Error#> for Errorrust-analyzer cargo clearscreen 4.0.2 Error# {
757 fn fromrust-analyzer cargo clearscreen 4.0.2 impl#[Error][`From<terminfo::Error>`]from().(err: terminforust-analyzer cargo terminfo 0.9.0 crate/::Errorrust-analyzer cargo terminfo 0.9.0 error/Error#) -> Selfrust-analyzer cargo clearscreen 4.0.2 impl#[Error][`From<terminfo::Error>`] {
•758 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[Error][`From<terminfo::Error>`]::Terminforust-analyzer cargo clearscreen 4.0.2 Error#Terminfo#(TerminfoErrorrust-analyzer cargo clearscreen 4.0.2 TerminfoError#::fromrust-analyzer cargo clearscreen 4.0.2 impl#[TerminfoError][`From<terminfo::Error>`]from().(err))
759 }
760 }
761
762 #[cfg(unix)]
763 mod unixrust-analyzer cargo clearscreen 4.0.2 unix/ {
764 use superrust-analyzer cargo clearscreen 4.0.2 crate/::{Errorrust-analyzer cargo clearscreen 4.0.2 Error#, NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#};
765
766 use nixrust-analyzer cargo nix 0.30.1 crate/::{
767 sysrust-analyzer cargo nix 0.30.1 sys/::termiosrust-analyzer cargo nix 0.30.1 sys/termios/::{
768 tcgetattrrust-analyzer cargo nix 0.30.1 sys/termios/tcgetattr()., tcsetattrrust-analyzer cargo nix 0.30.1 sys/termios/tcsetattr()., ControlFlagsrust-analyzer cargo nix 0.30.1 sys/termios/ControlFlags#, InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#, LocalFlagsrust-analyzer cargo nix 0.30.1 sys/termios/LocalFlags#, OutputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/OutputFlags#,
769 SetArgrust-analyzer cargo nix 0.30.1 sys/termios/SetArg#::TCSANOWrust-analyzer cargo nix 0.30.1 sys/termios/SetArg#TCSANOW#, Termiosrust-analyzer cargo nix 0.30.1 sys/termios/Termios#,
770 },
771 unistdrust-analyzer cargo nix 0.30.1 unistd/::isattyrust-analyzer cargo nix 0.30.1 unistd/isatty().,
772 };
773
774 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin()., osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::AsFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/AsFd#, osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/prelude/::AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#};
775
776 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn vt_cookedrust-analyzer cargo clearscreen 4.0.2 unix/vt_cooked().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
777 write_termiosrust-analyzer cargo clearscreen 4.0.2 unix/write_termios().(|t| {
778 t.input_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#input_flags..insertrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]insert().(
779 InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::BRKINTrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]BRKINT.
780 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::ICRNLrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]ICRNL.
781 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::IGNPARrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]IGNPAR.
782 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::ISTRIPrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]ISTRIP.
783 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::IXONrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]IXON.,
784 );
785 t.output_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#output_flags..insertrust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags]insert().(OutputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/OutputFlags#::OPOSTrust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags]OPOST.);
786 t.local_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#local_flags..insertrust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]insert().(LocalFlagsrust-analyzer cargo nix 0.30.1 sys/termios/LocalFlags#::ICANONrust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]ICANON. rust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags][`BitOr<Self>`]bitor().|rust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags][`BitOr<Self>`]bitor().LocalFlagsrust-analyzer cargo nix 0.30.1 sys/termios/LocalFlags#::ISIGrust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]ISIG.);
787 })
788 }
789
790 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn vt_well_donerust-analyzer cargo clearscreen 4.0.2 unix/vt_well_done().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
791 write_termiosrust-analyzer cargo clearscreen 4.0.2 unix/write_termios().(|t| {
792 let mut inserts = InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::BRKINTrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]BRKINT.
793 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::ICRNLrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]ICRNL.
794 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::IGNPARrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]IGNPAR.
795 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::IMAXBELrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]IMAXBEL.
796 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::ISTRIPrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]ISTRIP.
797 |rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOr<Self>`]bitor().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::IXONrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]IXON.;
798
799 #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
800 {
801 inserts rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags][`BitOrAssign<Self>`]bitor_assign().InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::IUTF8rust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]IUTF8.;
802 }
803
804 t.input_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#input_flags..insertrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]insert().(inserts);
805 t.output_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#output_flags.
806 .insertrust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags]insert().(OutputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/OutputFlags#::ONLCRrust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags]ONLCR. rust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags][`BitOr<Self>`]bitor().|rust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags][`BitOr<Self>`]bitor().OutputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/OutputFlags#::OPOSTrust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags]OPOST.);
807 t.control_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#control_flags..insertrust-analyzer cargo nix 0.30.1 sys/termios/impl#[ControlFlags]insert().(ControlFlagsrust-analyzer cargo nix 0.30.1 sys/termios/ControlFlags#::CREADrust-analyzer cargo nix 0.30.1 sys/termios/impl#[ControlFlags]CREAD.);
808 t.local_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#local_flags..insertrust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]insert().(LocalFlagsrust-analyzer cargo nix 0.30.1 sys/termios/LocalFlags#::ICANONrust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]ICANON. rust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags][`BitOr<Self>`]bitor().|rust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags][`BitOr<Self>`]bitor().LocalFlagsrust-analyzer cargo nix 0.30.1 sys/termios/LocalFlags#::ISIGrust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]ISIG.);
809 })
810 }
811
812 fn reset_termiosrust-analyzer cargo clearscreen 4.0.2 unix/reset_termios().(t: &mut Termiosrust-analyzer cargo nix 0.30.1 sys/termios/Termios#) {
813 t.input_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#input_flags..removerust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]remove().(InputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/InputFlags#::allrust-analyzer cargo nix 0.30.1 sys/termios/impl#[InputFlags]all().());
814 t.output_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#output_flags..removerust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags]remove().(OutputFlagsrust-analyzer cargo nix 0.30.1 sys/termios/OutputFlags#::allrust-analyzer cargo nix 0.30.1 sys/termios/impl#[OutputFlags]all().());
815 t.control_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#control_flags..removerust-analyzer cargo nix 0.30.1 sys/termios/impl#[ControlFlags]remove().(ControlFlagsrust-analyzer cargo nix 0.30.1 sys/termios/ControlFlags#::allrust-analyzer cargo nix 0.30.1 sys/termios/impl#[ControlFlags]all().());
816 t.local_flagsrust-analyzer cargo nix 0.30.1 sys/termios/Termios#local_flags..removerust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]remove().(LocalFlagsrust-analyzer cargo nix 0.30.1 sys/termios/LocalFlags#::allrust-analyzer cargo nix 0.30.1 sys/termios/impl#[LocalFlags]all().());
817 }
818
819 fn write_termiosrust-analyzer cargo clearscreen 4.0.2 unix/write_termios().(f: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&mut Termiosrust-analyzer cargo nix 0.30.1 sys/termios/Termios#)) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
820 if isattyrust-analyzer cargo nix 0.30.1 unistd/isatty().(stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
821 let mut t = tcgetattrrust-analyzer cargo nix 0.30.1 sys/termios/tcgetattr().(stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`io::Stdin`][AsFd]as_fd().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
822 reset_termiosrust-analyzer cargo clearscreen 4.0.2 unix/reset_termios().(&mut t);
823 f(&mut t);
824 tcsetattrrust-analyzer cargo nix 0.30.1 sys/termios/tcsetattr().(stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`io::Stdin`][AsFd]as_fd().(), TCSANOWrust-analyzer cargo nix 0.30.1 sys/termios/SetArg#TCSANOW#, &t).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
825 } else {
826 let tty = OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().().readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true).writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true).openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().("/dev/tty")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
827 let fd = tty.as_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`fs::File`][AsFd]as_fd().();
828
829 let mut t = tcgetattrrust-analyzer cargo nix 0.30.1 sys/termios/tcgetattr().(fd).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
830 reset_termiosrust-analyzer cargo clearscreen 4.0.2 unix/reset_termios().(&mut t);
831 f(&mut t);
832 tcsetattrrust-analyzer cargo nix 0.30.1 sys/termios/tcsetattr().(fd, TCSANOWrust-analyzer cargo nix 0.30.1 sys/termios/SetArg#TCSANOW#, &t).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(NixErrorrust-analyzer cargo clearscreen 4.0.2 NixError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
833 }
834
835 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
836 }
837 }
838
839 #[cfg(windows)]
840 mod winrust-analyzer cargo clearscreen 4.0.2 win/ {
841 use superrust-analyzer cargo clearscreen 4.0.2 crate/::Errorrust-analyzer cargo clearscreen 4.0.2 Error#;
842
843 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of()., ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/};
844
845 use windows_sys::Win32::Foundation::{FALSE, HANDLE, INVALID_HANDLE_VALUE};
846 use windows_sys::Win32::NetworkManagement::NetManagement::{
847 NetApiBufferAllocate, NetApiBufferFree, NetServerGetInfo, NetWkstaGetInfo,
848 MAJOR_VERSION_MASK, SERVER_INFO_101, SV_PLATFORM_ID_NT, WKSTA_INFO_100,
849 };
850 use windows_sys::Win32::System::Console::{
851 GetConsoleMode, GetStdHandle, SetConsoleMode, CONSOLE_MODE, ENABLE_ECHO_INPUT,
852 ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT, ENABLE_VIRTUAL_TERMINAL_PROCESSING,
853 STD_OUTPUT_HANDLE,
854 };
855 use windows_sys::Win32::System::SystemInformation::{
856 VerSetConditionMask, VerifyVersionInfoW, OSVERSIONINFOEXW, VER_MAJORVERSION,
857 VER_MINORVERSION, VER_SERVICEPACKMAJOR,
858 };
859 use windows_sys::Win32::System::SystemServices::VER_GREATER_EQUAL;
860
861 #[cfg(feature = "windows-console")]
862 use windows_sys::Win32::System::Console::{
863 FillConsoleOutputAttribute, FillConsoleOutputCharacterW, GetConsoleScreenBufferInfo,
864 ScrollConsoleScreenBufferW, SetConsoleCursorPosition, CHAR_INFO, CHAR_INFO_0,
865 CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT,
866 };
867
868 fn console_handle() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<HANDLE, Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
869 match unsafe { GetStdHandle(STD_OUTPUT_HANDLE) } {
870 INVALID_HANDLE_VALUE => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into()),
871 handle => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(handle),
872 }
873 }
874
875 #[cfg(feature = "windows-console")]
876 fn buffer_info(console: HANDLE) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<CONSOLE_SCREEN_BUFFER_INFO, Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
877 let csbi: *mut CONSOLE_SCREEN_BUFFER_INFO = ptr::null_mut();
878 if unsafe { GetConsoleScreenBufferInfo(console, csbi) } == FALSE {
879 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
880 }
881
882 if csbi.is_null() {
883 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo clearscreen 4.0.2 Error#::NullPtrrust-analyzer cargo clearscreen 4.0.2 Error#NullPtr#("GetConsoleScreenBufferInfo"))
884 } else {
885 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(unsafe { ptr::read(csbi) })
886 }
887 }
888
889 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn vt() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
890 let stdout = console_handle()?;
891
892 let mut mode = 0;
893 if unsafe { GetConsoleMode(stdout, &mut mode) } == FALSE {
894 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
895 }
896
897 mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
898 if unsafe { SetConsoleMode(stdout, mode) } == FALSE {
899 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
900 }
901
902 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
903 }
904
905 // Ref https://docs.microsoft.com/en-us/windows/console/clearing-the-screen#example-2
906 #[cfg(feature = "windows-console")]
907 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn clear() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
908 let console = console_handle()?;
909 let csbi = buffer_info(console)?;
910
911 // Scroll the rectangle of the entire buffer.
912 let rect = SMALL_RECT {
913 Left: 0,
914 Top: 0,
915 Right: csbi.dwSize.X,
916 Bottom: csbi.dwSize.Y,
917 };
918
919 // Scroll it upwards off the top of the buffer with a magnitude of the entire height.
920 let target = COORD {
921 X: 0,
922 Y: (0 - csbi.dwSize.Y) as i16,
923 };
924
925 // Fill with empty spaces with the buffer’s default text attribute.
926 let space = CHAR_INFO_0 {
927 AsciiChar: b' ' as i8,
928 };
929
930 let fill = CHAR_INFO {
931 Char: space,
932 Attributes: csbi.wAttributes,
933 };
934
935 // Do the scroll.
936 if unsafe { ScrollConsoleScreenBufferW(console, &rect, ptr::null(), target, &fill) }
937 == FALSE
938 {
939 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
940 }
941
942 // Move the cursor to the top left corner too.
943 let mut cursor = csbi.dwCursorPosition;
944 cursor.X = 0;
945 cursor.Y = 0;
946
947 if unsafe { SetConsoleCursorPosition(console, cursor) } == FALSE {
948 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
949 }
950
951 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
952 }
953
954 // Ref https://docs.microsoft.com/en-us/windows/console/clearing-the-screen#example-3
955 #[cfg(feature = "windows-console")]
956 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn blank() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
957 let console = console_handle()?;
958
959 // Fill the entire screen with blanks.
960 let csbi = buffer_info(console)?;
961
962 let buffer_size = csbi.dwSize.X * csbi.dwSize.Y;
963 let home_coord = COORD { X: 0, Y: 0 };
964
965 if FALSE
966 == unsafe {
967 FillConsoleOutputCharacterW(
968 console,
969 b' ' as u16,
970 u32::try_from(buffer_size).unwrap_or(0),
971 home_coord,
972 ptr::null_mut(),
973 )
974 } {
975 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
976 }
977
978 // Set the buffer's attributes accordingly.
979 let csbi = buffer_info(console)?;
980 if FALSE
981 == unsafe {
982 FillConsoleOutputAttribute(
983 console,
984 csbi.wAttributes,
985 u32::try_from(buffer_size).unwrap_or(0),
986 home_coord,
987 ptr::null_mut(),
988 )
989 } {
990 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
991 }
992
993 // Put the cursor at its home coordinates.
994 if unsafe { SetConsoleCursorPosition(console, home_coord) } == FALSE {
995 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
996 }
997
998 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
999 }
1000
1001 const ENABLE_COOKED_MODE: CONSOLE_MODE =
1002 ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
1003
1004 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn cooked() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1005 let stdout = console_handle()?;
1006
1007 let mut mode = 0;
1008 if unsafe { GetConsoleMode(stdout, &mut mode) } == FALSE {
1009 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
1010 }
1011
1012 mode |= ENABLE_COOKED_MODE;
1013 if unsafe { SetConsoleMode(stdout, mode) } == FALSE {
1014 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
1015 }
1016
1017 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1018 }
1019
1020 // I hope someone searches for this one day and gets mad at me for making their life harder.
1021 const ABRACADABRA_THRESHOLD: (u8, u8) = (0x0A, 0x00);
1022
1023 // proper way, requires manifesting
1024 #[inline]
1025 fn um_verify_version() -> bool {
1026 let condition_mask: u64 = unsafe {
1027 VerSetConditionMask(
1028 VerSetConditionMask(
1029 VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL as u8),
1030 VER_MINORVERSION,
1031 VER_GREATER_EQUAL as u8,
1032 ),
1033 VER_SERVICEPACKMAJOR,
1034 VER_GREATER_EQUAL as u8,
1035 )
1036 };
1037
1038 let mut osvi = OSVERSIONINFOEXW {
1039 dwMinorVersion: ABRACADABRA_THRESHOLD.1 as _,
1040 dwMajorVersion: ABRACADABRA_THRESHOLD.0 as _,
1041 wServicePackMajor: 0,
1042 dwOSVersionInfoSize: size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<OSVERSIONINFOEXW>() as u32,
1043 dwBuildNumber: 0,
1044 dwPlatformId: 0,
1045 szCSDVersion: [0; 128],
1046 wServicePackMinor: 0,
1047 wSuiteMask: 0,
1048 wProductType: 0,
1049 wReserved: 0,
1050 };
1051
1052 let ret = unsafe {
1053 VerifyVersionInfoW(
1054 &mut osvi,
1055 VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR,
1056 condition_mask,
1057 )
1058 };
1059
1060 ret != FALSE
1061 }
1062
1063 // querying the local netserver management api?
1064 #[inline]
1065 fn um_netserver() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1066 unsafe {
1067 let mut buf = ptr::null_mut();
1068 match NetApiBufferAllocate(
1069 u32::try_from(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<SERVER_INFO_101>()).unwrap(),
1070 &mut buf,
1071 ) {
1072 0 => {}
1073 err => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::from_raw_os_error(i32::try_from(err).unwrap()).into()),
1074 }
1075
1076 let ret = match NetServerGetInfo(ptr::null_mut(), 101, buf as _) {
1077 0 => {
1078 let info: SERVER_INFO_101 = ptr::read(buf as _);
1079 let version = info.sv101_version_major | MAJOR_VERSION_MASK;
1080
1081 // IS it using the same magic version number? who the fuck knows. let's hope so.
1082 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(info.sv101_platform_id == SV_PLATFORM_ID_NT
1083 && version > ABRACADABRA_THRESHOLD.0 as _)
1084 }
1085 err => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::from_raw_os_error(i32::try_from(err).unwrap()).into()),
1086 };
1087
1088 // always free, even if the netservergetinfo call fails
1089 match NetApiBufferFree(buf) {
1090 0 => {}
1091 err => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::from_raw_os_error(i32::try_from(err).unwrap()).into()),
1092 }
1093
1094 ret
1095 }
1096 }
1097
1098 // querying the local workstation management api?
1099 #[inline]
1100 fn um_workstation() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1101 unsafe {
1102 let mut buf = ptr::null_mut();
1103 match NetApiBufferAllocate(
1104 u32::try_from(size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<WKSTA_INFO_100>()).unwrap(),
1105 &mut buf,
1106 ) {
1107 0 => {}
1108 err => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::from_raw_os_error(i32::try_from(err).unwrap()).into()),
1109 }
1110
1111 let ret = match NetWkstaGetInfo(ptr::null_mut(), 100, buf as _) {
1112 0 => {
1113 let info: WKSTA_INFO_100 = ptr::read(buf as _);
1114
1115 // IS it using the same magic version number? who the fuck knows. let's hope so.
1116 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(info.wki100_platform_id == SV_PLATFORM_ID_NT
1117 && info.wki100_ver_major > ABRACADABRA_THRESHOLD.0 as _)
1118 }
1119 err => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::from_raw_os_error(i32::try_from(err).unwrap()).into()),
1120 };
1121
1122 // always free, even if the netservergetinfo call fails
1123 match NetApiBufferFree(buf) {
1124 0 => {}
1125 err => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::from_raw_os_error(i32::try_from(err).unwrap()).into()),
1126 }
1127
1128 ret
1129 }
1130 }
1131
1132 // attempt to set the bit, then undo it
1133 fn vt_attempt() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1134 let stdout = console_handle()?;
1135
1136 let mut mode = 0;
1137 if unsafe { GetConsoleMode(stdout, &mut mode) } == FALSE {
1138 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(io::Error::last_os_error().into());
1139 }
1140
1141 let mut support = false;
1142
1143 let mut newmode = mode;
1144 newmode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
1145 if unsafe { SetConsoleMode(stdout, newmode) } != FALSE {
1146 support = true;
1147 }
1148
1149 // reset it to original value, whatever we do
1150 unsafe { SetConsoleMode(stdout, mode) };
1151
1152 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(support)
1153 }
1154
1155 #[inline]
1156 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn is_windows_10() -> bool {
1157 if um_verify_version() {
1158 return true;
1159 }
1160
1161 if um_netserver().unwrap_or(false) {
1162 return true;
1163 }
1164
1165 if um_workstation().unwrap_or(false) {
1166 return true;
1167 }
1168
1169 vt_attempt().unwrap_or(false)
1170 }
1171 }
1172
1173 #[cfg(not(unix))]
1174 #[allow(clippy::unnecessary_wraps)]
1175 mod unixrust-analyzer cargo clearscreen 4.0.2 unix/ {
1176 use superrust-analyzer cargo clearscreen 4.0.2 crate/::Errorrust-analyzer cargo clearscreen 4.0.2 Error#;
1177
1178 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn vt_cooked() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1179 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1180 }
1181
1182 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn vt_well_done() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1183 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1184 }
1185 }
1186
1187 #[cfg(not(windows))]
1188 #[allow(clippy::unnecessary_wraps)]
1189 mod winrust-analyzer cargo clearscreen 4.0.2 win/ {
1190 use superrust-analyzer cargo clearscreen 4.0.2 crate/::Errorrust-analyzer cargo clearscreen 4.0.2 Error#;
1191
1192 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn vtrust-analyzer cargo clearscreen 4.0.2 win/vt().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1193 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1194 }
1195
1196 #[cfg(feature = "windows-console")]
1197 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn clear() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1198 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1199 }
1200
1201 #[cfg(feature = "windows-console")]
1202 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn blank() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1203 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1204 }
1205
1206 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn cookedrust-analyzer cargo clearscreen 4.0.2 win/cooked().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo clearscreen 4.0.2 Error#> {
1207 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1208 }
1209
1210 #[inline]
1211 pub(craterust-analyzer cargo clearscreen 4.0.2 crate/) fn is_windows_10rust-analyzer cargo clearscreen 4.0.2 win/is_windows_10().() -> bool {
1212 false
1213 }
1214 }
1215
1216 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
1217 struct ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#<'a>(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [u8]>);
1218
1219 impl<'a> Capabilityrust-analyzer cargo terminfo 0.9.0 capability/Capability#<'a> for ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#<'a> {
1220 #[inline]
1221 fn namerust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`Capability<'a>`]name().() -> &'static str {
1222 "E3"
1223 }
1224
1225 #[inline]
1226 fn fromrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`Capability<'a>`]from().(value: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Valuerust-analyzer cargo terminfo 0.9.0 capability/Value#>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`Capability<'a>`]> {
1227 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Valuerust-analyzer cargo terminfo 0.9.0 capability/Value#::Stringrust-analyzer cargo terminfo 0.9.0 capability/Value#String#(value)) = value {
1228 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`Capability<'a>`](Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(value)))
1229 } else {
1230 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
1231 }
1232 }
1233
1234 #[inline]
1235 fn intorust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`Capability<'a>`]into().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Valuerust-analyzer cargo terminfo 0.9.0 capability/Value#> {
1236 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Valuerust-analyzer cargo terminfo 0.9.0 capability/Value#::Stringrust-analyzer cargo terminfo 0.9.0 capability/Value#String#(match self.0rust-analyzer cargo clearscreen 4.0.2 ResetScrollback#0. {
1237 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(value) => value.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
1238
1239 Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(value) => value,
1240 }))
1241 }
1242 }
1243
1244 impl<'a, T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<&'a [u8]>> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<T> for ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#<'a> {
1245 #[inline]
1246 fn fromrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`From<T>`]from().(value: T) -> Selfrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`From<T>`] {
1247 Selfrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'a>`][`From<T>`](Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()))
1248 }
1249 }
1250
1251 impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> for ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#<'_> {
1252 #[inline]
1253 fn as_refrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'_>`][`AsRef<[u8]>`]as_ref().(&self) -> &[u8] {
1254 &self.0rust-analyzer cargo clearscreen 4.0.2 ResetScrollback#0.
1255 }
1256 }
1257
1258 impl ResetScrollbackrust-analyzer cargo clearscreen 4.0.2 ResetScrollback#<'_> {
1259 #[inline]
1260 fn expandrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'_>`]expand().(&self) -> Expansionrust-analyzer cargo terminfo 0.9.0 capability/Expansion#<Selfrust-analyzer cargo clearscreen 4.0.2 impl#[`ResetScrollback<'_>`]> {
1261 #[allow(dead_code)]
1262 struct ExpansionHererust-analyzer cargo clearscreen 4.0.2 ExpansionHere#<'a, T: 'a + AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>> {
1263 stringrust-analyzer cargo clearscreen 4.0.2 ExpansionHere#string.: &'a T,
1264 paramsrust-analyzer cargo clearscreen 4.0.2 ExpansionHere#params.: [Parameterrust-analyzer cargo terminfo 0.9.0 expand/Parameter#; 9],
1265 contextrust-analyzer cargo clearscreen 4.0.2 ExpansionHere#context.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a mut Contextrust-analyzer cargo terminfo 0.9.0 expand/Context#>,
1266 }
1267
1268 let here = ExpansionHererust-analyzer cargo clearscreen 4.0.2 ExpansionHere# {
1269 stringrust-analyzer cargo clearscreen 4.0.2 ExpansionHere#string.: self,
1270 paramsrust-analyzer cargo clearscreen 4.0.2 ExpansionHere#params.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; _]`][Default]default().(),
1271 contextrust-analyzer cargo clearscreen 4.0.2 ExpansionHere#context.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1272 };
1273
1274 // UNSAFE >:( this is iffy af but also the only way to create an Expansion
1275 // such that we can add the E3 capability.
1276 unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().(here) }
1277 }
1278 }