package main
import (
"fmt"
"log"
"time"
"github.com/qzeleza/ziva"
)
func main() {
// Create task queue with title
queue := ziva.NewQueue("Ziva Demo Application")
// Configure appearance
queue.WithAppName("MyApp")
queue.WithTasksNumbered(false, "[%d]")
// Create tasks
createTasks(queue)
// Run the queue
if err := queue.Run(); err != nil {
log.Fatal(err)
}
// Show results
printResults()
}
func createTasks(queue *ziva.Queue) {
// 1. Confirmation task with timeout
confirm := ziva.NewYesNoTask("Confirmation", "Start setup?").
WithTimeout(5*time.Second, "Yes")
// 2. Environment selection
environments := []ziva.Item{
{Key: "development", Name: "development", Description: "Development environment"},
{Key: "staging", Name: "staging", Description: "Testing environment"},
{Key: "production", Name: "production", Description: "Production environment"},
}
env := ziva.NewSingleSelectTask("Environment Selection", environments).
WithDefaultItem("staging")
// 3. Component selection
components := []ziva.Item{
{Key: "api", Name: "api", Description: "REST API server"},
{Key: "web", Name: "web", Description: "Web interface"},
{Key: "cli", Name: "cli", Description: "Command line"},
{Key: "docs", Name: "docs", Description: "Documentation"},
}
comp := ziva.NewMultiSelectTask("Components", components).
WithSelectAll("Select all").
WithDefaultItems([]string{"api", "cli"})
// 4. Project name input with validation
name := ziva.NewInputTask("Project Name", "Enter name:").
WithValidator(ziva.DefaultValidators.Required())
// 5. Functional task
setup := ziva.NewFuncTask("Setup", func() error {
time.Sleep(2 * time.Second) // Work simulation
return nil
}, ziva.WithSummaryFunction(func() []string {
return []string{"Configuration created", "Project ready"}
}))
// Add all tasks to queue
queue.AddTasks(confirm, env, comp, name, setup)
}
func printResults() {
fmt.Println("\n🎉 Application completed!")
fmt.Println("Results are stored in task objects.")
}