Debian Codegraph @

src/canvas/dialogs/process_kill_dialog.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 //! A dialog box to handle killing processes.
2
•3 use craterust-analyzer cargo bottom 0.14.9 crate/::utilsrust-analyzer cargo bottom 0.14.9 utils/::stringsrust-analyzer cargo bottom 0.14.9 utils/strings/::truncate_strrust-analyzer cargo bottom 0.14.9 utils/strings/truncate_str().;
4
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#;
6
7 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
8 use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::ListStaterust-analyzer cargo ratatui-widgets 0.3.2 list/state/ListState#;
9 use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::{
10 Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#,
11 layoutrust-analyzer cargo ratatui-core 0.1.2 layout/::{Alignmentrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/Alignment#, Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#, Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#, Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#, Positionrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position#, Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#},
12 textrust-analyzer cargo ratatui-core 0.1.2 text/::{Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#, Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#, Textrust-analyzer cargo ratatui-core 0.1.2 text/text/Text#},
13 widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::{Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#, Wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap#},
14 };
15
16 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
17 use craterust-analyzer cargo bottom 0.14.9 crate/::canvasrust-analyzer cargo bottom 0.14.9 canvas/::componentsrust-analyzer cargo bottom 0.14.9 canvas/components/::scroll_barrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/::{
18 ScrollBarArgsrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#, dialog_scroll_bar_arearust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/dialog_scroll_bar_area()., draw_scroll_barrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/draw_scroll_bar().,
19 };
20 use craterust-analyzer cargo bottom 0.14.9 crate/::{
21 canvasrust-analyzer cargo bottom 0.14.9 canvas/::drawing_utilsrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/::dialog_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/dialog_block()., collectionrust-analyzer cargo bottom 0.14.9 collection/::processesrust-analyzer cargo bottom 0.14.9 collection/processes/::Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#, optionsrust-analyzer cargo bottom 0.14.9 options/::configrust-analyzer cargo bottom 0.14.9 options/config/::stylerust-analyzer cargo bottom 0.14.9 options/config/style/::Stylesrust-analyzer cargo bottom 0.14.9 options/config/style/Styles#,
22 };
23
24 // Configure signal text based on the target OS.
25 cfg_selectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/cfg_select!! {
26 target_os = "linux" => {
27 const DEFAULT_KILL_SIGNALrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/DEFAULT_KILL_SIGNAL.: usize = 15;
28 const SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT.: [&str; 63] = [
29 "0: Cancel",
30 "1: HUP",
31 "2: INT",
32 "3: QUIT",
33 "4: ILL",
34 "5: TRAP",
35 "6: ABRT",
36 "7: BUS",
37 "8: FPE",
38 "9: KILL",
39 "10: USR1",
40 "11: SEGV",
41 "12: USR2",
42 "13: PIPE",
43 "14: ALRM",
44 "15: TERM",
45 "16: STKFLT",
46 "17: CHLD",
47 "18: CONT",
48 "19: STOP",
49 "20: TSTP",
50 "21: TTIN",
51 "22: TTOU",
52 "23: URG",
53 "24: XCPU",
54 "25: XFSZ",
55 "26: VTALRM",
56 "27: PROF",
57 "28: WINCH",
58 "29: IO",
59 "30: PWR",
60 "31: SYS",
61 "34: RTMIN",
62 "35: RTMIN+1",
63 "36: RTMIN+2",
64 "37: RTMIN+3",
65 "38: RTMIN+4",
66 "39: RTMIN+5",
67 "40: RTMIN+6",
68 "41: RTMIN+7",
69 "42: RTMIN+8",
70 "43: RTMIN+9",
71 "44: RTMIN+10",
72 "45: RTMIN+11",
73 "46: RTMIN+12",
74 "47: RTMIN+13",
75 "48: RTMIN+14",
76 "49: RTMIN+15",
77 "50: RTMAX-14",
78 "51: RTMAX-13",
79 "52: RTMAX-12",
80 "53: RTMAX-11",
81 "54: RTMAX-10",
82 "55: RTMAX-9",
83 "56: RTMAX-8",
84 "57: RTMAX-7",
85 "58: RTMAX-6",
86 "59: RTMAX-5",
87 "60: RTMAX-4",
88 "61: RTMAX-3",
89 "62: RTMAX-2",
90 "63: RTMAX-1",
91 "64: RTMAX",
92 ];
93 }
94 target_os = "macos" => {
95 const DEFAULT_KILL_SIGNAL: usize = 15;
96 const SIGNAL_TEXT: [&str; 32] = [
97 "0: Cancel",
98 "1: HUP",
99 "2: INT",
100 "3: QUIT",
101 "4: ILL",
102 "5: TRAP",
103 "6: ABRT",
104 "7: EMT",
105 "8: FPE",
106 "9: KILL",
107 "10: BUS",
108 "11: SEGV",
109 "12: SYS",
110 "13: PIPE",
111 "14: ALRM",
112 "15: TERM",
113 "16: URG",
114 "17: STOP",
115 "18: TSTP",
116 "19: CONT",
117 "20: CHLD",
118 "21: TTIN",
119 "22: TTOU",
120 "23: IO",
121 "24: XCPU",
122 "25: XFSZ",
123 "26: VTALRM",
124 "27: PROF",
125 "28: WINCH",
126 "29: INFO",
127 "30: USR1",
128 "31: USR2",
129 ];
130 }
131 target_os = "freebsd" => {
132 const DEFAULT_KILL_SIGNAL: usize = 15;
133 const SIGNAL_TEXT: [&str; 34] = [
134 "0: Cancel",
135 "1: HUP",
136 "2: INT",
137 "3: QUIT",
138 "4: ILL",
139 "5: TRAP",
140 "6: ABRT",
141 "7: EMT",
142 "8: FPE",
143 "9: KILL",
144 "10: BUS",
145 "11: SEGV",
146 "12: SYS",
147 "13: PIPE",
148 "14: ALRM",
149 "15: TERM",
150 "16: URG",
151 "17: STOP",
152 "18: TSTP",
153 "19: CONT",
154 "20: CHLD",
155 "21: TTIN",
156 "22: TTOU",
157 "23: IO",
158 "24: XCPU",
159 "25: XFSZ",
160 "26: VTALRM",
161 "27: PROF",
162 "28: WINCH",
163 "29: INFO",
164 "30: USR1",
165 "31: USR2",
166 "32: THR",
167 "33: LIBRT",
168 ];
169 }
170 _ => {}
171 }
172
173 /// Button state type for a [`ProcessKillDialog`].
174 ///
175 /// Simple only has two buttons (yes/no), while signals (AKA advanced) are
176 /// a list of signals to send.
177 ///
178 /// Note that signals are not available for Windows.
179 #[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:)]
180 pub(craterust-analyzer cargo bottom 0.14.9 crate/) enum ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState# {
181 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
182 Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# {
183 staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state.: ListStaterust-analyzer cargo ratatui-widgets 0.3.2 list/state/ListState#,
184 last_button_draw_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#last_button_draw_area.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#,
185 },
186 Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# {
187 yesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#yes.: bool,
188 last_yes_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_yes_button_area.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#,
189 last_no_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_no_button_area.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#,
190 },
191 }
192
193 #[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:)]
194 struct ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
195 process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#process_name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
196 pidsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#pids.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#>,
197 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#,
198 }
199
200 /// The current state of the process kill dialog.
201 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
202 enum ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState# {
203 #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:]
204 NotEnabledrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#NotEnabled#,
205 Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#),
206 Errorrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error# {
207 process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#process_name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
208 pidrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#pid.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#>,
209 errrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#err.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
210 },
211 }
212
213 /// Process kill dialog.
214 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
215 pub(craterust-analyzer cargo bottom 0.14.9 crate/) struct ProcessKillDialogrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog# {
216 staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.: ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#,
217 last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(char, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#)>,
218 }
219
220 impl ProcessKillDialogrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog# {
221 pub fn resetrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]reset().(&mut self) {
222 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = Selfrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]::defaultrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog][Default]default().();
223 }
224
225 #[inline]
226 pub fn is_openrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]is_open().(&self) -> bool {
227 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state., ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::NotEnabledrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#NotEnabled#))
228 }
229
230 pub fn on_escrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_esc().(&mut self) {
231 self.resetrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]reset().();
232 }
233
234 pub fn on_enterrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_enter().(&mut self) {
235 // We do this to get around borrow issues.
236 let mut current = ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::NotEnabledrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#NotEnabled#;
237 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/::swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/swap().(&mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state., &mut current);
238
239 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(state) = current {
240 let process_name = state.process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#process_name.;
241 let button_state = state.button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.;
242 let pids = state.pidsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#pids.;
243
244 match button_state {
245 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
246 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state., .. } => {
247 use craterust-analyzer cargo bottom 0.14.9 crate/::utilsrust-analyzer cargo bottom 0.14.9 utils/::process_killerrust-analyzer cargo bottom 0.14.9 utils/process_killer/;
248
249 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(selected) = state.selectedrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]selected().()
250 && selected rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0
251 {
252 let signal = get_signal_from_indexrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/get_signal_from_index().(selected);
253
254 for pid in pids {
255 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) = process_killerrust-analyzer cargo bottom 0.14.9 utils/process_killer/::kill_process_given_pidrust-analyzer cargo bottom 0.14.9 utils/process_killer/kill_process_given_pid().(pid, signal) {
256 self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state. = ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Errorrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error# {
257 process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#process_name.,
258 pidrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#pid.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pid),
259 errrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#err.: err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
260 };
261 return;
262 }
263 }
264 }
265 }
266 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# { yesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#yes., .. } => {
267 if yes {
268 cfg_selectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/cfg_select!! {
269 target_os = "windows" => {
270 use crate::utils::process_killer;
271
272 for pid in pids {
273 if let Err(err) = process_killer::kill_process_given_pid(pid) {
274 self.state = ProcessKillDialogState::Error { process_name, pid: Some(pid), err: err.to_string() };
275 break;
276 }
277 }
278 }
279 any(target_os = "linux", target_os = "macos", target_os = "freebsd") => {
280 use craterust-analyzer cargo bottom 0.14.9 crate/::utilsrust-analyzer cargo bottom 0.14.9 utils/::process_killerrust-analyzer cargo bottom 0.14.9 utils/process_killer/;
281
282 for pid in pids {
283 // Send a SIGTERM by default.
284 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) = process_killerrust-analyzer cargo bottom 0.14.9 utils/process_killer/::kill_process_given_pidrust-analyzer cargo bottom 0.14.9 utils/process_killer/kill_process_given_pid().(pid, DEFAULT_KILL_SIGNALrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/DEFAULT_KILL_SIGNAL.) {
285 self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state. = ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Errorrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error# { process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#process_name., pidrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#pid.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pid), errrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#err.: err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() };
286 break;
287 }
288 }
289 }
290 _ => {
291 self.state = ProcessKillDialogState::Error { process_name, pid: None, err: "Killing processes is not supported on this platform.".into() };
292
293 }
294 }
295 }
296 }
297 }
298 }
299
300 // Fall through behaviour is just to close the dialog.
301 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
302 }
303
304 pub fn on_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_char().(&mut self, c: char) {
305 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
306 const MAX_KEY_TIMEOUTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/MAX_KEY_TIMEOUT.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration# = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(1);
307
308 match c {
309 'h' => self.on_left_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_left_key().(),
310 'j' => self.on_down_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_down_key().(),
311 'k' => self.on_up_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_up_key().(),
312 'l' => self.on_right_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_right_key().(),
313 '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
314 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
315 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = c.to_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_digit().(10)
316 && let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
317 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state., .. },
318 ..
319 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
320 {
321 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((prev, last_press)) = self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. {
322 if prev.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().() && last_press.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().MAX_KEY_TIMEOUTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/MAX_KEY_TIMEOUT. {
323 let current = state.selectedrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]selected().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0);
324 let new = {
325 let new = current rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().value as usize;
326
327 // Note that 32 and 33 are skipped on linux.
328 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_os = "linux") {
329 if new rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().32 || new rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().33 {
330 value as usize
331 } else if new rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().34 {
332 new rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().2
333 } else {
334 new
335 }
336 } else {
337 new
338 }
339 };
340
341 if new rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
342 // If the new value is too large, then just assume we instead
343 // want the value itself.
344 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value as usize));
345 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((c, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().()));
346 } else {
347 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new));
348 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
349 }
350 } else {
351 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value as usize));
352 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((c, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().()));
353 }
354 } else {
355 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value as usize));
356 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((c, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().()));
357 }
358
359 return; // Needed to avoid accidentally clearing last_char.
360 }
361 }
362 'g' => {
363 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
364 {
365 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('g', last_press)) = self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. {
366 if last_press.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().MAX_KEY_TIMEOUTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/MAX_KEY_TIMEOUT. {
367 self.go_to_firstrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]go_to_first().();
368 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
369 } else {
370 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('g', Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().()));
371 }
372 } else {
373 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(('g', Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().()));
374 }
375 return;
376 }
377 }
378 'G' => {
379 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
380 self.go_to_lastrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]go_to_last().();
381 }
382 _ => {}
383 }
384
385 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
386 }
387
388 /// Handle a click at the given coordinates. Returns true if the click was
389 /// handled, false otherwise.
390 pub fn on_clickrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_click().(&mut self, x: u16, y: u16) -> bool {
391 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(state) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state. {
392 match &mut state.button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state. {
393 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
394 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# {
395 staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state.,
396 last_button_draw_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#last_button_draw_area.,
397 } => {
398 if last_button_draw_area.containsrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect]contains().(Positionrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position# { xrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position#x., yrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position#y. }) {
399 let relative_y =
400 y.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(last_button_draw_area.yrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#y.) as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().state.offsetrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]offset().();
401 if relative_y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
402 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(relative_y));
403 }
404 }
405 }
406 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# {
407 yesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#yes.,
408 last_yes_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_yes_button_area.,
409 last_no_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_no_button_area.,
410 } => {
411 if last_yes_button_area.containsrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect]contains().(Positionrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position# { xrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position#x., yrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position#y. }) {
412 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().yes = true;
413 } else if last_no_button_area.containsrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect]contains().(Positionrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position# { xrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position#x., yrust-analyzer cargo ratatui-core 0.1.2 layout/position/Position#y. }) {
414 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().yes = false;
415 }
416 }
417 }
418 }
419
420 false
421 }
422
423 /// Scroll up in the signal list.
424 pub fn on_scroll_uprust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_scroll_up().(&mut self) {
425 self.on_up_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_up_key().();
426 }
427
428 /// Scroll down in the signal list.
429 pub fn on_scroll_downrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_scroll_down().(&mut self) {
430 self.on_down_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_down_key().();
431 }
432
433 /// Handle a left key press.
434 pub fn on_left_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_left_key().(&mut self) {
435 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
436
437 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
438 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# { yesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#yes., .. },
439 ..
440 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
441 {
442 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().yes = true;
443 }
444 }
445
446 /// Handle a right key press.
447 pub fn on_right_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_right_key().(&mut self) {
448 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
449
450 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
451 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# { yesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#yes., .. },
452 ..
453 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
454 {
455 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().yes = false;
456 }
457 }
458
459 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
460 fn scroll_up_byrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]scroll_up_by().(state: &mut ListStaterust-analyzer cargo ratatui-widgets 0.3.2 list/state/ListState#, amount: usize) {
461 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(selected) = state.selectedrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]selected().() {
462 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new_position) = selected.checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_sub().(amount) {
463 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new_position));
464 } else {
465 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0));
466 }
467 }
468 }
469
470 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
471 fn scroll_down_byrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]scroll_down_by().(state: &mut ListStaterust-analyzer cargo ratatui-widgets 0.3.2 list/state/ListState#, amount: usize) {
472 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(selected) = state.selectedrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]selected().() {
473 let new_position = selected rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().amount;
474 if new_position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
475 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new_position));
476 } else {
477 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1));
478 }
479 }
480 }
481
482 /// Handle an up key press.
483 pub fn on_up_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_up_key().(&mut self) {
484 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
485
486 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
487 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
488 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state., .. },
489 ..
490 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
491 {
492 Selfrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]::scroll_up_byrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]scroll_up_by().(state, 1);
493 }
494 }
495
496 /// Handle a down key press.
497 pub fn on_down_keyrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_down_key().(&mut self) {
498 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
499
500 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
501 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
502 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state., .. },
503 ..
504 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
505 {
506 Selfrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]::scroll_down_byrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]scroll_down_by().(state, 1);
507 }
508 }
509
510 // Handle page up.
511 pub fn on_page_uprust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_page_up().(&mut self) {
512 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
513
514 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
515 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
516 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.:
517 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# {
518 staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state.,
519 last_button_draw_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#last_button_draw_area.,
520 ..
521 },
522 ..
523 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
524 {
525 Selfrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]::scroll_up_byrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]scroll_up_by().(state, last_button_draw_area.heightrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#height. as usize);
526 }
527 }
528
529 /// Handle page down.
530 pub fn on_page_downrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]on_page_down().(&mut self) {
531 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
532
533 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
534 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
535 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.:
536 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# {
537 staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state.,
538 last_button_draw_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#last_button_draw_area.,
539 ..
540 },
541 ..
542 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
543 {
544 Selfrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]::scroll_down_byrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]scroll_down_by().(state, last_button_draw_area.heightrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#height. as usize);
545 }
546 }
547
548 pub fn go_to_firstrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]go_to_first().(&mut self) {
549 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
550
551 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
552 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
553 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state., .. },
554 ..
555 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
556 {
557 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0));
558 }
559 }
560
561 pub fn go_to_lastrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]go_to_last().(&mut self) {
562 self.last_charrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#last_char. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
563
564 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
565 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
566 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state., .. },
567 ..
568 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
569 {
570 state.selectrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]select().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1));
571 }
572 }
573
574 /// Enable the process kill process.
575 pub fn start_process_killrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]start_process_kill().(
576 &mut self, process_name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, pids: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#>, use_simple_selection: bool,
577 ) {
578 let button_state = if use_simple_selection {
579 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# {
580 yesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#yes.: false,
581 last_yes_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_yes_button_area.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect][Default]default().(),
582 last_no_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_no_button_area.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect][Default]default().(),
583 }
584 } else {
585 cfg_selectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/cfg_select!! {
586 any(target_os = "linux", target_os = "macos", target_os = "freebsd") => {
587 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state.: ListStaterust-analyzer cargo ratatui-widgets 0.3.2 list/state/ListState#::defaultrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState][Default]default().().with_selectedrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]with_selected().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DEFAULT_KILL_SIGNALrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/DEFAULT_KILL_SIGNAL.)), last_button_draw_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#last_button_draw_area.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect][Default]default().() }
588 }
589 _ => {
590 ButtonState::Simple { yes: false, last_yes_button_area: Rect::default(), last_no_button_area: Rect::default()}
591 }
592 }
593 };
594
595 if pids.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
596 self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state. = ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Errorrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error# {
597 process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#process_name.,
598 pidrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#pid.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
599 errrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#err.: "No PIDs found for the given process name.".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
600 };
601 return;
602 }
603
604 self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state. = ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
605 process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#process_name.,
606 pidsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#pids.,
607 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.,
608 });
609 }
610
611 pub fn handle_redrawrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]handle_redraw().(&mut self) {
612 // FIXME: Not sure if we need this. We can probably handle this better in the
613 // draw function later.
614
615 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
616 {
617 if let ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
618 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.: ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state., .. },
619 ..
620 }) = &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state.
621 {
622 // Fix the button offset state when we do things like resize.
623 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().state.offset_mutrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]offset_mut().() = 0;
624 }
625 }
626 }
627
628 #[inline]
629 fn draw_selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]draw_selecting().(
630 f: &mut Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#<'_>, draw_area: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#, styles: &Stylesrust-analyzer cargo bottom 0.14.9 options/config/style/Styles#, state: &mut ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#,
631 ) {
632 let ProcessKillSelectingInnerrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner# {
633 process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#process_name.,
634 pidsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#pids.,
635 button_staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillSelectingInner#button_state.,
636 ..
637 } = state;
638
639 // FIXME: Add some colour to this!
640 let text = {
641 const MAX_PROCESS_NAME_WIDTHrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/MAX_PROCESS_NAME_WIDTH.: usize = 20;
642
643 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first_pid) = pids.firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().() {
644 let truncated_process_name =
•645 truncate_strrust-analyzer cargo bottom 0.14.9 utils/strings/truncate_str().(process_name, MAX_PROCESS_NAME_WIDTHrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/MAX_PROCESS_NAME_WIDTH.);
646
647 let text = if pids.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 {
648 Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'_>`][`From<String>`]from().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
649 "Kill {} processes with the name '{}'? Press ENTER to confirm.",
650 pids.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
651 truncated_process_name
652 ))
653 } else {
654 Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'_>`][`From<String>`]from().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
655 "Kill process '{truncated_process_name}' with PID {first_pid}? Press ENTER to confirm."
656 ))
657 };
658
659 Textrust-analyzer cargo ratatui-core 0.1.2 text/text/Text#::fromrust-analyzer cargo ratatui-core 0.1.2 text/text/impl#[`Text<'a>`][`From<Vec<Line<'a>>>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![text])
660 } else {
661 Textrust-analyzer cargo ratatui-core 0.1.2 text/text/Text#::fromrust-analyzer cargo ratatui-core 0.1.2 text/text/impl#[`Text<'a>`][`From<Vec<Line<'a>>>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
662 "Could not find process to kill.".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
663 "Please press ENTER or ESC to close this dialog.".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
664 ])
665 }
666 };
667
668 let text: Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#<'_> = Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#::newrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]new().(text)
669 .stylerust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]style().(styles.text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)
670 .alignmentrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]alignment().(Alignmentrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/Alignment#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/HorizontalAlignment#Center#)
671 .wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]wrap().(Wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap# { trimrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap#trim.: true });
672
673 let title = match button_state {
674 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
675 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# { .. } => {
676 Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Select Signal ", styles.widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.)
677 }
678 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# { .. } => {
679 Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Confirm Kill Process ", styles.widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.)
680 }
681 };
682
683 let block = dialog_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/dialog_block().(styles.border_typerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_type., styles.border_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_style.)
684 .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(title)
685 .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Esc to close ", styles.widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.).right_alignedrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]right_aligned().());
686
687 let num_lines = text.line_countrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]line_count().(block.innerrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]inner().(draw_area).widthrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#width.) as u16;
688
689 match button_state {
690 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
691 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Signalsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals# {
692 staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#state.,
693 last_button_draw_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Signals#last_button_draw_area.,
694 } => {
695 use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::Listrust-analyzer cargo ratatui-widgets 0.3.2 list/List#;
696
697 // A list of options, displayed vertically.
698 const SIGNAL_TEXT_LENrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT_LEN.: u16 = SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u16;
699
700 // Make the rect only as big as it needs to be, which is the height of the text,
701 // the buttons, and up to 2 spaces (margin and space between), and the size of
702 // the block.
703 let [draw_area] =
704 Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::verticalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]vertical().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Maxrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Max#(num_lines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().SIGNAL_TEXT_LENrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT_LEN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().3)])
705 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#Center#)
706 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(draw_area);
707
708 // Now we need to divide the block into one area for the paragraph,
709 // and one for the buttons.
710 let [text_draw_area, button_draw_area] = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::verticalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]vertical().([
711 Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Maxrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Max#(num_lines),
712 Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Maxrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Max#(SIGNAL_TEXT_LENrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT_LEN.),
713 ])
714 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::SpaceEvenlyrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#SpaceEvenly#)
715 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(block.innerrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]inner().(draw_area));
716
717 // Render the block.
718 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(block, draw_area);
719
720 // Now render the text.
721 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(text, text_draw_area);
722
723 // And the tricky part, rendering the buttons.
724 let selected = state
725 .selectedrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]selected().()
726 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("the list state should always be initialized with a selection!");
727
728 let buttons = Listrust-analyzer cargo ratatui-widgets 0.3.2 list/List#::newrust-analyzer cargo ratatui-widgets 0.3.2 list/impl#[`List<'a>`]new().(SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(index, &signal)| {
729 let style = if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().selected {
730 styles.selected_text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#selected_text_style.
731 } else {
732 styles.text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.
733 };
734
735 Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().(signal, style)
736 }));
737
738 // This is kinda dumb how you have to set the constraint, but ok.
739 const LONGEST_SIGNAL_TEXT_LENGTHrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/LONGEST_SIGNAL_TEXT_LENGTH.: u16 = const {
740 let mut i = 0;
741 let mut max = 0;
742 while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
743 if SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().max {
744 max = SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
745 }
746 i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
747 }
748
749 max as u16
750 };
751
752 let [list_area] =
753 Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::horizontalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]horizontal().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Lengthrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Length#(LONGEST_SIGNAL_TEXT_LENGTHrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/LONGEST_SIGNAL_TEXT_LENGTH.)])
754 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#Center#)
755 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(button_draw_area);
756
757 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().last_button_draw_area = list_area;
758 f.render_stateful_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_stateful_widget().(buttons, list_area, state);
759
760 draw_scroll_barrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/draw_scroll_bar().(
761 f,
762 dialog_scroll_bar_arearust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/dialog_scroll_bar_area().(draw_area),
763 ScrollBarArgsrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs# {
764 content_lengthrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#content_length.: SIGNAL_TEXTrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/SIGNAL_TEXT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(),
765 viewport_lengthrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#viewport_length.: list_area.heightrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#height. as usize,
766 positionrust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#position.: state.selectedrust-analyzer cargo ratatui-widgets 0.3.2 list/state/impl#[ListState]selected().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0),
767 stylerust-analyzer cargo bottom 0.14.9 canvas/components/scroll_bar/ScrollBarArgs#style.: styles.text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.,
768 },
769 );
770 }
771 ButtonStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#::Simplerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple# {
772 yesrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#yes.,
773 last_yes_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_yes_button_area.,
774 last_no_button_arearust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ButtonState#Simple#last_no_button_area.,
775 } => {
776 // Make the rect only as big as it needs to be, which is the height of the text,
777 // the buttons, and up to 3 spaces (margin and space between) + 2 for block.
778 let [draw_area] = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::verticalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]vertical().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Maxrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Max#(num_lines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().2)])
779 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#Center#)
780 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(draw_area);
781
782 // Now we need to divide the block into one area for the paragraph,
783 // and one for the buttons.
784 let [text_area, button_area] =
785 Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::verticalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]vertical().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Maxrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Max#(num_lines), Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Lengthrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Length#(1)])
786 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::SpaceEvenlyrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#SpaceEvenly#)
787 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(block.innerrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]inner().(draw_area));
788
789 // Render things, starting from the block.
790 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(block, draw_area);
791 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(text, text_area);
792
793 let (yes, no) = {
794 let (yes_style, no_style) = if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().yes {
795 (styles.selected_text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#selected_text_style., styles.text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)
796 } else {
797 (styles.text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style., styles.selected_text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#selected_text_style.)
798 };
799
800 (
801 Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#::newrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]new().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().("Yes", yes_style)),
802 Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#::newrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]new().(Spanrust-analyzer cargo ratatui-core 0.1.2 text/span/Span#::styledrust-analyzer cargo ratatui-core 0.1.2 text/span/impl#[`Span<'a>`]styled().("No", no_style)),
803 )
804 };
805
806 let [yes_area, no_area] = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::horizontalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]horizontal().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Lengthrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Length#(3); 2])
807 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::SpaceEvenlyrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#SpaceEvenly#)
808 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(button_area);
809
810 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().last_yes_button_area = yes_area;
811 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().last_no_button_area = no_area;
812
813 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(yes, yes_area);
814 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(no, no_area);
815 }
816 }
817 }
818
819 #[inline]
820 fn draw_no_button_dialogrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]draw_no_button_dialog().(
821 &self, f: &mut Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#<'_>, draw_area: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#, styles: &Stylesrust-analyzer cargo bottom 0.14.9 options/config/style/Styles#, text: Textrust-analyzer cargo ratatui-core 0.1.2 text/text/Text#<'_>, title: Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#<'_>,
822 ) {
823 let text = Paragraphrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Paragraph#::newrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]new().(text)
824 .stylerust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]style().(styles.text_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#text_style.)
825 .alignmentrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]alignment().(Alignmentrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/Alignment#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/HorizontalAlignment#Center#)
826 .wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]wrap().(Wraprust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap# { trimrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/Wrap#trim.: true });
827
828 let block = dialog_blockrust-analyzer cargo bottom 0.14.9 canvas/drawing_utils/dialog_block().(styles.border_typerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_type., styles.border_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#border_style.)
829 .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(title)
830 .title_toprust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]title_top().(Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Esc to close ", styles.widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.).right_alignedrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]right_aligned().());
831
832 let num_lines = text.line_countrust-analyzer cargo ratatui-widgets 0.3.2 paragraph/impl#[`Paragraph<'a>`]line_count().(block.innerrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]inner().(draw_area).widthrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#width.) as u16;
833
834 // Also calculate how big of a draw loc we actually need. For this
835 // one, we want it to be shorter if possible.
836 //
837 // Note the +2 is for the margin, and another +2 for border.
838 let [draw_area] = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::verticalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]vertical().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Maxrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Max#(num_lines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().2)])
839 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#Center#)
840 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(draw_area);
841
842 let [text_draw_area] = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::verticalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]vertical().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Lengthrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Length#(num_lines)])
843 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#Center#)
844 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(block.innerrust-analyzer cargo ratatui-widgets 0.3.2 block/impl#[`Block<'a>`]inner().(draw_area));
845
846 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(block, draw_area);
847 f.render_widgetrust-analyzer cargo ratatui-core 0.1.2 terminal/frame/impl#[`Frame<'_>`]render_widget().(text, text_draw_area);
848 }
849
850 /// Draw the [`ProcessKillDialog`].
851 pub fn drawrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]draw().(&mut self, f: &mut Framerust-analyzer cargo ratatui-core 0.1.2 terminal/frame/Frame#<'_>, draw_area: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#, styles: &Stylesrust-analyzer cargo bottom 0.14.9 options/config/style/Styles#) {
852 // The idea is:
853 // - Use as big of a dialog box as needed (within the maximal draw loc)
854 // - So the non-button ones are going to be smaller... probably whatever the
855 // height of the text is.
856 // - Meanwhile for the button one, it'll likely be full height if it's
857 // "advanced" kill.
858
859 const MAX_DIALOG_WIDTHrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/MAX_DIALOG_WIDTH.: u16 = 100;
860 let [draw_area] = Layoutrust-analyzer cargo ratatui-core 0.1.2 layout/layout/Layout#::horizontalrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]horizontal().([Constraintrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#::Maxrust-analyzer cargo ratatui-core 0.1.2 layout/constraint/Constraint#Max#(MAX_DIALOG_WIDTHrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/MAX_DIALOG_WIDTH.)])
861 .flexrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]flex().(Flexrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/flex/Flex#Center#)
862 .areasrust-analyzer cargo ratatui-core 0.1.2 layout/layout/impl#[Layout]areas().(draw_area);
863
864 // FIXME: Add some colour to this!
865 match &mut self.staterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialog#state. {
866 ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::NotEnabledrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#NotEnabled# => {}
867 ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Selecting#(state) => {
868 // Draw a text box. If buttons are yes/no, fit it, otherwise, use max space.
869 Selfrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]::draw_selectingrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]draw_selecting().(f, draw_area, styles, state);
870 }
871 ProcessKillDialogStaterust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#::Errorrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error# {
872 process_namerust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#process_name.,
873 pidrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#pid.,
874 errrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/ProcessKillDialogState#Error#err.,
875 } => {
876 let text = Textrust-analyzer cargo ratatui-core 0.1.2 text/text/Text#::fromrust-analyzer cargo ratatui-core 0.1.2 text/text/impl#[`Text<'a>`][`From<Vec<Line<'a>>>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
877 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pid) = pid {
878 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to kill process {process_name} ({pid}):").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
879 } else {
880 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to kill process '{process_name}':").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
881 },
882 err.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
883 "Please press ENTER or ESC to close this dialog.".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
884 ])
885 .alignmentrust-analyzer cargo ratatui-core 0.1.2 text/text/impl#[`Text<'a>`]alignment().(Alignmentrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/Alignment#::Centerrust-analyzer cargo ratatui-core 0.1.2 layout/alignment/HorizontalAlignment#Center#);
886 let title = Linerust-analyzer cargo ratatui-core 0.1.2 text/line/Line#::styledrust-analyzer cargo ratatui-core 0.1.2 text/line/impl#[`Line<'a>`]styled().(" Error ", styles.widget_title_stylerust-analyzer cargo bottom 0.14.9 options/config/style/Styles#widget_title_style.);
887
888 self.draw_no_button_dialogrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/impl#[ProcessKillDialog]draw_no_button_dialog().(f, draw_area, styles, text, title);
889 }
890 }
891 }
892 }
893
894 /// Return the signal number to send given the index on a list.
895 ///
896 /// On Linux, we need to skip 32 and 33, so we add 2 to the index if it's >= 32.
897 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
898 fn get_signal_from_indexrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/get_signal_from_index().(index: usize) -> usize {
899 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_os = "linux") && index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().32 {
900 index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2
901 } else {
902 index
903 }
904 }
905
906 #[cfg(test)]
907 mod testsrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/tests/ {
908 #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
909 use superrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/::*;
910
911 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
912 #[cfg(target_os = "linux")]
913 fn test_getting_signal_from_index_on_linuxrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/tests/test_getting_signal_from_index_on_linux().() {
914 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_indexrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/get_signal_from_index().(0), 0);
915 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_indexrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/get_signal_from_index().(31), 31);
916 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_indexrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/get_signal_from_index().(32), 34);
917 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_indexrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/get_signal_from_index().(33), 35);
918 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_indexrust-analyzer cargo bottom 0.14.9 canvas/dialogs/process_kill_dialog/get_signal_from_index().(34), 36);
919 }
920
921 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
922 #[cfg(any(target_os = "macos", target_os = "freebsd"))]
923 fn test_getting_signal_from_index_not_on_linux() {
924 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_index(0), 0);
925 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_index(31), 31);
926 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_index(32), 32);
927 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_index(33), 33);
928 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(get_signal_from_index(34), 34);
929 }
930 }