Skip to main content

rec/demo/
mod.rs

1//! Interactive demo session generation.
2//!
3//! Provides a guided walkthrough of `rec` features using simulated
4//! terminal output with typing effects.
5
6use std::thread;
7use std::time::Duration;
8
9/// Run a simulated interactive walkthrough of the core rec workflow.
10///
11/// Prints a complete demonstration of the start -> record -> stop -> show ->
12/// replay --dry-run -> export flow using styled text. No real sessions are
13/// created, no state files are touched.
14///
15/// When `is_tty` is true, brief pauses (500ms) are added between sections
16/// for readability. When false (piped output, CI), everything is printed
17/// immediately.
18pub fn run_demo(is_tty: bool) {
19    let pause = if is_tty {
20        Duration::from_millis(500)
21    } else {
22        Duration::ZERO
23    };
24
25    // Step 1: Welcome banner
26    println!("Welcome to rec! Let's walk through the core workflow.");
27    println!("rec records your terminal commands and lets you replay, export, and share them.");
28    if !pause.is_zero() {
29        thread::sleep(pause);
30    }
31
32    // Step 2: Starting a recording
33    println!();
34    println!("$ rec start --name deploy-demo");
35    println!("\u{2713} Recording started: deploy-demo");
36    if !pause.is_zero() {
37        thread::sleep(pause);
38    }
39
40    // Step 3: Show example commands being "captured"
41    println!();
42    println!("$ echo \"Hello from rec!\"");
43    println!("$ git status");
44    println!("$ docker compose up -d");
45    if !pause.is_zero() {
46        thread::sleep(pause);
47    }
48
49    // Step 4: Stopping the recording
50    println!();
51    println!("$ rec stop");
52    println!("\u{2713} Recording stopped: deploy-demo (3 commands)");
53    if !pause.is_zero() {
54        thread::sleep(pause);
55    }
56
57    // Step 5: Viewing the session
58    println!();
59    println!("$ rec show deploy-demo");
60    println!("Session: deploy-demo");
61    println!("Commands: 3");
62    println!("  1. echo \"Hello from rec!\"");
63    println!("  2. git status");
64    println!("  3. docker compose up -d");
65    if !pause.is_zero() {
66        thread::sleep(pause);
67    }
68
69    // Step 6: Replay with dry-run
70    println!();
71    println!("$ rec replay deploy-demo --dry-run");
72    println!("[dry-run] Would execute: echo \"Hello from rec!\"");
73    println!("[dry-run] Would execute: git status");
74    println!("[dry-run] Would execute: docker compose up -d");
75    if !pause.is_zero() {
76        thread::sleep(pause);
77    }
78
79    // Step 7: Export to bash script
80    println!();
81    println!("$ rec export deploy-demo --format bash");
82    println!("#!/usr/bin/env bash");
83    println!("set -euo pipefail");
84    println!("echo \"Hello from rec!\"");
85    println!("git status");
86    println!("docker compose up -d");
87    if !pause.is_zero() {
88        thread::sleep(pause);
89    }
90
91    // Step 8: v2 feature highlights
92    println!();
93    println!("New in v2:");
94    println!("  \u{2022} rec search \"docker\"     \u{2014} Search across all sessions");
95    println!("  \u{2022} rec stats               \u{2014} View recording statistics");
96    println!("  \u{2022} rec doctor              \u{2014} Diagnose installation issues");
97    println!("  \u{2022} rec import deploy.sh    \u{2014} Import from scripts or history");
98    if !pause.is_zero() {
99        thread::sleep(pause);
100    }
101
102    // Step 9: Closing
103    println!();
104    println!("That's rec! Get started: rec start --name my-first-session");
105    println!("Docs: https://github.com/zeybek/rec");
106}
107
108#[cfg(test)]
109mod tests {
110    // run_demo prints to stdout — we just verify it doesn't panic.
111
112    #[test]
113    fn run_demo_non_tty_does_not_panic() {
114        // Non-TTY mode: no pauses, fast completion
115        super::run_demo(false);
116    }
117}