feat: add initial session name to layout template (#789)
* feat: add session configuration to layout template WIP: prototyping for issue #611 * test(layout): add session name * feat(layout): add cond flow to check session name * feat(layout): update session * feat: add function to attach a session * fix(layout): update feedback * attach option only works when layout template exists. * feat(layout): add conditional for session-layout * update default attach value
This commit is contained in:
parent
b232326dc2
commit
4838f0b52c
4 changed files with 108 additions and 17 deletions
|
|
@ -211,17 +211,65 @@ pub(crate) fn start_client(opts: CliArgs) {
|
|||
attach_layout,
|
||||
);
|
||||
} else {
|
||||
let session_name = opts
|
||||
.session
|
||||
.clone()
|
||||
.unwrap_or_else(|| names::Generator::default().next().unwrap());
|
||||
let start_client_plan = |session_name: std::string::String| {
|
||||
assert_session_ne(&session_name);
|
||||
|
||||
// Determine and initialize the data directory
|
||||
let data_dir = opts.data_dir.clone().unwrap_or_else(get_default_data_dir);
|
||||
#[cfg(not(disable_automatic_asset_installation))]
|
||||
populate_data_dir(&data_dir);
|
||||
};
|
||||
|
||||
if let Some(session_name) = opts.session.clone() {
|
||||
start_client_plan(session_name.clone());
|
||||
start_client_impl(
|
||||
Box::new(os_input),
|
||||
opts,
|
||||
config,
|
||||
config_options,
|
||||
ClientInfo::New(session_name),
|
||||
layout,
|
||||
);
|
||||
} else {
|
||||
if let Some(layout_some) = layout.clone() {
|
||||
if let Some(session_name) = layout_some.session.name {
|
||||
if layout_some.session.attach.unwrap() {
|
||||
let client = attach_with_session_name(
|
||||
Some(session_name),
|
||||
config_options.clone(),
|
||||
true,
|
||||
);
|
||||
|
||||
let attach_layout = match client {
|
||||
ClientInfo::Attach(_, _) => None,
|
||||
ClientInfo::New(_) => layout,
|
||||
};
|
||||
|
||||
start_client_impl(
|
||||
Box::new(os_input),
|
||||
opts,
|
||||
config,
|
||||
config_options,
|
||||
client,
|
||||
attach_layout,
|
||||
);
|
||||
} else {
|
||||
start_client_plan(session_name.clone());
|
||||
start_client_impl(
|
||||
Box::new(os_input),
|
||||
opts,
|
||||
config,
|
||||
config_options,
|
||||
ClientInfo::New(session_name),
|
||||
layout,
|
||||
);
|
||||
}
|
||||
|
||||
process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
let session_name = names::Generator::default().next().unwrap();
|
||||
start_client_plan(session_name.clone());
|
||||
start_client_impl(
|
||||
Box::new(os_input),
|
||||
opts,
|
||||
|
|
@ -232,3 +280,4 @@ pub(crate) fn start_client(opts: CliArgs) {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ pub struct Layout {
|
|||
#[serde(crate = "self::serde")]
|
||||
#[serde(default)]
|
||||
pub struct LayoutFromYaml {
|
||||
#[serde(default)]
|
||||
pub session: SessionFromYaml,
|
||||
#[serde(default)]
|
||||
pub template: LayoutTemplate,
|
||||
#[serde(default)]
|
||||
|
|
@ -245,6 +247,20 @@ impl LayoutFromYaml {
|
|||
}
|
||||
}
|
||||
|
||||
// The struct that is used to deserialize the session from
|
||||
// a yaml configuration file
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
|
||||
#[serde(crate = "self::serde")]
|
||||
pub struct SessionFromYaml {
|
||||
pub name: Option<String>,
|
||||
#[serde(default = "default_as_some_true")]
|
||||
pub attach: Option<bool>,
|
||||
}
|
||||
|
||||
fn default_as_some_true() -> Option<bool> {
|
||||
Some(true)
|
||||
}
|
||||
|
||||
// The struct that carries the information template that is used to
|
||||
// construct the layout
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||
|
|
@ -591,6 +607,7 @@ impl Default for LayoutTemplate {
|
|||
impl Default for LayoutFromYaml {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
session: SessionFromYaml::default(),
|
||||
template: LayoutTemplate::default(),
|
||||
borderless: false,
|
||||
tabs: vec![],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
session:
|
||||
name: "zellij-session"
|
||||
|
|
@ -719,3 +719,25 @@ fn no_layout_template_merged_correctly() {
|
|||
|
||||
assert_eq!(merged_layout, tab_layout.try_into().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn session_name_to_layout_is_ok() {
|
||||
let path = layout_test_dir("session-name-to-layout.yaml".into());
|
||||
let layout_from_yaml = LayoutFromYaml::new(&path);
|
||||
assert!(layout_from_yaml.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn session_name_to_layout_has_name() {
|
||||
let path = layout_test_dir("session-name-to-layout.yaml".into());
|
||||
let layout_from_yaml = LayoutFromYaml::new(&path);
|
||||
let layout_template = layout_from_yaml.unwrap();
|
||||
let session_layout = layout_template.session;
|
||||
|
||||
let expected_session = SessionFromYaml {
|
||||
name: Some(String::from("zellij-session")),
|
||||
attach: Some(true),
|
||||
};
|
||||
|
||||
assert_eq!(expected_session, session_layout);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue