par-term 0.48.0

Cross-platform GPU-accelerated terminal emulator with inline graphics support (Sixel, iTerm2, Kitty)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
//! Split pane operations: split, navigate, resize, close panes.

use std::sync::Arc;

use super::super::window_state::WindowState;

impl WindowState {
    /// Shared implementation for trigger- and keyboard-initiated pane splits.
    ///
    /// Handles renderer bounds query, tmux delegation, and the split call.
    /// Returns the new pane ID on success, None on failure.
    ///
    /// `initial_command` — when `Some((cmd, args))` the new pane launches that
    /// process directly instead of the login shell. The pane closes when the
    /// process exits.
    pub(crate) fn split_pane_direction(
        &mut self,
        direction: crate::pane::SplitDirection,
        focus_new: bool,
        initial_command: Option<(String, Vec<String>)>,
        split_percent: u8,
    ) -> Option<crate::pane::PaneId> {
        self.split_pane_placed(direction, false, focus_new, initial_command, split_percent)
    }

    /// Split the focused pane running `profile` (UX.md PR1 "Split with
    /// Profile"): the profile's program (env included), its working
    /// directory, focused, rebalanced like a keyboard split. Local panes
    /// only — the caller gates par-mux and tmux tabs
    /// (`split_with_profile`).
    pub(crate) fn split_pane_direction_with_profile(
        &mut self,
        direction: crate::pane::SplitDirection,
        profile: &crate::profile::Profile,
    ) -> Option<crate::pane::PaneId> {
        let config = self.config.load_full();
        let new_pane = self.split_pane_with(
            direction,
            false,
            crate::tab::SplitRequest {
                focus_new: true,
                dpi_scale: 1.0,
                initial_command: None,
                split_percent: 50,
                launch: Some(crate::tab::profile_split_launch(profile, &config)),
                cwd: profile.working_directory.clone(),
            },
        )?;
        let balance = config.panes.split_balance;
        let rebalanced = self
            .tab_manager
            .active_tab_mut()
            .and_then(|t| t.pane_manager_mut())
            .is_some_and(|pm| pm.balance_after_split(new_pane, balance));
        if rebalanced {
            self.after_pane_layout_change();
        }
        Some(new_pane)
    }

    /// [`Self::split_pane_direction`] with the new pane placed before (left
    /// of / above) the focused one when `before` is set (UX.md A5).
    pub(crate) fn split_pane_placed(
        &mut self,
        direction: crate::pane::SplitDirection,
        before: bool,
        focus_new: bool,
        initial_command: Option<(String, Vec<String>)>,
        split_percent: u8,
    ) -> Option<crate::pane::PaneId> {
        self.split_pane_with(
            direction,
            before,
            crate::tab::SplitRequest {
                focus_new,
                dpi_scale: 1.0,
                initial_command,
                split_percent,
                launch: None,
                cwd: None,
            },
        )
    }

