2023-10-26 12:02:53 +02:00
|
|
|
mod asciicast;
|
2023-10-21 14:40:39 +02:00
|
|
|
mod pty;
|
2023-10-24 10:29:09 +02:00
|
|
|
mod recorder;
|
2023-10-26 17:30:42 +02:00
|
|
|
use anyhow::Result;
|
2023-10-27 13:03:30 +02:00
|
|
|
use clap::{Parser, Subcommand};
|
2023-10-27 12:54:45 +02:00
|
|
|
use std::env;
|
2023-10-26 17:30:42 +02:00
|
|
|
|
|
|
|
|
#[derive(Debug, Parser)]
|
2023-10-27 11:41:38 +02:00
|
|
|
#[clap(author, version, about)]
|
2023-10-26 17:30:42 +02:00
|
|
|
#[command(name = "asciinema")]
|
|
|
|
|
struct Cli {
|
|
|
|
|
#[command(subcommand)]
|
|
|
|
|
command: Commands,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
|
enum Commands {
|
|
|
|
|
/// Record terminal session
|
|
|
|
|
#[command(name = "rec")]
|
|
|
|
|
Record {
|
|
|
|
|
filename: String,
|
|
|
|
|
|
|
|
|
|
/// Enable input recording
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
stdin: bool,
|
|
|
|
|
|
|
|
|
|
/// Append to existing asciicast file
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
append: bool,
|
|
|
|
|
|
|
|
|
|
/// Save raw output only
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
raw: bool,
|
|
|
|
|
|
|
|
|
|
/// Overwrite target file if it already exists
|
2023-10-27 22:14:09 +02:00
|
|
|
#[arg(long, conflicts_with = "append")]
|
2023-10-26 17:30:42 +02:00
|
|
|
overwrite: bool,
|
|
|
|
|
|
|
|
|
|
/// Command to record
|
|
|
|
|
#[arg(short, long, default_value_t = String::from("$SHELL"))]
|
|
|
|
|
command: String,
|
|
|
|
|
|
|
|
|
|
/// List of env vars to save
|
|
|
|
|
#[arg(short, long, default_value_t = String::from("SHELL,TERM"))]
|
|
|
|
|
env: String,
|
|
|
|
|
|
|
|
|
|
/// Title of the recording
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
title: Option<String>,
|
|
|
|
|
|
|
|
|
|
/// Limit idle time to given number of seconds
|
|
|
|
|
#[arg(short, long, value_name = "SECS")]
|
|
|
|
|
idle_time_limit: Option<f64>,
|
|
|
|
|
|
|
|
|
|
/// Override terminal width (columns) for recorded command
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
cols: Option<u16>,
|
|
|
|
|
|
|
|
|
|
/// Override terminal height (rows) for recorded command
|
|
|
|
|
#[arg(long)]
|
|
|
|
|
rows: Option<u16>,
|
|
|
|
|
|
|
|
|
|
/// Quiet mode - suppress all notices/warnings
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
quiet: bool,
|
|
|
|
|
},
|
2023-10-27 11:41:38 +02:00
|
|
|
|
|
|
|
|
/// Play terminal session
|
|
|
|
|
Play {
|
|
|
|
|
filename: String,
|
|
|
|
|
|
|
|
|
|
/// Limit idle time to given number of seconds
|
|
|
|
|
#[arg(short, long, value_name = "SECS")]
|
|
|
|
|
idle_time_limit: Option<f64>,
|
|
|
|
|
|
|
|
|
|
/// Set playback speed
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
speed: Option<f64>,
|
|
|
|
|
|
|
|
|
|
/// Loop loop loop loop
|
|
|
|
|
#[arg(short, long, name = "loop")]
|
|
|
|
|
loop_: bool,
|
|
|
|
|
|
|
|
|
|
/// Automatically pause on markers
|
|
|
|
|
#[arg(short = 'm', long)]
|
|
|
|
|
pause_on_markers: bool,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Print full output of terminal sessions
|
|
|
|
|
Cat {
|
|
|
|
|
#[arg(required = true)]
|
|
|
|
|
filename: Vec<String>,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Upload recording to asciinema.org
|
|
|
|
|
Upload {
|
|
|
|
|
/// Filename/path of asciicast to upload
|
|
|
|
|
filename: String,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Link this system to asciinema.org account
|
|
|
|
|
Auth,
|
2023-10-26 17:30:42 +02:00
|
|
|
}
|
2023-10-21 14:40:39 +02:00
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2023-10-26 17:30:42 +02:00
|
|
|
let cli = Cli::parse();
|
|
|
|
|
|
|
|
|
|
match cli.command {
|
|
|
|
|
Commands::Record {
|
|
|
|
|
filename,
|
|
|
|
|
stdin,
|
|
|
|
|
append,
|
|
|
|
|
raw,
|
|
|
|
|
overwrite,
|
|
|
|
|
command,
|
|
|
|
|
env,
|
|
|
|
|
title,
|
|
|
|
|
idle_time_limit,
|
|
|
|
|
cols,
|
|
|
|
|
rows,
|
|
|
|
|
quiet,
|
|
|
|
|
} => {
|
|
|
|
|
let format = if raw {
|
|
|
|
|
recorder::Format::Raw
|
|
|
|
|
} else {
|
|
|
|
|
recorder::Format::Asciicast
|
|
|
|
|
};
|
2023-10-24 10:29:09 +02:00
|
|
|
|
2023-10-26 17:30:42 +02:00
|
|
|
let mut recorder = recorder::new(filename, format, append, stdin)?;
|
2023-10-27 12:54:45 +02:00
|
|
|
|
|
|
|
|
let command = if command == "$SHELL" {
|
|
|
|
|
env::var("SHELL").ok().unwrap_or("/bin/sh".to_owned())
|
|
|
|
|
} else {
|
|
|
|
|
command
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pty::exec(&["/bin/sh", "-c", &command], &mut recorder)?;
|
2023-10-26 17:30:42 +02:00
|
|
|
}
|
2023-10-27 11:41:38 +02:00
|
|
|
|
|
|
|
|
Commands::Play {
|
|
|
|
|
filename,
|
|
|
|
|
idle_time_limit,
|
|
|
|
|
speed,
|
|
|
|
|
loop_,
|
|
|
|
|
pause_on_markers,
|
|
|
|
|
} => todo!(),
|
|
|
|
|
|
|
|
|
|
Commands::Cat { filename } => todo!(),
|
|
|
|
|
|
|
|
|
|
Commands::Upload { filename } => todo!(),
|
|
|
|
|
|
|
|
|
|
Commands::Auth => todo!(),
|
2023-10-26 17:30:42 +02:00
|
|
|
}
|
2023-10-21 15:21:53 +02:00
|
|
|
|
|
|
|
|
Ok(())
|
2023-10-20 15:11:16 +02:00
|
|
|
}
|