Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,17 @@ mod tests {
Ok(())
}

fn apply_task_status_bar(
&self,
_session_name: &str,
_category_title: &str,
_task_title: &str,
_branch_name: &str,
_color_seed: &str,
) -> Result<()> {
Ok(())
}

fn switch_client(
&self,
session_name: &str,
Expand Down
66 changes: 64 additions & 2 deletions src/app/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use crate::git::{
};
use crate::process::command;
use crate::tmux::{
PopupThemeStyle, sanitize_session_name_for_project, tmux_create_session, tmux_kill_session,
tmux_open_session_in_new_terminal, tmux_session_exists, tmux_show_popup, tmux_switch_client,
PopupThemeStyle, sanitize_session_name_for_project, tmux_apply_task_status_bar,
tmux_create_session, tmux_kill_session, tmux_open_session_in_new_terminal, tmux_session_exists,
tmux_show_popup, tmux_switch_client,
};

/// Runtime trait for task recovery operations
Expand All @@ -20,6 +21,14 @@ pub trait RecoveryRuntime {
fn worktree_exists(&self, worktree_path: &Path) -> bool;
fn session_exists(&self, session_name: &str) -> bool;
fn create_session(&self, session_name: &str, working_dir: &Path, command: &str) -> Result<()>;
fn apply_task_status_bar(
&self,
session_name: &str,
category_title: &str,
task_title: &str,
branch_name: &str,
color_seed: &str,
) -> Result<()>;
fn switch_client(
&self,
session_name: &str,
Expand Down Expand Up @@ -56,6 +65,23 @@ impl RecoveryRuntime for RealRecoveryRuntime {
tmux_create_session(session_name, working_dir, Some(command))
}

fn apply_task_status_bar(
&self,
session_name: &str,
category_title: &str,
task_title: &str,
branch_name: &str,
color_seed: &str,
) -> Result<()> {
tmux_apply_task_status_bar(
session_name,
category_title,
task_title,
branch_name,
color_seed,
)
}

fn switch_client(
&self,
session_name: &str,
Expand Down Expand Up @@ -109,6 +135,14 @@ pub trait CreateTaskRuntime {
working_dir: &Path,
command: Option<&str>,
) -> Result<()>;
fn tmux_apply_task_status_bar(
&self,
session_name: &str,
category_title: &str,
task_title: &str,
branch_name: &str,
color_seed: &str,
) -> Result<()>;
fn tmux_kill_session(&self, session_name: &str) -> Result<()>;
}

Expand Down Expand Up @@ -225,6 +259,23 @@ impl CreateTaskRuntime for RealCreateTaskRuntime {
tmux_create_session(session_name, working_dir, command)
}

fn tmux_apply_task_status_bar(
&self,
session_name: &str,
category_title: &str,
task_title: &str,
branch_name: &str,
color_seed: &str,
) -> Result<()> {
tmux_apply_task_status_bar(
session_name,
category_title,
task_title,
branch_name,
color_seed,
)
}

fn tmux_kill_session(&self, session_name: &str) -> Result<()> {
tmux_kill_session(session_name)
}
Expand Down Expand Up @@ -396,6 +447,17 @@ mod tests {
Ok(())
}

fn apply_task_status_bar(
&self,
_session_name: &str,
_category_title: &str,
_task_title: &str,
_branch_name: &str,
_color_seed: &str,
) -> Result<()> {
Ok(())
}

fn switch_client(
&self,
_session_name: &str,
Expand Down
37 changes: 36 additions & 1 deletion src/app/workflows/attach.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

use anyhow::Result;
use anyhow::{Context, Result};
use tracing::warn;
use tuirealm::ratatui::style::Color;
use uuid::Uuid;
Expand Down Expand Up @@ -91,9 +91,20 @@ fn ensure_task_session_with_runtime(
));
}

let category_title = task_status_bar_category_title(db, task);

if let Some(session_name) = task.tmux_session_name.as_deref()
&& runtime.session_exists(session_name)
{
runtime
.apply_task_status_bar(
session_name,
&category_title,
&task.title,
&task.branch,
&task.id.to_string(),
)
.context("failed to configure task tmux status bar")?;
let working_dir = task
.worktree_path
.as_deref()
Expand Down Expand Up @@ -131,6 +142,15 @@ fn ensure_task_session_with_runtime(
);

runtime.create_session(&session_name, worktree_path, &command)?;
runtime
.apply_task_status_bar(
&session_name,
&category_title,
&task.title,
&task.branch,
&task.id.to_string(),
)
.context("failed to configure task tmux status bar")?;
db.update_task_tmux(
task.id,
Some(session_name.clone()),
Expand All @@ -144,6 +164,21 @@ fn ensure_task_session_with_runtime(
}))
}

fn task_status_bar_category_title(db: &Database, task: &Task) -> String {
match db.get_category(task.category_id) {
Ok(category) => category.name,
Err(err) => {
warn!(
error = %err,
task_id = %task.id,
category_id = %task.category_id,
"failed to load task category for tmux status bar"
);
"TASK".to_string()
}
}
}

fn maybe_show_attach_popup(
db: &Database,
task_id: Uuid,
Expand Down
14 changes: 14 additions & 0 deletions src/app/workflows/create_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ pub(crate) fn create_task_pipeline_with_runtime(
let mut created_task_id: Option<Uuid> = None;
let branch_name = branch.clone();
let resolved_title = resolve_task_title(state.title_input.trim(), &branch_name);
let category_title = db
.get_category(todo_category_id)
.context("failed to load task category")?
.name;

let mut operation = || -> Result<()> {
let session_name =
Expand All @@ -172,6 +176,16 @@ pub(crate) fn create_task_pipeline_with_runtime(
.context("failed to save task")?;
created_task_id = Some(task.id);

runtime
.tmux_apply_task_status_bar(
&session_name,
&category_title,
&task.title,
&task.branch,
&task.id.to_string(),
)
.context("failed to configure task tmux status bar")?;

db.update_task_tmux(
task.id,
Some(session_name.clone()),
Expand Down
15 changes: 15 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ fn task_create(db: &Database, project: &str, args: TaskCreateArgs) -> CliResult<
Some(value) => value,
None => resolve_default_category_id(db)?,
};
let category_title = db
.get_category(category_id)
.context("failed to load task category")
.map_err(classify_db_error)?
.name;

let branch = args.branch.trim();
if branch.is_empty() {
Expand Down Expand Up @@ -637,6 +642,16 @@ fn task_create(db: &Database, project: &str, args: TaskCreateArgs) -> CliResult<
.context("failed to save task")?;
created_task_id = Some(task.id);

CreateTaskRuntime::tmux_apply_task_status_bar(
&runtime,
&session_name,
&category_title,
&task.title,
&task.branch,
&task.id.to_string(),
)
.context("failed to configure task tmux status bar")?;

db.update_task_tmux(
task.id,
Some(session_name.clone()),
Expand Down
6 changes: 5 additions & 1 deletion src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ impl Database {
map_repo_row(&row)
}

async fn get_category_async(&self, id: Uuid) -> Result<Category> {
pub async fn get_category_async(&self, id: Uuid) -> Result<Category> {
let row = sqlx::query(
"SELECT id, slug, name, position, color, created_at FROM categories WHERE id = ?",
)
Expand All @@ -1057,6 +1057,10 @@ impl Database {
let row = row.with_context(|| format!("category {id} not found"))?;
map_category_row(&row)
}

pub fn get_category(&self, id: Uuid) -> Result<Category> {
block_on_db(self.get_category_async(id))
}
}

fn sqlite_connect_options(path_ref: &Path) -> Result<SqliteConnectOptions> {
Expand Down
3 changes: 3 additions & 0 deletions src/tmux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use termlauncher::{Application, CustomTerminal, Error as TermlauncherError, Term

use crate::process::{command, tmux_env_args};

mod status_bar;
pub use status_bar::{TaskStatusBarSpec, render_task_status_bar, tmux_apply_task_status_bar};

const TMUX_SOCKET: &str = "";

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down
Loading
Loading