Pular para o conteúdo

Comandos Paralelos e UI de Terminal

Nesta página

Um bloco parallel executa cada expressão de nível superior como tarefa irmã e espera por todas. Bindings não atravessam as fronteiras das tarefas; use um canal quando elas precisarem trocar valores.

Executa três comandos em paralelo e coleta dois status de saída por um canal.

11-parallel.zolo
Playground
// 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])}")

Requer a CLI/host do Zolo — abra no playground ou rode localmente.

std::term fornece prompts e estilos ANSI para programas interativos. Os helpers de estilo respeitam NO_COLOR; o exemplo deixa os prompts comentados para poder rodar sem interação.

Estiliza texto e imprime mensagens de sucesso, aviso e erro sem alterar o status de saída do processo.

12-term.zolo
Playground
// 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)")

Requer a CLI/host do Zolo — abra no playground ou rode localmente.

Buscar no Zolo

9 resultados

enespt-br