diff options
author | Jae-Heon Ji <32578710+jaeheonji@users.noreply.github.com> | 2021-11-09 03:43:51 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 19:43:51 +0100 |
commit | 4838f0b52cdd0f8369b8842f6496efb949402250 (patch) | |
tree | 035270a14ef5a65a6e0b5df97e7fa7f7fdd648c7 /zellij-utils/src/input | |
parent | b232326dc2b419467914f00a04e472e81379891f (diff) |
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
Diffstat (limited to 'zellij-utils/src/input')
-rw-r--r-- | zellij-utils/src/input/layout.rs | 17 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/fixtures/layouts/session-name-to-layout.yaml | 3 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/layout_test.rs | 22 |
3 files changed, 42 insertions, 0 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 2bbc8cb48..df976b8e1 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -144,6 +144,8 @@ pub struct Layout { #[serde(default)] pub struct LayoutFromYaml { #[serde(default)] + pub session: SessionFromYaml, + #[serde(default)] pub template: LayoutTemplate, #[serde(default)] pub borderless: bool, @@ -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![], diff --git a/zellij-utils/src/input/unit/fixtures/layouts/session-name-to-layout.yaml b/zellij-utils/src/input/unit/fixtures/layouts/session-name-to-layout.yaml new file mode 100644 index 000000000..144d555b9 --- /dev/null +++ b/zellij-utils/src/input/unit/fixtures/layouts/session-name-to-layout.yaml @@ -0,0 +1,3 @@ +--- +session: + name: "zellij-session" diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index dc8969251..2ec66a2a0 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -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); +} |