    /// The split every entry point funnels into. `request.dpi_scale` is
    /// replaced with the renderer's; a profile split (UX.md PR1) carries
    /// its `launch` and `cwd` here.
    pub(crate) fn split_pane_with(
        &mut self,
        direction: crate::pane::SplitDirection,
        before: bool,
        mut request: crate::tab::SplitRequest,
    ) -> Option<crate::pane::PaneId> {
        let (max_panes, min_cells) = {
            let config = self.config.load();
            (config.panes.max_panes, config.panes.pane_min_size)
        };
        // Calculate status bar height for proper content area
        let is_tmux_connected = self.is_tmux_connected();
        let status_bar_height = crate::tmux_status_bar_ui::TmuxStatusBarUI::height(
            &self.config.load(),
            is_tmux_connected,
        );
        let custom_status_bar_height = self
            .status_bar_ui
            .height(&self.config.load(), self.is_fullscreen);

        // Get bounds info from renderer for proper pane sizing
        let bounds_info = self.renderer.as_ref().map(|r| {
            let size = r.size();
            let padding = r.window_padding();
            let content_offset_y = r.content_offset_y();
            let cell_width = r.cell_width();
            let cell_height = r.cell_height();
            let scale = r.scale_factor();
            (
                size,
                padding,
                content_offset_y,
                cell_width,
                cell_height,
                scale,
            )
        });
        let scrollbar_inset = self
            .renderer
            .as_ref()
            .map(|r| r.scrollbar_width())
            .unwrap_or(0.0);
        // After the split the tab has dividers: the render pass pads every
        // pane by half a divider plus pane_padding (gpu_submit).
        let split_pane_padding = {
            let config = self.config.load();
            config.panes.pane_divider_width.unwrap_or(2.0) / 2.0 + config.panes.pane_padding
        };

        let dpi_scale = bounds_info.map(|b| b.5).unwrap_or(1.0);

        let tab = self.tab_manager.active_tab_mut()?;

        // Set pane bounds before split if we have renderer info
        if let Some((size, padding, content_offset_y, cell_width, cell_height, scale)) = bounds_info
        {
            // After split there will be multiple panes, so use 0 padding if configured
            let effective_padding = if self.config.load().window.hide_window_padding_on_split {
                0.0
            } else {
                padding
            };
            // Scale status_bar_height from logical to physical pixels
            let physical_status_bar_height = (status_bar_height + custom_status_bar_height) * scale;
            let content_width = size.width as f32 - effective_padding * 2.0;
            let content_height = size.height as f32
                - content_offset_y
                - effective_padding
                - physical_status_bar_height;
            let bounds = crate::pane::PaneBounds::new(
                effective_padding,
                content_offset_y,
                content_width,
                content_height,
            );
            tab.set_pane_bounds(bounds, cell_width, cell_height);
            if let Some(pm) = tab.pane_manager_mut() {
                pm.set_min_pane_size(
                    min_cells,
                    (cell_width, cell_height),
                    crate::app::render_pipeline::pane_cell_overhead(
                        &self.config.load(),
                        split_pane_padding,
                        scrollbar_inset,
                        scale,
                    ),
                );
            }
        }
        let at_max = max_panes > 0 && tab.pane_count() >= max_panes;

        request.dpi_scale = dpi_scale;
        let result = tab.split_placed(
            direction,
            before,
            &self.config.load(),
            Arc::clone(&self.runtime),
            request,
        );

        match result {
            Ok(Some(pane_id)) => {
                log::info!("Split pane {:?}, new pane {}", direction, pane_id);
                // Clear renderer cells to remove stale single-pane data
                if let Some(renderer) = &mut self.renderer {
                    renderer.clear_all_cells();
                }
                // Invalidate tab cache — must re-borrow since we moved tab above
                if let Some(tab) = self.tab_manager.active_tab_mut() {
                    tab.active_cache_mut().cells = None;
                }
                // Start refresh tasks for all panes so secondary panes trigger redraws
                if let Some(window) = &self.window
                    && let Some(tab) = self.tab_manager.active_tab_mut()
                {
                    tab.start_pane_refresh_tasks(
                        Arc::clone(&self.runtime),
                        Arc::clone(window),
                        self.config.load().rendering.max_fps,
                        self.config.load().power.inactive_tab_fps,
                    );
                }
                self.focus_state.needs_redraw = true;
                self.request_redraw();
                Some(pane_id)
            }
            Ok(None) => {
                // PN10 / PN4: say why nothing happened.
                let reason = if at_max {
                    format!("Pane limit ({max_panes}) reached — change it in Settings › Panes")
                } else {
                    format!("Split refused: a pane would be smaller than {min_cells} cells")
                };
                log::info!("{direction:?} split refused: {reason}");
                self.show_toast(reason);
                None
            }
            Err(e) => {
                log::error!("Failed to split pane {:?}: {}", direction, e);
                None
            }
        }
    }

