aboutsummaryrefslogtreecommitdiffstats
path: root/default-plugins/layout-manager/src/screens/mod.rs
blob: d9d617be9e0efc37af728c5909d3d8c30df555cc (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
74
75
76
77
78
79
mod import_layout;
mod layout_list;
mod new_layout_from_session;
mod rename_layout;

use zellij_tile::prelude::LayoutMetadata;

pub use import_layout::ImportLayoutScreen;
pub use layout_list::LayoutListScreen;
pub use new_layout_from_session::NewLayoutFromCurrentSessionScreen;
pub use rename_layout::RenameLayoutScreen;

// Re-export error types from errors module for convenience
pub use crate::errors::{ErrorDetailScreen, ErrorScreen};

#[derive(Clone)]
pub enum Screen {
    LayoutList(LayoutListScreen),
    NewLayoutFromSession(NewLayoutFromCurrentSessionScreen),
    ImportLayout(ImportLayoutScreen),
    RenameLayout(RenameLayoutScreen),
    Error(ErrorScreen),
    ErrorDetail(ErrorDetailScreen),
}

impl Default for Screen {
    fn default() -> Self {
        Screen::LayoutList(LayoutListScreen::default())
    }
}

/// Optimistic state updates to apply before Zellij confirms
#[derive(Clone, Debug)]
pub enum OptimisticUpdate {
    Delete(String), // file_name
    Rename {
        old_name: String,
        new_name: String,
    },
    Add {
        name: String,
        metadata: LayoutMetadata,
    },
}

/// Response from screen key handlers
#[derive(Default)]
pub struct KeyResponse {
    pub should_render: bool,
    pub new_screen: Option<Screen>,
    pub optimistic_update: Option<OptimisticUpdate>,
}

impl KeyResponse {
    pub fn render() -> Self {
        KeyResponse {
            should_render: true,
            new_screen: None,
            optimistic_update: None,
        }
    }

    pub fn new_screen(screen: Screen) -> Self {
        KeyResponse {
            should_render: true,
            new_screen: Some(screen),
            optimistic_update: None,
        }
    }

    pub fn with_optimistic(mut self, update: OptimisticUpdate) -> Self {
        self.optimistic_update = Some(update);
        self
    }

    pub fn none() -> Self {
        KeyResponse::default()
    }
}