par_term/pane/manager/
session.rs1use super::PaneManager;
7use crate::config::Config;
8use crate::pane::types::{Pane, PaneNode};
9use crate::session::SessionPaneNode;
10use anyhow::Result;
11use std::sync::Arc;
12use tokio::runtime::Runtime;
13
14impl PaneManager {
15 pub fn build_from_layout(
25 &mut self,
26 layout: &SessionPaneNode,
27 config: &Config,
28 runtime: Arc<Runtime>,
29 ) -> Result<()> {
30 let root = self.build_node_from_layout(layout, config, runtime)?;
31 let first_id = root.all_pane_ids().first().copied();
32 self.root = Some(root);
33 self.focused_pane_id = first_id;
34 self.recalculate_bounds();
35
36 let panes = self.all_panes_mut();
38 for (index, pane) in panes.into_iter().enumerate() {
39 if let Some((image_path, mode, opacity, darken)) = config.get_pane_background(index) {
40 pane.set_background(crate::pane::PaneBackground {
41 image_path: Some(image_path),
42 mode,
43 opacity,
44 darken,
45 });
46 }
47 }
48
49 Ok(())
50 }
51
52 fn build_node_from_layout(
54 &mut self,
55 layout: &SessionPaneNode,
56 config: &Config,
57 runtime: Arc<Runtime>,
58 ) -> Result<PaneNode> {
59 match layout {
60 SessionPaneNode::Leaf { cwd, user_title } => {
61 let id = self.next_pane_id;
62 self.next_pane_id += 1;
63
64 let validated_cwd = crate::session::restore::validate_cwd(cwd);
65 let mut pane = Pane::new(id, config, runtime, validated_cwd)?;
66 if let Some(title) = user_title.as_deref().filter(|t| !t.is_empty()) {
70 pane.user_named = true;
71 pane.has_default_title = false;
72 pane.title = title.to_string();
73 }
74 Ok(PaneNode::leaf(pane))
75 }
76 SessionPaneNode::Split {
77 direction,
78 ratio,
79 first,
80 second,
81 } => {
82 let first_node = self.build_node_from_layout(first, config, runtime.clone())?;
83 let second_node = self.build_node_from_layout(second, config, runtime)?;
84 Ok(PaneNode::split(*direction, *ratio, first_node, second_node))
85 }
86 }
87 }
88}