    /// Split the current pane horizontally (panes stacked top/bottom)
    pub fn split_pane_horizontal(&mut self) {
        // par-mux transport: split daemon-side — the daemon pane is the
        // real one; a native split here would create a local pane whose
        // input the mux router then starves.
        #[cfg(feature = "mux")]
        if self.split_pane_via_mux(false) {
            return;
        }
        // In tmux mode, send split command to tmux instead
        if self.is_tmux_connected() && self.split_pane_via_tmux(false) {
            crate::debug_info!("TMUX", "Sent horizontal split command to tmux");
            return;
        }
        // Fall through to local split if tmux command failed or not connected
        self.user_split(crate::pane::SplitDirection::Horizontal, false);
    }

    /// Split the current pane vertically (panes side by side)
    pub fn split_pane_vertical(&mut self) {
        // par-mux transport: split daemon-side — the daemon pane is the
        // real one; a native split here would create a local pane whose
        // input the mux router then starves.
        #[cfg(feature = "mux")]
        if self.split_pane_via_mux(true) {
            return;
        }
        // In tmux mode, send split command to tmux instead
        if self.is_tmux_connected() && self.split_pane_via_tmux(true) {
            crate::debug_info!("TMUX", "Sent vertical split command to tmux");
            return;
        }
        // Fall through to local split if tmux command failed or not connected
        self.user_split(crate::pane::SplitDirection::Vertical, false);
    }

    /// A keyboard or menu split of a local tab: the new pane is focused and
    /// the tab is rebalanced per `split_balance` (PN7). Trigger and snippet
    /// splits pass their own percent through `split_pane_direction` and are
    /// never rebalanced.
    pub(crate) fn user_split(&mut self, direction: crate::pane::SplitDirection, before: bool) {
        let Some(new_pane) = self.split_pane_placed(direction, before, true, None, 50) else {
            return;
        };
        let balance = self.config.load().panes.split_balance;
        let rebalanced = self
            .tab_manager
            .active_tab_mut()
            .and_then(|t| t.pane_manager_mut())
            .is_some_and(|pm| pm.balance_after_split(new_pane, balance));
        if rebalanced {
            self.after_pane_layout_change();
        }
    }

    /// Close the focused pane in the current tab
    ///
    /// If this is the last pane, the tab is closed.
    /// Returns true if the window should close (last tab was closed).
    pub fn close_focused_pane(&mut self) -> bool {
        // par-mux transport: close daemon-side — the daemon pane is the
        // real one; a native close here would delete the local pane and
        // dangle the tmux→native mapping while the daemon pane lives on.
        #[cfg(feature = "mux")]
        {
            // A mux tab's LAST pane must not be kill-pane'd: the daemon's
            // kill-pane on a window's only pane CLOSES the window (and an
            // emptied session) — destroying the session without warning
            // while the tab sat dead. Close the TAB instead, the Cmd+W
            // shape: the daemon window keeps running (recorded decision,
            // card 01a0d9b5568175c084eb7f9d70c0ec4f — the alternative,
            // confirming before a kill, is the heavier UX for the same
            // safety).
            if self.tmux_state.transport.is_some()
                && self.focused_mux_pane_from_native().is_some()
                && !self
                    .tab_manager
                    .active_tab()
                    .is_some_and(|tab| tab.has_multiple_panes())
            {
                crate::debug_info!(
                    "MUX",
                    "close of a mux tab's last pane — hiding the tab (D7)"
                );
                return self.hide_active_mux_tab();
            }
            if self.confirm_mux_pane_close() {
                return false; // the dialog decides
            }
            if self.close_pane_via_mux() {
                // Consumed: the daemon's %layout-change drives the local
                // removal, so the window-close answer is "not yet".
                return false;
            }
        }
        if self.is_tmux_connected() {
            // Display tabs show tmux window content but are not the gateway.  Closing
            // a pane via par-term's UI on a display tab should close the display tab
            // itself — not kill the underlying tmux pane.  Killing tmux panes is tmux's
            // responsibility (prefix+x, etc.).
            let active_tab_id = self.tab_manager.active_tab_id();
            let is_tmux_display_tab = active_tab_id
                .map(|id| {
                    self.tmux_state.tmux_gateway_tab_id.is_some()
                        && self.tmux_state.tmux_gateway_tab_id != Some(id)
                })
                .unwrap_or(false);

            if is_tmux_display_tab {
                crate::debug_info!(
                    "TMUX",
                    "close_focused_pane on display tab — closing display tab instead of kill-pane"
                );
                return self.close_current_tab_immediately();
            }

            // Gateway tab (or connected but display tab check failed): send kill-pane.
            if self.close_pane_via_tmux() {
                crate::debug_info!("TMUX", "Sent kill-pane command to tmux");
                // Don't close the local pane - wait for tmux layout change
                return false;
            }
        }
        // Fall through to local close if tmux command failed or not connected

        // Check if we need to show confirmation for running jobs
        if self.config.load().shell.confirm_close_running_jobs
            && let Some(command_name) = self.check_current_pane_running_job()
            && let Some(tab) = self.tab_manager.active_tab()
            && let Some(pane_id) = tab.focused_pane_id()
        {
            let tab_id = tab.id;
            let tab_title = if tab.title.is_empty() {
                "Terminal".to_string()
            } else {
                tab.title.clone()
            };
            self.overlay_ui.close_confirmation_ui.show_for_pane(
                tab_id,
                pane_id,
                &tab_title,
                &command_name,
            );
            self.focus_state.needs_redraw = true;
            self.request_redraw();
            return false; // Don't close yet, waiting for confirmation
        }

        self.close_focused_pane_immediately()
    }

