Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(cli): add branded welcome screen when invoked with no args
Richie McIlroycdd9421e808f
diff --git a/apps/cli/src/main.rs b/apps/cli/src/main.rsindex 36c54ee3a..202edfe56 100644--- a/apps/cli/src/main.rs+++ b/apps/cli/src/main.rs@@ -13,7 +13,7 @@ mod update;mod upload;use std::{- io::{Write, stderr, stdout},+ io::{IsTerminal, Write, stderr, stdout},path::PathBuf,};@@ -24,6 +24,121 @@ use serde::Serialize;use tracing_subscriber::{filter::LevelFilter, layer::SubscriberExt, util::SubscriberInitExt};const TOKIO_WORKER_THREAD_STACK_SIZE: usize = 16 * 1024 * 1024;+const ANSI_RESET: &str = "\x1b[0m";+const ANSI_BOLD: &str = "\x1b[1m";+const ANSI_BLUE: &str = "\x1b[38;2;71;133;255m";+const ANSI_SOFT_BLUE: &str = "\x1b[38;2;173;201;255m";+const ANSI_MUTED: &str = "\x1b[38;2;118;128;145m";++const WELCOME_LINES: &[&[(&str, &str)]] = &[+ &[+ (ANSI_MUTED, " .----------------------. "),+ (ANSI_BOLD, " _____"),+ ],+ &[+ (ANSI_MUTED, " .' '. "),+ (ANSI_BOLD, " / ____|__ _ _ __"),+ ],+ &[+ (ANSI_MUTED, " / \\ "),+ (ANSI_BOLD, "| | / _` | '_ \\"),+ ],+ &[+ (ANSI_MUTED, " | | "),+ (ANSI_BOLD, "| |__| (_| | |_) |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, ".----------."),+ (ANSI_MUTED, " | "),+ (ANSI_BOLD, "\\_____\\__,_| .__/"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, ".-' '-."),+ (ANSI_MUTED, " | "),+ (ANSI_BOLD, "|_|"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, ".' "),+ (ANSI_SOFT_BLUE, ".------."),+ (ANSI_BLUE, " '."),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "/ "),+ (ANSI_SOFT_BLUE, "/ \\"),+ (ANSI_BLUE, " \\"),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "| "),+ (ANSI_SOFT_BLUE, "| "),+ (ANSI_RESET, ".----."),+ (ANSI_SOFT_BLUE, " |"),+ (ANSI_BLUE, " |"),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "| "),+ (ANSI_SOFT_BLUE, "| "),+ (ANSI_RESET, "( )"),+ (ANSI_SOFT_BLUE, " |"),+ (ANSI_BLUE, " |"),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "| "),+ (ANSI_SOFT_BLUE, "| "),+ (ANSI_RESET, "'----'"),+ (ANSI_SOFT_BLUE, " |"),+ (ANSI_BLUE, " |"),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "\\ "),+ (ANSI_SOFT_BLUE, "\\ /"),+ (ANSI_BLUE, " /"),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "'. "),+ (ANSI_SOFT_BLUE, "'------'"),+ (ANSI_BLUE, " .'"),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "'-. .-'"),+ (ANSI_MUTED, " |"),+ ],+ &[+ (ANSI_MUTED, " | "),+ (ANSI_BLUE, "'----------'"),+ (ANSI_MUTED, " |"),+ ],+ &[(ANSI_MUTED, " \\ /")],+ &[(ANSI_MUTED, " '. .'")],+ &[(ANSI_MUTED, " '----------------------'")],+ &[],+ &[(+ ANSI_BOLD,+ " Record, edit, and share screen recordings from the command line.",+ )],+ &[],+ &[(ANSI_BLUE, " cap record start --screen <id> --detach")],+ &[(+ ANSI_MUTED,+ " cap targets cap doctor cap guide --json cap --help",+ )],+];/// Long-form help epilogue. Agents read `cap --help` before doing anything, so the conventions they/// need to drive the CLI correctly (JSON on stdout, env vars, the canonical workflow) live here.@@ -75,7 +190,7 @@ struct Cli {#[arg(long, global = true)]json: bool,#[command(subcommand)]- command: Commands,+ command: Option<Commands>,}#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]@@ -141,6 +256,14 @@ impl Commands {}}+impl Cli {+ fn exit_after_success(&self) -> bool {+ self.command+ .as_ref()+ .is_some_and(Commands::exit_after_success)+ }+}+#[derive(Args)]#[command(args_conflicts_with_subcommands = true)]struct RecordArgs {@@ -342,7 +465,7 @@ fn main() {).init();- let exit_after_success = cli.command.exit_after_success();+ let exit_after_success = cli.exit_after_success();// Windows export exercises deep WGPU/MediaFoundation/FFmpeg stacks. Running the CLI runtime// on an explicitly large stack is what stopped the export worker from overflowing before@@ -396,7 +519,11 @@ fn main() {async fn run(cli: Cli) -> Result<(), String> {let json = cli.json;- match cli.command {+ let Some(command) = cli.command else {+ return print_welcome(json);+ };++ match command {Commands::Export(e) => e.run(json).await,Commands::ExportPreview(e) => e.run().await,Commands::Project(args) => args.run(json),@@ -440,7 +567,7 @@ async fn run(cli: Cli) -> Result<(), String> {}},Commands::Targets(args) => args.run(json),- Commands::Doctor(args) => doctor::run_doctor(resolve_format(json, args.format)),+ Commands::Doctor(args) => doctor::run_doctor(resolve_format(json, args.format)).await,Commands::Version(args) => {let format = resolve_format(json, args.format);finish_json(format, doctor::run_version(format))@@ -463,6 +590,31 @@ async fn run(cli: Cli) -> Result<(), String> {}}+fn print_welcome(json: bool) -> Result<(), String> {+ if json {+ return write_json(&serde_json::json!({+ "name": "cap",+ "about": "Cap screen recording from the command line",+ "commands": ["record", "targets", "doctor", "guide", "upload"],+ }));+ }++ let ansi = stdout().is_terminal() && std::env::var_os("NO_COLOR").is_none();+ let mut stdout = stdout();+ for line in WELCOME_LINES {+ for segment in *line {+ let (style, text) = *segment;+ if ansi && !text.is_empty() {+ write!(stdout, "{style}{text}{ANSI_RESET}").map_err(|e| e.to_string())?;+ } else {+ write!(stdout, "{text}").map_err(|e| e.to_string())?;+ }+ }+ writeln!(stdout).map_err(|e| e.to_string())?;+ }+ stdout.flush().map_err(|e| e.to_string())+}+/// `--json` is a global convenience that forces JSON regardless of a command's local `--format`/// (which stays for back-compat). Either one selecting JSON wins.pub fn resolve_format(global_json: bool, local: OutputFormat) -> OutputFormat {diff --git a/apps/cli/tests/cli.rs b/apps/cli/tests/cli.rsindex b3c4d63f0..9291f2de0 100644--- a/apps/cli/tests/cli.rs+++ b/apps/cli/tests/cli.rs@@ -55,6 +55,30 @@ fn help_succeeds_and_lists_commands() {}}+#[test]+fn no_args_prints_branded_intro() {+ let output = run(&[]);+ assert!(output.status.success(), "stderr: {}", stderr(&output));+ assert!(stderr(&output).is_empty(), "stderr: {}", stderr(&output));+ let text = stdout(&output);+ assert!(text.contains(".----------------------."), "stdout: {text}");+ assert!(text.contains(".----------."), "stdout: {text}");+ assert!(text.contains(".------."), "stdout: {text}");+ assert!(text.contains("( )"), "stdout: {text}");+ assert!(text.contains("/ ____|__ _ _ __"), "stdout: {text}");+ assert!(text.contains("cap record start --screen <id> --detach"));+ assert!(text.contains("cap --help"));+}++#[test]+fn no_args_json_is_parseable() {+ let output = run(&["--json"]);+ assert!(output.status.success(), "stderr: {}", stderr(&output));+ let json = parse_json(&output);+ assert_eq!(json["name"], "cap");+ assert!(json["commands"].is_array());+}+#[test]fn subcommand_help_succeeds() {for command in [@@ -576,6 +600,18 @@ fn doctor_check_ids_are_the_pinned_vocabulary() {.iter().map(|c| c["id"].as_str().unwrap()).collect();+ #[cfg(target_os = "macos")]+ assert_eq!(+ ids,+ [+ "ffmpeg",+ "screenRecordingPermission",+ "screenCaptureKit",+ "cliInstall"+ ]+ );++ #[cfg(not(target_os = "macos"))]assert_eq!(ids, ["ffmpeg", "screenRecordingPermission", "cliInstall"]);}