feat: main flow created
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
header = "App do Dono - Instalador Cliente"
|
||||
)
|
||||
|
||||
func (m Model) View() tea.View {
|
||||
pad := strings.Repeat(" ", padding)
|
||||
var body string
|
||||
helpMsg := "ctrl+c: sair"
|
||||
|
||||
switch m.currentStep {
|
||||
case StepCheckDocker:
|
||||
body = m.viewCheckDocker()
|
||||
case StepDockerInstall:
|
||||
body = m.viewDockerInstall()
|
||||
helpMsg = "qualquer tecla: sair"
|
||||
case StepIPQuestion:
|
||||
body = m.viewIPQuestion()
|
||||
case StepServerConfig:
|
||||
body = m.serverForm.View()
|
||||
helpMsg = "tab: próximo campo • enter: confirmar • ctrl+c: sair"
|
||||
case StepDatabaseConfig:
|
||||
body = m.dbForm.View()
|
||||
helpMsg = "tab: próximo campo • enter: confirmar • ctrl+c: sair"
|
||||
case StepCertConfig:
|
||||
body = m.certForm.View()
|
||||
helpMsg = "tab: próximo campo • enter: confirmar • ctrl+c: sair"
|
||||
}
|
||||
|
||||
help := HelpStyle.Render(helpMsg)
|
||||
|
||||
v := tea.NewView(fmt.Sprintf("\n%s%s\n\n%s\n\n%s%s\n",
|
||||
pad, TitleStyle.Render(header),
|
||||
body,
|
||||
pad, help,
|
||||
))
|
||||
v.AltScreen = true
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (m Model) viewCheckDocker() string {
|
||||
pad := strings.Repeat(" ", padding)
|
||||
|
||||
barWidth := 40
|
||||
filled := int(m.checkProgress * float64(barWidth))
|
||||
empty := barWidth - filled
|
||||
|
||||
bar := ProgressFillStyle.Render(strings.Repeat("█", filled)) +
|
||||
ProgressEmptyStyle.Render(strings.Repeat("░", empty))
|
||||
|
||||
percent := fmt.Sprintf(" %d%%", int(m.checkProgress*100))
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString(pad + "Avaliando instalação do Docker...\n\n")
|
||||
sb.WriteString(pad + bar + HelpStyle.Render(percent))
|
||||
|
||||
if m.checkDockerDone && m.checkProgress == 1 {
|
||||
found := ""
|
||||
|
||||
if m.dockerInstalled {
|
||||
found = "encontrado"
|
||||
} else {
|
||||
found = "não encontrado"
|
||||
}
|
||||
|
||||
sb.WriteString("\n\n" + pad + fmt.Sprintf("Docker %s na máquina. Pressione qualquer tecla para seguir.", found))
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (m Model) viewDockerInstall() string {
|
||||
pad := strings.Repeat(" ", padding)
|
||||
|
||||
var sb strings.Builder
|
||||
sb.WriteString(pad + "Nenhuma versão do Docker encontrada no sistema.\n")
|
||||
sb.WriteString(pad + "Instale o Docker manualmente e execute este instalador novamente para concluir a configuração.")
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (m Model) viewIPQuestion() string {
|
||||
pad := strings.Repeat(" ", padding)
|
||||
|
||||
var options = []string{"Sim", "Não"}
|
||||
|
||||
var sb strings.Builder
|
||||
|
||||
sb.WriteString(pad + "Existe IP público disponível para a máquina?\n")
|
||||
|
||||
for i, opt := range options {
|
||||
cursor := " "
|
||||
text := ""
|
||||
isSelected := m.cursor == i
|
||||
|
||||
if isSelected {
|
||||
cursor = CursorStyle.Render("> ")
|
||||
text = CursorStyle.Render(opt)
|
||||
} else {
|
||||
text = opt
|
||||
}
|
||||
sb.WriteString("\n" + pad + cursor + text)
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
Reference in New Issue
Block a user