prompts.rs

 1use crate::{
 2    templates::{BaseTemplate, Template, Templates, WorktreeData},
 3    thread::Prompt,
 4};
 5use anyhow::Result;
 6use gpui::{App, Entity};
 7use project::Project;
 8
 9pub struct BasePrompt {
10    project: Entity<Project>,
11}
12
13impl BasePrompt {
14    pub fn new(project: Entity<Project>) -> Self {
15        Self { project }
16    }
17}
18
19impl Prompt for BasePrompt {
20    fn render(&self, templates: &Templates, cx: &App) -> Result<String> {
21        BaseTemplate {
22            os: std::env::consts::OS.to_string(),
23            shell: util::get_system_shell(),
24            worktrees: self
25                .project
26                .read(cx)
27                .worktrees(cx)
28                .map(|worktree| WorktreeData {
29                    root_name: worktree.read(cx).root_name().to_string(),
30                })
31                .collect(),
32        }
33        .render(templates)
34    }
35}