feat(core): serialize workspace state
test / workspace (push) Successful in 11m55s

This commit is contained in:
Tom You
2026-07-06 23:59:11 -05:00
parent 9a61ff4a79
commit 2f1b9fcd5d
4 changed files with 40 additions and 8 deletions
Generated
+4
View File
@@ -2300,6 +2300,10 @@ dependencies = [
[[package]] [[package]]
name = "rabby-core" name = "rabby-core"
version = "0.1.0" version = "0.1.0"
dependencies = [
"serde",
"serde_json",
]
[[package]] [[package]]
name = "raw-window-handle" name = "raw-window-handle"
+6
View File
@@ -7,3 +7,9 @@ repository.workspace = true
[lib] [lib]
path = "src/lib.rs" path = "src/lib.rs"
[dependencies]
serde = { version = "1", features = ["derive"] }
[dev-dependencies]
serde_json = "1"
+3 -2
View File
@@ -1,13 +1,14 @@
use crate::{ConnectionKind, Profile}; use crate::{ConnectionKind, Profile};
use serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ShortcutBinding { pub struct ShortcutBinding {
pub command: String, pub command: String,
pub binding: String, pub binding: String,
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AppConfig { pub struct AppConfig {
pub profiles: Vec<Profile>, pub profiles: Vec<Profile>,
pub theme_id: String, pub theme_id: String,
+27 -6
View File
@@ -1,6 +1,7 @@
use crate::slug; use crate::slug;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ConnectionKind { pub enum ConnectionKind {
LocalShell, LocalShell,
Ssh, Ssh,
@@ -8,7 +9,7 @@ pub enum ConnectionKind {
Serial, Serial,
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Profile { pub struct Profile {
pub id: String, pub id: String,
pub name: String, pub name: String,
@@ -38,7 +39,7 @@ impl Profile {
} }
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PaneNode { pub enum PaneNode {
Leaf { Leaf {
profile_id: String, profile_id: String,
@@ -51,7 +52,7 @@ pub enum PaneNode {
}, },
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SplitAxis { pub enum SplitAxis {
Horizontal, Horizontal,
Vertical, Vertical,
@@ -89,14 +90,14 @@ impl PaneNode {
} }
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Tab { pub struct Tab {
pub title: String, pub title: String,
pub root: PaneNode, pub root: PaneNode,
pub progress: Option<u8>, pub progress: Option<u8>,
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Workspace { pub struct Workspace {
pub profiles: Vec<Profile>, pub profiles: Vec<Profile>,
pub tabs: Vec<Tab>, pub tabs: Vec<Tab>,
@@ -239,4 +240,24 @@ mod tests {
assert_eq!(ws.tabs[0].progress, Some(42)); assert_eq!(ws.tabs[0].progress, Some(42));
assert!(ws.set_tab_progress(0, Some(101)).is_err()); assert!(ws.set_tab_progress(0, Some(101)).is_err());
} }
#[test]
fn workspace_round_trips_nested_splits() {
let mut ws = Workspace::default_linux();
ws.add_profile(
Profile::new("ssh-prod", "Prod SSH", ConnectionKind::Ssh, "ssh prod").unwrap(),
)
.unwrap();
ws.tabs[0].root = PaneNode::leaf("local")
.split(SplitAxis::Horizontal, PaneNode::leaf("ssh-prod"), 55)
.unwrap();
ws.set_quake_mode(true);
let encoded = serde_json::to_string(&ws).unwrap();
let decoded: Workspace = serde_json::from_str(&encoded).unwrap();
assert_eq!(decoded, ws);
assert_eq!(decoded.tabs[0].root.leaf_count(), 2);
assert!(decoded.quake_mode);
}
} }