aboutsummaryrefslogtreecommitdiffstats
path: root/default-plugins/sequence/src/state/layout.rs
blob: 65a267e022dd2ba302b1a57e50caa12e8835588c (plain) (blame)
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
use crate::state::positioning;
use std::path::PathBuf;
use zellij_tile::prelude::*;

pub struct Layout {
    pub needs_reposition: bool,
    pub cached_cursor_position: Option<(usize, usize)>,
    pub spinner_frame: usize,
    pub spinner_timer_scheduled: bool,
}

impl Layout {
    pub fn new() -> Self {
        Self {
            needs_reposition: false,
            cached_cursor_position: None,
            spinner_frame: 0,
            spinner_timer_scheduled: false,
        }
    }

    pub fn reposition_plugin_based_on_sequence_state(
        &mut self,
        is_running: bool,
        first_command_pane_id: Option<PaneId>,
        pane_manifest: &PaneManifest,
        plugin_id: Option<u32>,
        total_viewport_columns: Option<usize>,
        total_viewport_rows: Option<usize>,
        total_commands: usize,
        _selected_index: Option<usize>,
        _running_index: usize,
        _cwd: &Option<PathBuf>,
    ) {
        let Some(plugin_id) = plugin_id else {
            return;
        };
        let (Some(total_cols), Some(total_rows)) = (total_viewport_columns, total_viewport_rows)
        else {
            return;
        };

        if !self.needs_reposition || !is_running {
            return;
        }

        let Some(first_pane_id) = first_command_pane_id else {
            return;
        };

        for (_tab_index, panes) in &pane_manifest.panes {
            for pane in panes {
                if !pane.is_plugin && PaneId::Terminal(pane.id) == first_pane_id {
                    positioning::reposition_plugin_for_sequence(
                        plugin_id,
                        total_cols,
                        total_rows,
                        total_commands,
                    );

                    self.needs_reposition = false;
                    return;
                }
            }
        }
    }
}

impl Default for Layout {
    fn default() -> Self {
        Self::new()
    }
}