1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! Command-line interface.
use std::path::PathBuf;
use anyhow::Result;
use clap::{Parser, Subcommand};
use crate::{compile, notes, present};
#[derive(Parser)]
#[command(
name = "deckhand",
version,
about = "Present markdown slide decks as a TUI",
args_conflicts_with_subcommands = true
)]
struct Cli {
/// Deck to present: a markdown file, a JSON manifest, a URL, or a
/// GitHub gist (shorthand for `deckhand present <deck>`)
deck: Option<String>,
/// Unix socket path for presenter-notes sync
#[arg(long)]
socket: Option<PathBuf>,
/// Don't live-reload when the deck's files change on disk
#[arg(long)]
no_watch: bool,
/// Start terminal commands as soon as their slide appears (default:
/// each terminal shows its command until run with t, then y)
#[arg(long)]
eager: bool,
#[command(subcommand)]
command: Option<Cmd>,
}
#[derive(Subcommand)]
enum Cmd {
/// Present a deck (a local file, a URL, or a GitHub gist). Local
/// decks live-reload when their files change
Present {
deck: String,
/// Unix socket path for presenter-notes sync
#[arg(long)]
socket: Option<PathBuf>,
/// Don't live-reload when the deck's files change on disk
#[arg(long)]
no_watch: bool,
/// Start terminal commands as soon as their slide appears
/// (default: each shows its command until run with t, then y)
#[arg(long)]
eager: bool,
},
/// Follow presenter notes from a separate terminal
Notes {
/// Unix socket path the presenter is broadcasting on
#[arg(long)]
socket: Option<PathBuf>,
},
/// Flatten a deck (e.g. a JSON manifest) into one markdown file.
/// Decks with terminal blocks require choosing --snapshots (runs
/// their commands, bakes screen captures in) or --no-snapshots
Compile {
deck: String,
/// Write here instead of stdout
#[arg(short, long)]
output: Option<PathBuf>,
/// Run each terminal block in a PTY and bake its screen capture
/// in (this RUNS the deck's commands — only for decks you trust)
#[arg(long, conflicts_with = "no_snapshots")]
snapshots: bool,
/// Compile without running terminal blocks or baking captures
#[arg(long)]
no_snapshots: bool,
/// How long to let each command run before capturing (ms)
#[arg(long, default_value_t = 1500)]
snapshot_wait_ms: u64,
/// Terminal width for captures
#[arg(long, default_value_t = 80)]
snapshot_cols: u16,
/// Working directory for captured commands (controls the prompt
/// path etc.); defaults to the deck's directory
#[arg(long)]
snapshot_root: Option<PathBuf>,
},
}
fn default_socket() -> PathBuf {
std::env::temp_dir().join("deckhand.sock")
}
/// Parse arguments and dispatch to present / notes / compile.
pub fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Some(Cmd::Present {
deck,
socket,
no_watch,
eager,
}) => present::run(
&deck,
socket.unwrap_or_else(default_socket),
!no_watch,
eager,
),
Some(Cmd::Notes { socket }) => notes::run(socket.unwrap_or_else(default_socket)),
Some(Cmd::Compile {
deck,
output,
snapshots,
no_snapshots,
snapshot_wait_ms,
snapshot_cols,
snapshot_root,
}) => {
let choice = match (snapshots, no_snapshots) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None, // compile errors if the deck has terminals
};
let opts = crate::snapshot::Options {
wait: std::time::Duration::from_millis(snapshot_wait_ms),
cols: snapshot_cols,
root: snapshot_root,
};
compile::run(&deck, output.as_deref(), choice, opts)
}
None => match cli.deck {
Some(deck) => present::run(
&deck,
cli.socket.unwrap_or_else(default_socket),
!cli.no_watch,
cli.eager,
),
None => {
eprintln!("usage: deckhand <deck.md|deck.json|url> | deckhand notes");
eprintln!(" deckhand --help");
std::process::exit(2);
}
},
}
}