Input e Write
Componentes de entrada de texto para coletar informações do usuário.
Input
Entrada de texto de linha única com validação opcional.
Uso Básico
invowk tui input --title "What is your name?"
Opções
| Opção | Descrição |
|---|---|
--title | Texto do prompt |
--description | Descrição abaixo do título |
--placeholder | Texto de placeholder |
--value | Valor inicial |
--password | Ocultar entrada (para secrets) |
--char-limit | Máximo de caracteres |
--width | Largura do campo |
--prompt | Caracter(es) de prompt antes da entrada |
Exemplos
# With placeholder
invowk tui input --title "Email" --placeholder "user@example.com"
# Password input (hidden)
invowk tui input --title "Password" --password
# With initial value
invowk tui input --title "Name" --value "John Doe"
# Limited length
invowk tui input --title "Username" --char-limit 20
Capturando Saída
NAME=$(invowk tui input --title "Enter your name:")
echo "Hello, $NAME!"
Em Scripts
{
name: "create-user"
implementations: [{
script: """
USERNAME=$(invowk tui input --title "Username:" --char-limit 20)
EMAIL=$(invowk tui input --title "Email:" --placeholder "user@example.com")
PASSWORD=$(invowk tui input --title "Password:" --password)
echo "Creating user: $USERNAME ($EMAIL)"
./scripts/create-user.sh "$USERNAME" "$EMAIL" "$PASSWORD"
"""
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Write
Editor de texto multilinha para entradas mais longas como descrições ou mensagens de commit.
Uso Básico
invowk tui write --title "Enter description"
Opções
| Opção | Descrição |
|---|---|
--title | Título do editor |
--description | Descrição abaixo do título |
--placeholder | Texto de placeholder |
--value | Conteúdo inicial |
--show-line-numbers | Exibir números de linha |
--char-limit | Máximo de caracteres |
--width | Largura do editor |
--height | Altura do editor |
Exemplos
# Basic editor
invowk tui write --title "Description:"
# With line numbers
invowk tui write --title "Code:" --show-line-numbers
# With initial content
invowk tui write --title "Edit message:" --value "Initial text here"
Casos de Uso
Mensagem de Git Commit
MESSAGE=$(invowk tui write --title "Commit message:")
git commit -m "$MESSAGE"
Configuração Multilinha
CONFIG=$(invowk tui write --title "Enter YAML config:" --show-line-numbers)
echo "$CONFIG" > config.yaml
Release Notes
NOTES=$(invowk tui write --title "Release notes:")
gh release create v1.0.0 --notes "$NOTES"
Em Scripts
{
name: "commit"
description: "Interactive commit with editor"
implementations: [{
script: """
# Show staged changes
git diff --cached --stat
# Get commit message
MESSAGE=$(invowk tui write --title "Commit message:")
if [ -z "$MESSAGE" ]; then
echo "Commit cancelled (empty message)"
exit 1
fi
git commit -m "$MESSAGE"
"""
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Dicas
Tratando Entrada Vazia
NAME=$(invowk tui input --title "Name:")
if [ -z "$NAME" ]; then
echo "Name is required!"
exit 1
fi
Loop de Validação
while true; do
EMAIL=$(invowk tui input --title "Email:")
if echo "$EMAIL" | grep -qE '^[^@]+@[^@]+\.[^@]+$'; then
break
fi
echo "Invalid email format, try again."
done
Valores Padrão
# Use shell default if empty
NAME=$(invowk tui input --title "Name:" --placeholder "Anonymous")
NAME="${NAME:-Anonymous}"
Próximos Passos
- Choose e Confirm - Componentes de seleção
- Visão Geral - Todos os componentes TUI