    /// Whether the focused attached (par-mux) pane runs a foreground job
    /// that should hold a close for confirmation.
    #[cfg(feature = "mux")]
    fn check_mux_pane_running_job(&self) -> MuxJobCheck {
        match self.focused_mux_pane_from_native() {
            Some(pane) => self.check_mux_panes_running_job(&[pane]),
            None => MuxJobCheck::Idle,
        }
    }

    /// Whether any of `panes` (attached par-mux panes) runs a foreground
    /// job that should hold a close for confirmation.
    ///
    /// The job runs daemon-side, so the local hidden shell cannot answer:
    /// this asks the daemon (`pane-info`, foreground command name) and
    /// applies the same `jobs_to_ignore` list as the local check. The
    /// queries share one [`MUX_JOB_CHECK_BUDGET`] and do not queue behind a
    /// slow command already in flight on the attached connection. A daemon
    /// that ANSWERED without evidence of a job (an `%error` reply from a
    /// daemon without `pane-info`, a reply without the `cmd=` token) is
    /// `Idle`; one that could not be asked in time is `Unanswered`.
    #[cfg(feature = "mux")]
    pub(super) fn check_mux_panes_running_job(&self, panes: &[u64]) -> MuxJobCheck {
        let Some(transport) = self.tmux_state.transport.as_ref() else {
            return MuxJobCheck::Idle;
        };
        let deadline = std::time::Instant::now() + MUX_JOB_CHECK_BUDGET;
        for &pane in panes {
            let budget = deadline.saturating_duration_since(std::time::Instant::now());
            let reply = match transport.query_bounded(&format!("pane-info -t %{pane}"), budget) {
                Ok(reply) => reply,
                Err(e) => {
                    log::warn!("par-mux pane-info failed, confirming close unverified: {e}");
                    return MuxJobCheck::Unanswered;
                }
            };
            if let Some(job) =
                par_term_mux::pane_foreground_command(&reply, pane).and_then(|name| {
                    mux_foreground_job(&name, &self.config.load().shell.jobs_to_ignore)
                })
            {
                return MuxJobCheck::Job(job);
            }
        }
        MuxJobCheck::Idle
    }

