buzzsprout-cli 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +271 -0
  4. data/bin/buzzsprout +6 -0
  5. data/lib/buzzsprout/animation/wordmark.rb +41 -0
  6. data/lib/buzzsprout/animation.rb +181 -0
  7. data/lib/buzzsprout/cli.rb +215 -0
  8. data/lib/buzzsprout/client.rb +306 -0
  9. data/lib/buzzsprout/color.rb +195 -0
  10. data/lib/buzzsprout/commands/base.rb +188 -0
  11. data/lib/buzzsprout/commands/brand_affiliations.rb +98 -0
  12. data/lib/buzzsprout/commands/chapters.rb +58 -0
  13. data/lib/buzzsprout/commands/contributors.rb +119 -0
  14. data/lib/buzzsprout/commands/downloads.rb +139 -0
  15. data/lib/buzzsprout/commands/episodes.rb +116 -0
  16. data/lib/buzzsprout/commands/fan_mail.rb +216 -0
  17. data/lib/buzzsprout/commands/feed_verifications.rb +74 -0
  18. data/lib/buzzsprout/commands/listings.rb +159 -0
  19. data/lib/buzzsprout/commands/login.rb +264 -0
  20. data/lib/buzzsprout/commands/podcasts.rb +85 -0
  21. data/lib/buzzsprout/commands/podrolls.rb +74 -0
  22. data/lib/buzzsprout/commands/skills.rb +144 -0
  23. data/lib/buzzsprout/commands/status.rb +64 -0
  24. data/lib/buzzsprout/commands/team.rb +75 -0
  25. data/lib/buzzsprout/commands/transcripts.rb +100 -0
  26. data/lib/buzzsprout/commands/update.rb +36 -0
  27. data/lib/buzzsprout/commands/uploads.rb +134 -0
  28. data/lib/buzzsprout/config.rb +125 -0
  29. data/lib/buzzsprout/formatter.rb +68 -0
  30. data/lib/buzzsprout/group_help.rb +74 -0
  31. data/lib/buzzsprout/oauth.rb +203 -0
  32. data/lib/buzzsprout/options.rb +155 -0
  33. data/lib/buzzsprout/podcast_picker.rb +328 -0
  34. data/lib/buzzsprout/redact.rb +65 -0
  35. data/lib/buzzsprout/updater.rb +230 -0
  36. data/lib/buzzsprout/version.rb +5 -0
  37. data/skills/README.md +62 -0
  38. data/skills/brand_affiliations/SKILL.md +52 -0
  39. data/skills/buzzsprout/SKILL.md +111 -0
  40. data/skills/chapters/SKILL.md +49 -0
  41. data/skills/contributors/SKILL.md +58 -0
  42. data/skills/episodes/SKILL.md +61 -0
  43. data/skills/fan_mail/SKILL.md +53 -0
  44. data/skills/feed_verifications/SKILL.md +51 -0
  45. data/skills/insertion_points/SKILL.md +50 -0
  46. data/skills/listings/SKILL.md +52 -0
  47. data/skills/podcasts/SKILL.md +57 -0
  48. data/skills/podrolls/SKILL.md +49 -0
  49. data/skills/soundbites/SKILL.md +51 -0
  50. data/skills/stats/SKILL.md +65 -0
  51. data/skills/team/SKILL.md +10 -0
  52. data/skills/transcripts/SKILL.md +60 -0
  53. data/skills/uploads/SKILL.md +68 -0
  54. metadata +102 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 207b85a58e1f62a64a34160ddedb20ef64d0c8f73765aca0a7d89ee3ecc1daf2
