use crate::tui::thread::Thread;
use crate::workspace::Repository;
pub struct Pane {
pub thread: Thread,
pub repository: Option<Repository>,
pub prompt: String,
pub history_at: Option<usize>,
pub follow: bool,
}
impl Default for Pane {
fn default() -> Self {
Self {
thread: Thread::default(),
repository: None,
prompt: String::new(),
history_at: None,
follow: true,
}
}
}
impl Pane {
pub fn new(repository: Option<Repository>) -> Self {
Self {
repository,
..Self::default()
}
}
pub fn title(&self) -> String {
if let Some(repo) = &self.repository {
return repo.name.clone();
}
match self.thread.turns.first() {
Some(turn) => turn.prompt.clone(),
None => "new".to_string(),
}
}
pub fn running(&self) -> bool {
self.thread.running()
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
fn repository(name: &str) -> Repository {
Repository {
name: name.to_string(),
path: PathBuf::from("/p").join(name),
}
}
#[test]
fn a_pane_is_named_for_the_repository_it_works_in() {
assert_eq!(Pane::new(Some(repository("scratch"))).title(), "scratch");
}
#[test]
fn a_pane_with_nowhere_to_work_yet_says_so_rather_than_being_blank() {
assert_eq!(Pane::new(None).title(), "new");
}
}