    /// Show the running-job close confirmation for the focused attached
    /// pane. Returns true when the dialog is now up and the close must wait
    /// for its answer; false when the close may proceed. A check the daemon
    /// could not answer fails closed: the dialog opens saying so.
    #[cfg(feature = "mux")]
    fn confirm_mux_pane_close(&mut self) -> bool {
        if !self.config.load().shell.confirm_close_running_jobs {
            return false;
        }
        let check = self.check_mux_pane_running_job();
        if matches!(check, MuxJobCheck::Idle) {
            return false;
        }
        let Some(tab) = self.tab_manager.active_tab() else {
            return false;
        };
        let Some(pane_id) = tab.focused_pane_id() else {
            return false;
        };
        let tab_id = tab.id;
        let tab_title = if tab.title.is_empty() {
            "Terminal".to_string()
        } else {
            tab.title.clone()
        };
        let dialog = &mut self.overlay_ui.close_confirmation_ui;
        match check {
            MuxJobCheck::Job(command_name) => {
                dialog.show_for_pane(tab_id, pane_id, &tab_title, &command_name);
            }
            _ => dialog.show_for_pane_unverified(tab_id, pane_id, &tab_title),
        }
        self.focus_state.needs_redraw = true;
        self.request_redraw();
        true
    }

    /// Close the focused pane after the running-job dialog was confirmed.
    ///
    /// An attached pane must die daemon-side (`kill-pane`), the same route
    /// as an unconfirmed close: the immediate local close would delete the
    /// mirror pane while the daemon process lives on. A mux tab that has
    /// meanwhile shrunk to its last pane takes the last-pane route (hide
    /// the tab, keep the daemon window). Local panes close as before.
    pub(crate) fn close_focused_pane_confirmed(&mut self) -> bool {
        #[cfg(feature = "mux")]
        if self.tmux_state.transport.is_some() && self.focused_mux_pane_from_native().is_some() {
            if self
                .tab_manager
                .active_tab()
                .is_some_and(|tab| tab.has_multiple_panes())
            {
                if self.close_pane_via_mux() {
                    return false;
                }
            } else {
                return self.hide_active_mux_tab();
            }
        }
        self.close_focused_pane_immediately()
    }

    /// Close the focused pane immediately without confirmation
    /// Returns true if the window should close (last tab was closed).
    pub(crate) fn close_focused_pane_immediately(&mut self) -> bool {
        if let Some(tab) = self.tab_manager.active_tab_mut()
            && tab.has_multiple_panes()
        {
            let is_last_pane = tab.close_focused_pane();
            if is_last_pane {
                // Last pane closed, close the tab
                return self.close_current_tab_immediately();
            }
            self.focus_state.needs_redraw = true;
            self.request_redraw();
            return false;
        }
        // Single pane or no tab, close the tab
        self.close_current_tab_immediately()
    }

    /// Check if the current pane's terminal has a running job that should trigger confirmation
    ///
    /// Returns Some(command_name) if confirmation should be shown, None otherwise.
    pub(super) fn check_current_pane_running_job(&self) -> Option<String> {
        let tab = self.tab_manager.active_tab()?;

        // If the tab has split panes, check the focused pane
        if tab.has_multiple_panes() {
            let pane_manager = tab.pane_manager()?;
            let focused_id = pane_manager.focused_pane_id()?;
            let pane = pane_manager.get_pane(focused_id)?;
            // blocking_read: user-initiated close — must not silently skip confirmation.
            // should_confirm_close() only needs &self; read lock is correct.
            let term = pane.terminal.blocking_read();
            log::info!(
                "[CLOSE_CONFIRM] check_current_pane_running_job (split pane): marker={:?} command={:?}",
                term.shell_integration_marker(),
                term.shell_integration_command()
            );
            return term.should_confirm_close(&self.config.load().shell.jobs_to_ignore);
        }

        // Single pane - use the tab's terminal.
        // blocking_read: user-initiated close — must not silently skip confirmation.
        let term = tab.terminal.blocking_read();
        log::info!(
            "[CLOSE_CONFIRM] check_current_pane_running_job (single pane): marker={:?} command={:?} is_running={}",
            term.shell_integration_marker(),
            term.shell_integration_command(),
            term.is_command_running()
        );
        term.should_confirm_close(&self.config.load().shell.jobs_to_ignore)
    }

