#![cfg_attr(coverage_nightly, coverage(off))]
use anyhow::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TimelineMode {
Interactive,
#[default]
NonInteractive,
}
impl TimelineMode {
pub fn from_args(args: &[&str]) -> Self {
if args.contains(&"--interactive") || args.contains(&"-i") {
TimelineMode::Interactive
} else {
TimelineMode::NonInteractive
}
}
pub fn is_interactive(&self) -> bool {
matches!(self, TimelineMode::Interactive)
}
pub fn is_non_interactive(&self) -> bool {
matches!(self, TimelineMode::NonInteractive)
}
pub fn requires_terminal(&self) -> bool {
self.is_interactive()
}
pub fn validate_terminal_availability(&self, has_tty: bool) -> Result<()> {
if self.requires_terminal() && !has_tty {
anyhow::bail!("Interactive mode requires a TTY (terminal). Run without --interactive flag for batch mode.");
}
Ok(())
}
pub fn description(&self) -> &str {
match self {
TimelineMode::Interactive => "Interactive TUI mode",
TimelineMode::NonInteractive => "Non-interactive batch mode",
}
}
pub fn validate_args(args: &[&str]) -> Result<()> {
let has_interactive = args.contains(&"--interactive") || args.contains(&"-i");
let has_json = args.contains(&"--json");
if has_interactive && has_json {
anyhow::bail!("Conflicting flags: --interactive and --json cannot be used together");
}
Ok(())
}
#[cfg(feature = "tui")]
pub fn check_feature_availability(&self) -> Result<()> {
Ok(())
}
#[cfg(not(feature = "tui"))]
pub fn check_feature_availability(&self) -> Result<()> {
if self.is_interactive() {
anyhow::bail!(
"Interactive mode requires the 'tui' feature. Rebuild with --features tui"
);
}
Ok(())
}
}
pub fn handle_timeline(_args: &[&str]) -> Result<()> {
Ok(())
}
pub fn get_timeline_help_text() -> String {
r#"USAGE:
pmat timeline <recording.pmat> [OPTIONS]
OPTIONS:
--interactive, -i Launch interactive TUI for timeline navigation
--json Output timeline data as JSON (conflicts with --interactive)
--help, -h Print this help message
EXAMPLES:
# Interactive mode (TUI)
pmat timeline recording.pmat --interactive
# Non-interactive mode (default)
pmat timeline recording.pmat
# JSON output
pmat timeline recording.pmat --json
"#
.to_string()
}
include!("timeline_mode_tests.rs");