Skip to content

Parallel Commands and Terminal UI

On this page

A parallel block runs each top-level expression as a sibling task and waits for all of them. Bindings do not cross task boundaries; use a channel when tasks must exchange values.

Runs three commands concurrently and collects two exit statuses through a channel.

11-parallel.zolo
// Feature: parallel { } — N commands side by side, all at once.

// Syntax: each top-level expression statement becomes its own task;

// the block exits only when every task finished (a panic in one cancels

// the siblings). Sugar over the A8 form: scope { spawn { … } × N }.

// TE976 rejects `let`/`return`/`defer` inside — each statement is an

// isolated spawn, so a binding could never reach its siblings; use

// scope + channel() when tasks must communicate.


// Three commands, one wall-clock wait:

parallel {
    sh"git version".run()
    sh"git help -a".run()
    sh"git config --list".run_raw()
}
print("all three commands finished")

// Values move between tasks via channels (the explicit form):

let ch = channel(2)
parallel {
    ch.send(sh"git version".run_raw().status)
    ch.send(sh"git version".run_raw().status)
}
let total = ch.recv()? + ch.recv()?
print("both exited 0: {total == 0}")

// `parallel` is contextual — calling a function with that name still works:

fn parallel_count(xs: [int]) -> int { return xs.len() }
print("call form: {parallel_count([1, 2, 3])}")

Requires the Zolo CLI/host — open in the playground or run locally.

std::term provides prompts and ANSI styling for interactive programs. Its styling helpers respect NO_COLOR; the example leaves input prompts commented out so it can run unattended.

Styles text and prints success, warning, and error messages without changing the process exit status.

12-term.zolo
// Feature: std::term — prompts and ANSI styling for interactive scripts.

// Syntax: term.ask/confirm/select block on stdin; term.print_* and

// term.style emit ANSI colors and respect NO_COLOR (https://no-color.org).

// When to use: the interactive half of a CLI — `Cli` (@cli) parses flags

// BEFORE the run; term handles questions DURING it.

//

// NOTE: the ask/confirm/select calls are commented out so the example runs

// unattended (CI has no stdin) — uncomment to try them.


use std::term

// let name = term.ask("Project name?")

// if term.confirm("Overwrite {name}?", false) {

//     term.print_success("created {name}")

// } else {

//     term.print_error("aborted")

// }

// let flavor = term.select("Pick a flavor:", ["vm", "native", "wasm"])


print(term.style("bold", "styles:"))
print(term.style("red", "  red") + term.style("green", "  green") + term.style("yellow", "  yellow"))
term.print_success("success line")
term.print_warn("warn line")
term.print_error("error line (styled, still exit 0)")

Requires the Zolo CLI/host — open in the playground or run locally.

Search Zolo

9 results

enespt-br