    /// Check if the current tab has multiple panes
    pub fn has_multiple_panes(&self) -> bool {
        self.tab_manager
            .active_tab()
            .is_some_and(|tab| tab.has_multiple_panes())
    }

    /// Navigate to an adjacent pane in the given direction
    pub fn navigate_pane(&mut self, direction: crate::pane::NavigationDirection) {
        if let Some(tab) = self.tab_manager.active_tab_mut()
            && tab.has_multiple_panes()
        {
            tab.navigate_pane(direction);
            self.after_user_pane_focus();
        }
    }

    /// Swap the focused pane with its neighbor in the given direction.
    /// In mux mode the swap is daemon-side (`swap_pane_via_mux`) — the
    /// daemon owns the layout — so the local mirror only re-lays-out from
    /// the reply's %layout-change broadcast. Local tabs swap the pane
    /// tree directly.
    pub fn swap_pane(&mut self, direction: crate::pane::NavigationDirection) {
        #[cfg(feature = "mux")]
        if self.swap_pane_via_mux(direction) {
            self.focus_state.needs_redraw = true;
            self.request_redraw();
            return;
        }
        if let Some(tab) = self.tab_manager.active_tab_mut()
            && tab.has_multiple_panes()
        {
            tab.swap_pane(direction);
            self.focus_state.needs_redraw = true;
            self.request_redraw();
        }
    }
}

/// How long a close waits for the daemon to report its panes' foreground
/// jobs. It runs on the event loop, so it bounds the stall a hung daemon can
/// cause; past it the close is held for confirmation rather than skipped.
#[cfg(feature = "mux")]
const MUX_JOB_CHECK_BUDGET: std::time::Duration = std::time::Duration::from_secs(1);

/// What the daemon said about the closing attached panes' foreground jobs.
#[cfg(feature = "mux")]
pub(super) enum MuxJobCheck {
    /// No job to protect (or no daemon pane to ask about).
    Idle,
    /// This job is running.
    Job(String),
    /// The daemon could not be asked in time.
    Unanswered,
}

/// The job name to confirm a close for, given the daemon's foreground
/// command basename: an idle pane reports its shell (a login shell's argv0
/// carries a leading `-`), and anything on `jobs_to_ignore` is not a job.
#[cfg(feature = "mux")]
fn mux_foreground_job(name: &str, jobs_to_ignore: &[String]) -> Option<String> {
    let name = name.trim_start_matches('-');
    if name.is_empty() {
        return None;
    }
    let lower = name.to_lowercase();
    if jobs_to_ignore
        .iter()
        .any(|ignored| ignored.to_lowercase() == lower)
    {
        return None;
    }
    Some(name.to_string())
}

#[cfg(all(test, feature = "mux"))]
mod tests {
    use super::mux_foreground_job;

    fn ignore() -> Vec<String> {
        par_term_config::defaults::jobs_to_ignore()
    }

    #[test]
    fn an_idle_shell_is_not_a_job() {
        assert_eq!(mux_foreground_job("-zsh", &ignore()), None);
        assert_eq!(mux_foreground_job("bash", &ignore()), None);
        assert_eq!(mux_foreground_job("Fish", &ignore()), None);
    }

    #[test]
    fn a_foreground_program_is_a_job_unless_ignored() {
        assert_eq!(mux_foreground_job("vim", &ignore()).as_deref(), Some("vim"));
        // sleep is on the default ignore list, exactly as for local tabs.
        assert_eq!(mux_foreground_job("sleep", &ignore()), None);
        assert_eq!(
            mux_foreground_job("sleep", &["cat".to_string()]).as_deref(),
            Some("sleep")
        );
    }
}