4
+ data.tar.gz: 21bce92e4e4a04c9aae80e0c9434914db009fb2e11bd57533f299281f965c47a
5
+ SHA512:
6
+ metadata.gz: f8711d078652832b18b5b0cced58eb9978a0d921ec96daeb10c0a30533d40f9287b6d9b66b22babeb4ed37675cbc645a25b648a5ab828abf951b96199eeda5e4
7
+ data.tar.gz: c362c8c9c4d0c39be6cc8429f586601ad2cbdbd4c8d9c020e43f83448121632873e5b13b6f3c6823d108c4bd083747d7e424dd59f260e73fc82b716cf3274a8f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Higher Pixels
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT WITHOUT LIMITATION THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,271 @@
1
+ # Buzzsprout CLI
2
+
3
+ A fun, agent-friendly command-line interface for the [Buzzsprout API](https://github.com/buzzsprout/buzzsprout-api). List podcasts, manage episodes, upload audio, and call the rest of the public API — with a first-run that actually feels like a first run.
4
+
5
+ Modeled on [basecamp-cli](https://github.com/robzolkos/ruby-basecamp-cli): Ruby gem, `bin/` + `lib/` + `skills/`, stdlib `Net::HTTP` (no Thor; that CLI uses a small custom dispatcher, and this one matches it).
6
+
7
+ ## Features
8
+
9
+ - **First run** — braille startup animation of the Buzzsprout mark + wordmark (embedded in the CLI source), token prompt, live `GET /api/podcasts`, celebration, token saved to `~/.buzzsprout.json`
10
+ - **Browser login** — OAuth with automatic refresh; API tokens remain supported for scripts
11
+ - **Identifiable User-Agent** — `BuzzsproutCLI/0.1.1` on every request
12
+ - **Rate limits** — 60 req/min; retries `429` with backoff
13
+ - **ETags** — sends `If-None-Match` on repeat GETs
14
+ - **Agent skills** — `skills/` with one skill per API resource, plus `buzzsprout skills install`
15
+
16
+ ## Installation
17
+
18
+ Git installs track `main`. RubyGems, mise, and Homebrew installs come from tagged releases (`v0.1.1` and later). See [RELEASING.md](RELEASING.md).
19
+
20
+ ### macOS with Homebrew
21
+
22
+ Once the first release is available in the Buzzsprout tap, install the CLI and sign in with the commands below. Until then, use the [Git installer](#git).
23
+
24
+ ```bash
25
+ brew install buzzsprout/tap/buzzsprout-cli
26
+ buzzsprout login
27
+ ```
28
+
29
+ ### Git
30
+
31
+ On macOS or Linux, install Ruby 3.0+ and Git, then run:
32
+
33
+ ```bash
34
+ curl -fsSL https://raw.githubusercontent.com/buzzsprout/buzzsprout-cli/main/script/install | bash
35
+ buzzsprout login
36
+ ```
37
+
38
+ The repository is public; no GitHub account is required. The installer clones into `~/.buzzsprout-cli` and links `buzzsprout` into `~/.local/bin` (or `~/bin` if already on PATH). Follow any PATH instructions it prints. It does not use `sudo`. On Windows, use WSL with Ruby and Git installed.
39
+
40
+ To inspect the code before installing:
41
+
42
+ ```bash
43
+ git clone https://github.com/buzzsprout/buzzsprout-cli.git ~/.buzzsprout-cli
44
+ ~/.buzzsprout-cli/script/install
45
+ buzzsprout login
46
+ ```
47
+
48
+ If you already have a checkout, run `./script/install` from its root.
49
+
50
+ Installer overrides: `BUZZSPROUT_CLI_HOME` (clone directory), `BUZZSPROUT_CLI_BIN` (executable directory), `BUZZSPROUT_CLI_REPO` (Git remote), and `BUZZSPROUT_CLI_REF` (branch or tag, default `main`).
51
+
52
+ ### RubyGems and mise
53
+
54
+ After a release is on RubyGems:
55
+
56
+ ```bash
57
+ gem install buzzsprout-cli
58
+ buzzsprout login
59
+ ```
60
+
61
+ mise installs that gem:
62
+
63
+ ```bash
64
+ mise use -g gem:buzzsprout-cli
65
+ ```
66
+
67
+ ### Updating
68
+
69
+ Git installations keep their current update path. From a clean checkout of the official repository on `main`:
70
+
71
+ ```bash
72
+ buzzsprout update # update CLI and refresh agent skills
73
+ buzzsprout update --check # check without installing
74
+ buzzsprout update --check --json # machine-readable check for AI assistants
75
+ ```
76
+
77
+ Updates follow `main`, so changes to commands, the public OAuth client ID, and skills are detected even when the version number hasn't changed. The updater only fast-forwards clean installations of the official repository on `main`; it refuses local edits, other branches, and divergent history. Your login and saved podcast are preserved.
78
+
79
+ Skills refresh in detected Claude Code and Cursor directories, or the destination selected by `BUZZSPROUT_SKILLS_DIR` / `--dir`. For a custom location, run `buzzsprout update --dir PATH`. Previous skill copies are backed up. Start a new AI session after refreshing skills. If the skill refresh fails, the CLI update remains installed and the command reports how to retry.
80
+
81
+ Packaged installations use their package manager:
82
+
83
+ | Install | Update |
84
+ | --- | --- |
85
+ | RubyGems | `gem update buzzsprout-cli` |
86
+ | mise | `mise upgrade gem:buzzsprout-cli` |
87
+ | Homebrew | `brew upgrade buzzsprout-cli` |
88
+
89
+ `buzzsprout update` on a packaged installation prints that command and leaves the files in place. `buzzsprout update --check` compares the installed version with the latest GitHub Release. JSON output includes `update_command`. After the package manager finishes, run `buzzsprout skills install` to refresh copied agent skills. A custom destination uses `buzzsprout skills install --dir PATH`.
90
+
91
+ Normal commands check for updates at most once a day and print notices on stderr, preserving JSON stdout. Git installs compare against `main`. Packaged installs compare against the latest release and name their package manager. Checks have a three-second network timeout; offline or rate-limited checks do not fail the command. Automatic checks are skipped in CI, for dirty or non-main checkouts and source trees, and when `BUZZSPROUT_NO_UPDATE_CHECK=1`. Explicit `update --check` always requests a fresh result. Nothing updates automatically.
92
+
93
+ Older Git installations without the update command can be updated from a clean `main` checkout with `git pull --ff-only`, then `./script/install` and `buzzsprout skills install`.
94
+
95
+ ### From source
96
+
97
+ ```bash
98
+ git clone https://github.com/buzzsprout/buzzsprout-cli.git
99
+ cd buzzsprout-cli
100
+ bundle install
101
+ ```
102
+
103
+ Then either:
104
+
105
+ - Run directly: `./bin/buzzsprout`
106
+ - Add to PATH: `export PATH="$PATH:/path/to/buzzsprout-cli/bin"`
107
+ - Install as a gem: `rake install`
108
+ - Link this checkout onto PATH: `./script/install`
109
+
110
+ ## First run
111
+
112
+ Run `buzzsprout login` to connect your account:
113
+
114
+ 1. The CLI prints an authorization link and opens it in your browser.
115
+ 2. Sign in to Buzzsprout and approve access. Use a browser on the same computer as the CLI.
116
+ 3. Return to the terminal. The CLI checks the connection, saves your credentials privately, and helps you choose a default podcast.
117
+ 4. If agent skills are not installed, the CLI offers to install them. Use `--install-skills` to install without prompting or `--no-skills` to skip.
118
+
119
+ Use `buzzsprout login --no-browser` to open the printed link yourself. Authorization times out after five minutes; rerun login if needed.
120
+
121
+ ## Authentication
122
+
123
+ OAuth access tokens refresh automatically. If the connection has been revoked or cannot be refreshed, run `buzzsprout login` again. Failed login attempts leave existing saved credentials intact.
124
+
125
+ Existing API-token configurations continue to work. For token login, run `buzzsprout login --api-token` and enter your token from **Profile → API** at the hidden prompt. `BUZZSPROUT_API_TOKEN` takes precedence over saved credentials, including OAuth. It also selects token authentication when running login. This remains useful for scripts or remote sessions where browser callbacks cannot reach the CLI.
126
+
127
+ Credentials are saved in `~/.buzzsprout.json` with mode `0600` on Unix. Never copy this file into a chat or commit it. Tokens are redacted from status, dry-run output, and API errors. `status` shows the active authentication method.
128
+
129
+ `buzzsprout logout` revokes the saved OAuth connection and removes local credentials and the default podcast. `--local-only` removes only the local copy; you can disconnect the app from your Buzzsprout profile. API-token logout only removes the saved token; an environment variable remains active until you unset it.
130
+
131
+ **Agents:** do not read the credential file or print `BUZZSPROUT_API_TOKEN`. Use the authenticated CLI instead of constructing requests with real tokens.
132
+
133
+ ```bash
134
+ buzzsprout status # token_set: true — never the secret
135
+ buzzsprout podcast use # interactive picker, then save as default
136
+ buzzsprout podcast use 10 # or pass the id / --podcast / --in
137
+ buzzsprout logout
138
+ ```
139
+
140
+ ## Podcast selection
141
+
142
+ Any command that needs a podcast id goes through the same resolver:
143
+
144
+ 1. **Explicit** — positional id, `--podcast ID`, `--in ID`, or `BUZZSPROUT_PODCAST_ID` (this invocation only)
145
+ 2. **Saved** — `default_podcast_id` in `~/.buzzsprout.json` is reused with no picker
146
+ 3. **TTY, none saved** — vertical list (`GET /api/podcasts`, ↑/↓, type to search, Enter). The choice is saved. A single podcast auto-selects and is saved. The list redraws in place (no stacked frames).
147
+ 4. **Noninteractive, none saved** — `--json`, `BUZZSPROUT_NONINTERACTIVE=1`, or no TTY: error with “pass `--podcast ID` or run `buzzsprout podcast use`”
148
+
149
+ Change the saved podcast with `buzzsprout podcast use` (picker) or `buzzsprout podcast use 10`. Esc / Ctrl-C cancels the picker. Agents never block on it.
150
+
151
+ ```bash
152
+ buzzsprout episodes list --podcast 10
153
+ buzzsprout episodes list --in 10
154
+ buzzsprout episodes list # saved podcast, or picker if none is set
155
+ buzzsprout podcast use # pick a different saved podcast
156
+ ```
157
+
158
+ ## Commands
159
+
160
+ Global flags: `--json`, `--body '{…}'`, `--file PATH`, `--dry-run`, `--podcast ID` (alias `--in`), `--no-animation`, `--install-skills`, `--no-skills`.
161
+
162
+ ### Podcasts
163
+
164
+ ```bash
165
+ buzzsprout podcasts
166
+ buzzsprout podcast use
167
+ buzzsprout podcast use 10
168
+ buzzsprout podcasts show 10
169
+ buzzsprout podcasts update 10 --title "Life Empowerment"
170
+ ```
171
+
172
+ ### Episodes
173
+
174
+ ```bash
175
+ buzzsprout episodes list 10
176
+ buzzsprout episodes list # saved podcast, or picker if none is set
177
+ buzzsprout episodes show 10 788881
178
+ buzzsprout episodes create 10 --title "My episode" --private
179
+ buzzsprout episodes publish 10 788881
180
+ buzzsprout episodes unpublish 10 788881
181
+ ```
182
+
183
+ ### Uploads
184
+
185
+ Create the episode first. Complete is required or the episode has no media.
186
+
187
+ ```bash
188
+ buzzsprout uploads start 10 788881 --file ./episode.m4a
189
+ ```
190
+
191
+ That runs start → PUT bytes (no API token on the storage URL) → complete.
192
+
193
+ ### Downloads
194
+
195
+ Date is required (no default). `today` and `yesterday` are local calendar dates; `stats` is an alias.
196
+
197
+ ```bash
198
+ buzzsprout downloads today
199
+ buzzsprout downloads yesterday
200
+ buzzsprout downloads 2026-09-01
201
+ buzzsprout episode 788881 downloads today
202
+ buzzsprout episode 788881 downloads yesterday
203
+ buzzsprout episode 788881 downloads 2026-09-01
204
+ ```
205
+
206
+ ### Everything else
207
+
208
+ ```bash
209
+ buzzsprout team list 10
210
+ buzzsprout contributors list 10
211
+ buzzsprout brand-affiliations list 10
212
+ buzzsprout chapters list 10 788881
213
+ buzzsprout transcripts show 10 788881
214
+ buzzsprout listings
215
+ buzzsprout listings Apple url
216
+ buzzsprout listings Apple status
217
+ buzzsprout listings submit-all
218
+ buzzsprout podrolls list 10
219
+ buzzsprout feed-verifications list 10
220
+ buzzsprout fan-mail list 10
221
+ buzzsprout insertion-points list 10 788881
222
+ buzzsprout soundbites show 10 788881
223
+ ```
224
+
225
+ `buzzsprout help` prints the full map. `--dry-run` prints the HTTP request without sending it (useful without live credentials).
226
+
227
+ ## Skills for agents
228
+
229
+ Each major API resource has a skill under [`skills/`](skills/README.md): when to use it, endpoints, auth headers, example requests, and CLI mapping.
230
+
231
+ ```bash
232
+ buzzsprout skills
233
+ buzzsprout skills path
234
+ buzzsprout skills install --dir ~/.cursor/skills
235
+ ```
236
+
237
+ `buzzsprout skills install` installs or refreshes skills for detected Cursor and Claude Code installations (`~/.cursor` and `~/.claude`). Login offers the same installation when skills are missing or outdated. `BUZZSPROUT_SKILLS_DIR` or `--dir` selects a single destination instead. Resource folders use names such as `buzzsprout-stats`; previous Buzzsprout folders are archived beside the skills directory, and unrelated skills are preserved. Details: [skills/README.md](skills/README.md).
238
+
239
+ ## Environment
240
+
241
+ | Variable | Purpose |
242
+ | --- | --- |
243
+ | `BUZZSPROUT_API_TOKEN` | Token override (never print) |
244
+ | `BUZZSPROUT_PODCAST_ID` | Explicit podcast id for this process (skips the picker) |
245
+ | `BUZZSPROUT_NONINTERACTIVE=1` | Never open the podcast picker or the post-login skills prompt |
246
+ | `BUZZSPROUT_CONFIG` | Config path (default `~/.buzzsprout.json`) |
247
+ | `BUZZSPROUT_SKILLS_DIR` | Override detected agent skills directories |
248
+ | `BUZZSPROUT_API_BASE` | API base (default `https://www.buzzsprout.com/api`) |
249
+ | `BUZZSPROUT_NO_ANIMATION=1` | Skip the intro |
250
+ | `BUZZSPROUT_NO_UPDATE_CHECK=1` | Disable automatic update checks |
251
+ | `BUZZSPROUT_THEME` | `dark` or `light` for the intro. If unset: `COLORFGBG`, then a best-effort OSC 11 query **only** on a raw TTY (skipped if that would leak). Otherwise **dark** (bright green `#61D752` for bolt + wordmark). Light terminals use `#214538` for the wordmark. |
252
+ | `NO_COLOR` / `BUZZSPROUT_NO_COLOR` | Disable ANSI color |
253
+
254
+ ## Development
255
+
256
+ ```bash
257
+ bundle install
258
+ bundle exec rake test
259
+ ```
260
+
261
+ Tests use a local fake API (no real tokens). Do not put API tokens in this repo.
262
+
263
+ ## Releasing
264
+
265
+ `script/release 0.1.1` bumps the version and tags `v0.1.1`. Pushing the tag publishes the GitHub Release, the gem, and a Homebrew formula. Details: [RELEASING.md](RELEASING.md).
266
+
267
+ Endpoint shapes follow [buzzsprout/buzzsprout-api#56](https://github.com/buzzsprout/buzzsprout-api/pull/56).
268
+
269
+ ## License
270
+
271
+ MIT
data/bin/buzzsprout ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/buzzsprout/cli'
5
+
6
+ exit Buzzsprout::CLI.new.run(ARGV)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Buzzsprout
4
+ class Animation
5
+ # Default Buzzsprout wordmark as braille (logo mark + "Buzzsprout").
6
+ # Derived from the Figma Default lockup; stored as source, not image files.
7
+ WIDTH = 76
8
+ HEIGHT = 9
9
+ DELAY = 0.055
10
+ BOLT_COLOR = '#61D752'
11
+ MARK_COLOR_LIGHT = '#214538'
12
+ # Dark terminals: same hero green for bolt + wordmark (dark brand green vanishes).
13
+ MARK_COLOR_DARK = BOLT_COLOR
14
+ MARK_COLOR = MARK_COLOR_LIGHT
15
+
16
+ WORDMARK = [
17
+ ' ⢰⡇ ⣀⣀⣀⣀⡀ ',
18
+ ' ⢀⣿⡇ ⣿⣿⣿⣿⣿⣷⡀ ⢠⣤⡄ ',
19
+ ' ⣾⣿⣿⣿⣿⠃ ⣿⣿⠁⠈⣻⣿⡇⢀⣀⡀ ⢀⣀⣀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀⢀⣠⣤⣤⣀⢀⣀⣀⢀⣤⣤⡀ ⢀⣀⣀⣀⣤ ⢀⣠⣤⣄⡀ ⢀⣀⣀ ⣀⣀⢠⣾⣿⣇⣀',
20
+ ' ⣼⣿⣿⣿⣿⠇ ⣿⣿⣶⣶⣿⣿⠁⢸⣿⡇ ⢸⣿⣿⢸⣿⣿⣿⣿⠇⢿⣿⣿⣿⣿⢁⣾⣿⠿⢿⣿⢸⣿⣿⣿⣿⣿⣿⣆⢸⣿⣿⣿⣿⣰⣿⣿⣿⣿⣿⣆⢸⣿⣿ ⣿⣿⢸⣿⣿⣿⣿',
21
+ '⣿⣿⣦⡀ ⣿⡏⣠⣾⣿⡇ ⣿⣿⠛⠛⢿⣿⣧⢸⣿⡇ ⢸⣿⣿ ⣼⣿⡏ ⢀⣾⣿⠃⠘⣿⣿⣶⣦⣌⢸⣿⣿⠁ ⠘⣿⣿⢸⣿⣿⠃⢀⣿⣿⠁ ⠘⣿⣿⢸⣿⣿ ⣿⣿ ⢸⣿⡇ ',
22
+ '⢹⣿⣿⣿⣆⠿⣼⣿⣿⣿⠃ ⣿⣿ ⣸⣿⣿⢸⣿⣧ ⣸⣿⣿ ⣰⣿⡟ ⣼⣿⠏ ⣌⠙⠛⣿⣿⡎⣿⣿⣄ ⣠⣿⣿⢸⣿⣿ ⣿⣿⣄ ⣠⣿⣿⢸⣿⣿ ⣸⣿⣿ ⢸⣿⡇ ',
23
+ ' ⠹⣿⣿⣿⣸⣿⣿⡿⠃ ⣿⣿⣿⣿⣿⣿⠏⠘⣿⣿⣿⣿⣿⣿⢰⣿⣿⣿⣿⣿⣸⣿⣿⣿⣿⡇⣿⣿⣿⣿⡿⢱⣿⣿⣿⣿⣿⣿⠋⢸⣿⣿ ⠙⣿⣿⣿⣿⡿⠃⠘⣿⣿⣿⣿⣿⣿ ⠸⣿⣿⣿',
24
+ ' ⠈⠙⠛⠛⠛⠉ ⠉⠉⠉⠉⠉ ⠈⠉⠉ ⠉⠉⠈⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠈⠉⠉⠉ ⢸⣿⣿⠈⠉⠉⠁ ⠈⠉⠉ ⠉⠉⠉ ⠈⠉⠉⠁⠉⠉ ⠈⠉⠉',
25
+ ' ⢸⣿⣿ '
26
+ ].freeze
27
+
28
+ KIND = [
29
+ '....bb.......mmmmm..........................................................',
30
+ '...bbb.......mmmmmmm....................................................mmm.',
31
+ '...bbbbbb....mmmmmmmmmm.mmmmmmmmmmmmmmmmmmmmmmmmmmm.mmmmm.mmmmm.mmm..mmmmmmm',
32
+ '..bbbbbb.....mmmmmmmmmm.mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm..mmmmmmm',
33
+ 'mmmm.bbmmmm..mmmmmmmmmm.mmm..mmm..mmmmmmmmmmmmmm.mmmmmmmmmmm.mmmmmm..mm.mmm.',
34
+ 'mmmmmbmmmmm..mm..mmmmmm.mmm.mmm...mmm..mmmmmmmmm.mmmmmm..mmm.mmmmmm.mmm.mmm.',
35
+ '.mmmmmmmmm...mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm..mmmmmmmmmmmmmm.mmmm',
36
+ '..mmmmmm.....mmmmm...mmm.mmmmmmmmmmmmmmmmmm.mmmmmmm.mmm....mmm...mmmmmm..mmm',
37
+ '............................................mmm.............................'
38
+ ].freeze
39
+
40
+ end
41
+ end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'animation/wordmark'
4
+
5
+ module Buzzsprout
6
+ class Animation
7
+ DEFAULT_DELAY = DELAY
8
+
9
+ def initialize(io: $stdout, delay: nil, force: false)
10
+ @io = io
11
+ @delay = delay
12
+ @force = force
13
+ end
14
+
15
+ def play
16
+ return if skip?
17
+
18
+ Color.theme(@io)
19
+ hide_cursor
20
+ # Leave the finale wordmark on screen; auth continues below it.
21
+ run_block(frames.map { |frame| colorize(frame) }, @delay || DELAY)
22
+ ensure
23
+ show_cursor
24
+ end
25
+
26
+ def frames
27
+ self.class.frames
28
+ end
29
+
30
+ def self.frames
31
+ @frames ||= build_frames
32
+ end
33
+
34
+ def self.width
35
+ WIDTH
36
+ end
37
+
38
+ def self.height
39
+ HEIGHT
40
+ end
41
+
42
+ def self.reset!
43
+ @frames = nil
44
+ end
45
+
46
+ def self.icon_columns
47
+ occupied = Array.new(WIDTH) do |x|
48
+ KIND.any? { |row| row.chars[x] != '.' }
49
+ end
50
+ x = 0
51
+ x += 1 while x < WIDTH && !occupied[x]
52
+ x += 1 while x < WIDTH && occupied[x]
53
+ [x + 1, WIDTH].min
54
+ end
55
+
56
+ def self.build_frames
57
+ mark = icon_columns
58
+ frames = []
59
+ frames << mask { |_x, _y| false }
60
+
61
+ HEIGHT.times do |step|
62
+ threshold = HEIGHT - (step + 1)
63
+ frame = mask { |x, y| x < mark && y >= threshold }
64
+ frames << frame if frame['text'].any? { |line| line.match?(/\S/) }
65
+ end
66
+
67
+ frames << mask { |x, _y| x < mark }
68
+
69
+ remaining = WIDTH - mark
70
+ wipe_steps = 8
71
+ wipe_steps.times do |step|
72
+ edge = mark + (remaining * (step + 1) / wipe_steps)
73
+ frames << mask { |x, _y| x < edge }
74
+ end
75
+
76
+ 3.times { frames << mask { |_x, _y| true } }
77
+ frames
78
+ end
79
+
80
+ def self.mask
81
+ word = WORDMARK.map(&:chars)
82
+ kinds = KIND.map(&:chars)
83
+ texts = []
84
+ kind_rows = []
85
+ HEIGHT.times do |y|
86
+ chars = []
87
+ ks = []
88
+ WIDTH.times do |x|
89
+ if yield(x, y)
90
+ chars << (word[y][x] || ' ')
91
+ ks << (kinds[y][x] || '.')
92
+ else
93
+ chars << ' '
94
+ ks << '.'
95
+ end
96
+ end
97
+ texts << chars.join
98
+ kind_rows << ks.join
99
+ end
100
+ { 'text' => texts, 'kind' => kind_rows }
101
+ end
102
+ private_class_method :mask, :build_frames
103
+
104
+ private
105
+
106
+ def skip?
107
+ return false if @force
108
+ return true unless @io.respond_to?(:tty?) && @io.tty?
109
+ return true if ENV['BUZZSPROUT_NO_ANIMATION'] == '1'
110
+ return true if ENV['CI']
111
+
112
+ false
113
+ end
114
+
115
+ def colorize(frame)
116
+ frame['text'].each_with_index.map do |line, y|
117
+ kinds = frame['kind'][y].to_s
118
+ next line unless Color.enabled?(@io)
119
+
120
+ kind_chars = kinds.chars
121
+ line.chars.each_with_index.map do |char, x|
122
+ case kind_chars[x]
123
+ when 'b' then Color.rgb(char, bolt_hex, io: @io)
124
+ when 'm' then Color.rgb(char, mark_hex, io: @io)
125
+ else char
126
+ end
127
+ end.join
128
+ end
129
+ end
130
+
131
+ def bolt_hex
132
+ BOLT_COLOR
133
+ end
134
+
135
+ def mark_hex
136
+ Color.theme(@io) == :light ? MARK_COLOR_LIGHT : MARK_COLOR_DARK
137
+ end
138
+
139
+ def hide_cursor
140
+ @cursor_hidden = true
141
+ @io.print "\e[?25l" if @io.respond_to?(:print)
142
+ end
143
+
144
+ def show_cursor
145
+ return unless @cursor_hidden
146
+
147
+ @cursor_hidden = false
148
+ @io.print "\e[?25h" if @io.respond_to?(:print)
149
+ end
150
+
151
+ def run_block(frames, delay)
152
+ height = frames.first&.size.to_i
153
+ return if height <= 0
154
+
155
+ # Scroll the prompt up if we are near the bottom. Height-only CSI A is
156
+ # wrong when lines wrap; leave the finale wordmark in place.
157
+ height.times { @io.print "\n" }
158
+ @io.print "\e[#{height}A\r"
159
+
160
+ frames.each_with_index do |lines, index|
161
+ home_cursor(height) if index.positive?
162
+ paint_lines(lines)
163
+ sleep delay
164
+ end
165
+ end
166
+
167
+ # CSI n A preserves column on some terminals (Ghostty); CR + EL so a
168
+ # shorter/wrapped row cannot leave cells behind during in-place redraw.
169
+ def home_cursor(height)
170
+ return unless height&.positive?
171
+
172
+ @io.print "\e[#{height}A\r"
173
+ end
174
+
175
+ def paint_lines(lines)
176
+ lines.each do |line|
177
+ @io.print "\e[2K#{line}\e[0m\n"
178
+ end
179
+ end
180
+ end
181
+ end