diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-09 04:40:50 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-04-09 04:42:35 +0300 |
| commit | bb2c579df206e51d43833544d114f321423c997c (patch) | |
| tree | a26c6702e048f31429ebaa260ee40c3c2b111d3e /src | |
| parent | 5460a9601ea8dd3d05e64e97040c71c6be29172b (diff) | |
feat(cli): support labels when creating tabs and workspaces
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/schema.rs | 5 | ||||
| -rw-r--r-- | src/app/mod.rs | 28 | ||||
| -rw-r--r-- | src/cli.rs | 27 |
3 files changed, 53 insertions, 7 deletions
diff --git a/src/api/schema.rs b/src/api/schema.rs index 568a276b..42a9c259 100644 --- a/src/api/schema.rs +++ b/src/api/schema.rs @@ -93,6 +93,8 @@ pub struct WorkspaceCreateParams { pub cwd: Option<String>, #[serde(default)] pub focus: bool, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub label: Option<String>, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -109,6 +111,8 @@ pub struct TabCreateParams { pub cwd: Option<String>, #[serde(default)] pub focus: bool, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub label: Option<String>, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] @@ -688,6 +692,7 @@ mod tests { method: Method::WorkspaceCreate(WorkspaceCreateParams { cwd: Some("/tmp".into()), focus: true, + label: Some("api".into()), }), }; diff --git a/src/app/mod.rs b/src/app/mod.rs index a39ed436..8d089a9d 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1069,6 +1069,11 @@ impl App { .unwrap_or_else(|| std::path::PathBuf::from("/")); match self.create_workspace_with_options(cwd, params.focus) { Ok(index) => { + if let Some(label) = params.label { + if let Some(workspace) = self.state.workspaces.get_mut(index) { + workspace.set_custom_name(label); + } + } let workspace = self.workspace_info(index); self.emit_event(crate::api::schema::EventEnvelope { event: crate::api::schema::EventKind::WorkspaceCreated, @@ -1280,7 +1285,13 @@ impl App { } } Method::TabCreate(params) => { - let ws_idx = if let Some(workspace_id) = params.workspace_id { + let crate::api::schema::TabCreateParams { + workspace_id, + cwd, + focus, + label, + } = params; + let ws_idx = if let Some(workspace_id) = workspace_id { let Some(ws_idx) = self.parse_workspace_id(&workspace_id) else { return serde_json::to_string(&ErrorResponse { id: request.id, @@ -1304,8 +1315,7 @@ impl App { }) .unwrap(); }; - let cwd = params - .cwd + let cwd = cwd .map(std::path::PathBuf::from) .or_else(|| { self.state.workspaces.get(ws_idx).and_then(|ws| { @@ -1333,7 +1343,17 @@ impl App { }); match result { Ok(tab_idx) => { - if params.focus { + if let Some(label) = label { + if let Some(tab) = self + .state + .workspaces + .get_mut(ws_idx) + .and_then(|ws| ws.tabs.get_mut(tab_idx)) + { + tab.set_custom_name(label); + } + } + if focus { self.state.switch_workspace(ws_idx); self.state.switch_tab(tab_idx); self.state.mode = Mode::Terminal; @@ -144,6 +144,7 @@ fn workspace_list(args: &[String]) -> std::io::Result<i32> { fn workspace_create(args: &[String]) -> std::io::Result<i32> { let mut cwd = None; let mut focus = true; + let mut label = None; let mut index = 0; while index < args.len() { @@ -156,6 +157,14 @@ fn workspace_create(args: &[String]) -> std::io::Result<i32> { cwd = Some(value.clone()); index += 2; } + "--label" => { + let Some(value) = args.get(index + 1) else { + eprintln!("missing value for --label"); + return Ok(2); + }; + label = Some(value.clone()); + index += 2; + } "--no-focus" => { focus = false; index += 1; @@ -169,7 +178,7 @@ fn workspace_create(args: &[String]) -> std::io::Result<i32> { print_response(&send_request(&Request { id: "cli:workspace:create".into(), - method: Method::WorkspaceCreate(WorkspaceCreateParams { cwd, focus }), + method: Method::WorkspaceCreate(WorkspaceCreateParams { cwd, focus, label }), })?) } @@ -273,6 +282,7 @@ fn tab_create(args: &[String]) -> std::io::Result<i32> { let mut workspace_id = None; let mut cwd = None; let mut focus = true; + let mut label = None; let mut index = 0; while index < args.len() { @@ -293,6 +303,14 @@ fn tab_create(args: &[String]) -> std::io::Result<i32> { cwd = Some(value.clone()); index += 2; } + "--label" => { + let Some(value) = args.get(index + 1) else { + eprintln!("missing value for --label"); + return Ok(2); + }; + label = Some(value.clone()); + index += 2; + } "--no-focus" => { focus = false; index += 1; @@ -310,6 +328,7 @@ fn tab_create(args: &[String]) -> std::io::Result<i32> { workspace_id, cwd, focus, + label, }), })?) } @@ -1055,7 +1074,7 @@ fn parse_u64_flag(flag: &str, value: &str) -> std::io::Result<u64> { fn print_workspace_help() { eprintln!("herdr workspace commands:"); eprintln!(" herdr workspace list"); - eprintln!(" herdr workspace create [--cwd PATH] [--no-focus]"); + eprintln!(" herdr workspace create [--cwd PATH] [--label TEXT] [--no-focus]"); eprintln!(" herdr workspace get <workspace_id>"); eprintln!(" herdr workspace focus <workspace_id>"); eprintln!(" herdr workspace rename <workspace_id> <label>"); @@ -1065,7 +1084,9 @@ fn print_workspace_help() { fn print_tab_help() { eprintln!("herdr tab commands:"); eprintln!(" herdr tab list [--workspace <workspace_id>]"); - eprintln!(" herdr tab create [--workspace <workspace_id>] [--cwd PATH] [--no-focus]"); + eprintln!( + " herdr tab create [--workspace <workspace_id>] [--cwd PATH] [--label TEXT] [--no-focus]" + ); eprintln!(" herdr tab get <tab_id>"); eprintln!(" herdr tab focus <tab_id>"); eprintln!(" herdr tab rename <tab_id> <label>"); |
