Comandos Paralelos e Interfaz de Terminal
En esta página
Un bloque parallel ejecuta cada expresión de nivel superior como tarea hermana
y espera a todas. Los bindings no cruzan los límites de las tareas; usa un
canal cuando necesiten intercambiar valores.
Ejecuta tres comandos en paralelo y reúne dos estados de salida mediante un canal.
// 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])}")
Requiere la CLI o el host de Zolo; ábrelo en el playground o ejecútalo localmente.
std::term ofrece prompts y estilos ANSI para programas interactivos. Sus
helpers de estilo respetan NO_COLOR; el ejemplo deja los prompts comentados
para poder ejecutarse sin interacción.
Aplica estilos al texto e imprime mensajes de éxito, advertencia y error sin cambiar el estado de salida del proceso.
// 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)")
Requiere la CLI o el host de Zolo; ábrelo en el playground o ejecútalo localmente.
Consulta también