Choose e Confirm
Componentes de seleção e confirmação para decisões do usuário.
Choose
Selecione uma ou mais opções de uma lista.
Uso Básico
invowk tui choose "Option 1" "Option 2" "Option 3"
Opções
| Opção | Descrição |
|---|---|
--title | Prompt de seleção |
--limit | Máximo de seleções (padrão: 1) |
--no-limit | Seleções ilimitadas |
--height | Altura da lista |
Seleção Única
# Basic
COLOR=$(invowk tui choose red green blue)
echo "You chose: $COLOR"
# With title
ENV=$(invowk tui choose --title "Select environment" dev staging prod)
Seleção Múltipla
# Limited multi-select (up to 3)
ITEMS=$(invowk tui choose --limit 3 "One" "Two" "Three" "Four" "Five")
# Unlimited multi-select
ITEMS=$(invowk tui choose --no-limit "One" "Two" "Three" "Four" "Five")
Múltiplas seleções são retornadas como valores separados por nova linha:
SERVICES=$(invowk tui choose --no-limit --title "Select services to deploy" \
api web worker scheduler)
echo "$SERVICES" | while read -r service; do
echo "Deploying: $service"
done
Exemplos do Mundo Real
Seleção de Environment
ENV=$(invowk tui choose --title "Deploy to which environment?" \
development staging production)
case "$ENV" in
production)
if ! invowk tui confirm "Are you sure? This is PRODUCTION!"; then
exit 1
fi
;;
esac
./deploy.sh "$ENV"
Seleção de Serviço
SERVICES=$(invowk tui choose --no-limit --title "Which services?" \
api web worker cron)
for service in $SERVICES; do
echo "Restarting $service..."
systemctl restart "$service"
done
Confirm
Prompt de confirmação sim/não.
Uso Básico
invowk tui confirm "Are you sure?"
Retorna:
- Código de saída 0 se o usuário confirmar (sim)
- Código de saída 1 se o usuário recusar (não)
Opções
| Opção | Descrição |
|---|---|
--title | Título exibido acima do prompt |
--affirmative | Label customizado para "sim" |
--negative | Label customizado para "não" |
--default | Padrão para sim |
Exemplos
# Basic confirmation
if invowk tui confirm "Continue?"; then
echo "Continuing..."
else
echo "Cancelled."
fi
# Custom labels
if invowk tui confirm --affirmative "Delete" --negative "Cancel" "Delete all files?"; then
rm -rf ./temp/*
fi
# Default to yes (user just presses Enter)
if invowk tui confirm --default "Proceed with defaults?"; then
echo "Using defaults..."
fi
Execução Condicional
# Simple pattern
invowk tui confirm "Run tests?" && npm test
# Negation
invowk tui confirm "Skip build?" || npm run build
Operações Perigosas
# Double confirmation for dangerous actions
if invowk tui confirm "Delete production database?"; then
echo "This cannot be undone!" | invowk tui style --foreground "#FF0000" --bold
if invowk tui confirm --affirmative "YES, DELETE IT" --negative "No, abort" "Type to confirm:"; then
./scripts/delete-production-db.sh
fi
fi
Em Scripts
{
name: "clean"
description: "Clean build artifacts"
implementations: [{
script: """
echo "This will delete:"
echo " - ./build/"
echo " - ./dist/"
echo " - ./node_modules/"
if invowk tui confirm "Proceed with cleanup?"; then
rm -rf build/ dist/ node_modules/
echo "Cleaned!" | invowk tui style --foreground "#00FF00"
else
echo "Cancelled."
fi
"""
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Padrões Combinados
Seleção com Confirmação
ACTION=$(invowk tui choose --title "Select action" \
"Deploy to staging" \
"Deploy to production" \
"Rollback" \
"Cancel")
case "$ACTION" in
"Cancel")
exit 0
;;
"Deploy to production")
if ! invowk tui confirm --affirmative "Yes, deploy" "Deploy to PRODUCTION?"; then
echo "Aborted."
exit 1
fi
;;
esac
echo "Executing: $ACTION"
Wizard Multi-Etapa
# Step 1: Choose action
ACTION=$(invowk tui choose --title "What would you like to do?" \
"Create new project" \
"Import existing" \
"Exit")
if [ "$ACTION" = "Exit" ]; then
exit 0
fi
# Step 2: Get details
NAME=$(invowk tui input --title "Project name:")
# Step 3: Confirm
echo "Action: $ACTION"
echo "Name: $NAME"
if invowk tui confirm "Create project?"; then
# proceed
fi
Próximos Passos
- Filter e File - Busca e seleção de arquivo
- Visão Geral - Todos os componentes TUI