mod exit_status;
mod git_operations;
mod git_ref;
mod git_stash;
mod git_sync;
mod newline;
mod path;
mod prompt;
mod world_worktree;

use crate::{context::Context, formatting::Color};

/// A widget is a component of the prompt that can display content and have a color.
/// Widgets are rendered in order to create the final prompt string.
pub trait Widget {
    /// Returns the content to display for this widget.
    fn content(&self, context: &Context) -> Option<String>;

    /// Returns the color to use for this widget.
    fn color(&self, _context: &Context) -> Color {
        Color::Default
    }

    /// Whether to request a space before this widget when rendering.
    /// Note: a space will only be added if the previous widget sets `allow_space_after()`.
    fn space_before(&self) -> bool {
        true
    }

    /// Whether to allow a space to be placed after this widget when rendering.
    fn allow_space_after(&self) -> bool {
        true
    }
}

/// The default set of widgets used to render the prompt.
pub const DEFAULT_WIDGETS: &[&dyn Widget] = &[
    &newline::Newline,
    &world_worktree::WorldWorktree,
    &path::Path,
    &git_operations::GitOperations,
    &git_ref::GitRef,
    &git_stash::GitStash,
    &git_sync::GitSync,
    &exit_status::ExitStatus,
    &newline::Newline,
    &prompt::Prompt,
];
