Open Source

Interactive CLI Prompts in Swift: Promptberry Guide

Swift CLI tools deserve better than print-and-pray. Promptberry finally makes them feel modern — and usable.

Terminal screenshot of Promptberry interactive text prompt with validation in Swift CLI tool

Key Takeaways

  • Promptberry replaces clunky readLine() with placeholders, inline validation, and menus.
  • Supports selects, autocomplete, multiselect, confirmations, spinners, and progress bars.
  • Graceful Ctrl+C handling and async tasks make production CLIs feasible.

CLI prompts in Swift were a joke.

Twenty years watching this valley churn out “innovations,” and here’s Swift — Apple’s shiny toy — stuck with readLine() like it’s 1995. Print a message, slurp input, pray it works. No validation hints, no menus, nada. Promptberry? It’s a library that actually fixes this mess, delivering text fields, dropdowns, even spinners without you reinventing the wheel.

Look, I’ve built enough CLI tools to know: users hate typing blind. That basic loop — print(“Enter name:”), let name = readLine() ?? “” — it’s fine for a one-off script. But ship it as a tool? Users bail. Promptberry’s text prompt changes everything:

let name = try Promptberry.text( “Project name?”, placeholder: “MyApp”, validate: { $0.isEmpty ? “Name cannot be empty.” : nil } )

Validation pops right under the field — no wiping the input. Type junk, error flashes, keep going. Magic? Nah, just competent design borrowed from web forms.

Why Swift’s Stdlib Still Lags on CLIs

But here’s the thing — Swift Package Manager thrives on CLI tools. Code gens, deployers, listers. Yet the language acts like interactivity is optional. Node.js had Inquirer.js a decade ago; Python’s Click nailed it early. Swift? Crickets.

Promptberry plugs that hole with selects for choices. Arrow keys or j/k navigate, Enter picks. Throw allowOther: true, and it morphs into a combo box. Autocomplete for long lists — type “mit,” boom, MIT license floats up. Multiselect for checkboxes, toggling with spacebar. It’s not reinventing readline; it’s making it pro-grade.

Password masking? Swap to password(“secret?”, mask: “•”). Confirmations before nuking stuff: “Create "(name)"?” with Yes/No toggles. Guard confirmed else { cancel and bail }. Clean.

One gripe, though — it’s Swift 5.7+, so if you’re dragging on ancient Xcode, tough luck. But who’s not on 5.9 by now?

Does Promptberry Actually Save Time?

Async tasks next. Sequence ‘em with tasks([PromptTask(“Scaffolding”) { scaffold() }, …]). Each gets a spinner; fail, it reds out, halts. Progress bars for file copies: init with total, advance per step, complete with message. Feels alive, not dead.

Ctrl+C? Throws PromptCancelled. Catch it, outro gracefully. Wrap in do/catch, done. Intro/outro bookend the session — “New Swift Project,” prompts, “Happy coding!” Polished.

Skeptical me asks: is this vaporware? Nah, it’s on GitHub, lightweight, no deps beyond Swift. But who’s bankrolling it? Solo dev, probably. No VC spin, no “revolutionary” BS. That’s refreshing — in a world of $100M CLI frameworks that do less.

My hot take? This echoes Ruby’s HighLine from 2005 — that gem made CLIs fun before everyone forgot terminals could be interactive. Swift devs ignored that lesson; Promptberry revives it. Prediction: package managers like Tuist or SwiftGen adopt it fast. Your next CLI scaffolder? Infinitely friendlier.

Freeform multiline? Editable buffer, Enter for lines, Ctrl+D submits. Perfect for README stubs or configs.

Building a Real Tool with It

Picture a project scaffolder. Grab name, type, features, desc. Confirm. Tasks: scaffold dirs, write Package.swift, deps. Boom, done. No more brittle bash scripts.

Validation’s inline smarts shine — empty name? “Can’t be empty.” Email? Regex check. It’s not bolted-on; it’s baked in.

Downsides? Terminal quirks — some old ones choke on ANSI escapes. Test on iTerm, not just Xcode’s toy console. And it’s throwing-heavy; get comfy with try/await.

Still, for anything beyond toy scripts, it’s a no-brainer. I’ve wasted hours on custom readline wrappers. Promptberry? Drop-in sanity.

Unique angle: while everyone’s hyped on AI codegen, real dev time sinks in tooling. Promptberry frees hours — not by magic, but by ditching boilerplate. Who’s winning? You, the builder. Not some cloud vendor.

Interactive CLIs: Swift’s Missing Link?

Compare to crossterm in Rust or Bubble Tea — Promptberry’s simpler, Swift-native. No learning curve if you’re already in ecosystem.

Install? Swift Package Manager: .package(url: “https://github.com/promptberry/promptberry”), targets: [“Promptberry”]. Async-friendly, too — fits Swift’s concurrency push.

Edge cases? Long options lists — autocomplete saves scrolling hell. Preselects in multiselect. It’s thoughtful.

Cynic’s verdict: Swift CLI scene needed this yesterday. Ignore if you’re print/readLine purist (why?). Otherwise, level up.


🧬 Related Insights

Frequently Asked Questions

What is Promptberry for Swift?

It’s a library for interactive CLI prompts — text, selects, spinners — fixing stdlib’s gaps.

How do I install Promptberry in my Swift CLI tool?

Add to Package.swift: .package(url: “https://github.com/promptberry/promptberry”), import Promptberry, use try text(), select(), etc.

Does Promptberry handle async tasks in Swift?

Yes — tasks() for sequenced spinners, progress(total:) for bars, all awaitable.

Sarah Chen
Written by

AI research editor covering LLMs, benchmarks, and the race between frontier labs. Previously at MIT CSAIL.

Frequently asked questions

What is Promptberry for Swift?
It's a library for interactive CLI prompts — text, selects, spinners — fixing stdlib's gaps.
How do I install Promptberry in my Swift CLI tool?
Add to Package.swift: .package(url: "https://github.com/promptberry/promptberry"), import Promptberry, use try text(), select(), etc.
Does Promptberry handle async tasks in Swift?
Yes — tasks() for sequenced spinners, progress(total:) for bars, all awaitable.

Worth sharing?

Get the best Developer Tools stories of the week in your inbox — no noise, no spam.

Originally reported by dev.to

Stay in the loop

The week's most important stories from DevTools Feed, delivered once a week.