This commit is contained in:
@@ -2,9 +2,11 @@ package steps
|
||||
|
||||
import (
|
||||
"miasma-installer/tui/styles"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
type EncryptionModel struct {
|
||||
@@ -22,11 +24,13 @@ func NewEncryptionModel() EncryptionModel {
|
||||
pi := textinput.New()
|
||||
pi.Placeholder = "Enter encryption password"
|
||||
pi.EchoMode = textinput.EchoPassword
|
||||
pi.Width = 40
|
||||
pi.Focus()
|
||||
|
||||
ci := textinput.New()
|
||||
ci.Placeholder = "Confirm password"
|
||||
ci.EchoMode = textinput.EchoPassword
|
||||
ci.Width = 40
|
||||
|
||||
return EncryptionModel{
|
||||
EnableEncryption: true,
|
||||
@@ -108,25 +112,52 @@ func (m EncryptionModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
func (m EncryptionModel) View() string {
|
||||
s := styles.TitleStyle.Render("Disk Encryption")
|
||||
s += "\n\n"
|
||||
var content strings.Builder
|
||||
|
||||
content.WriteString(styles.TitleStyle.Render("🔒 Disk Encryption"))
|
||||
content.WriteString("\n\n")
|
||||
|
||||
if !m.showInputs {
|
||||
s += "Enable LUKS2 disk encryption? (recommended)\n\n"
|
||||
s += styles.HelpStyle.Render("[y] Yes [n] No")
|
||||
info := "LUKS2 encryption protects your data if your device is lost or stolen.\n"
|
||||
info += "You will need to enter the password every time you boot."
|
||||
content.WriteString(styles.InfoBoxStyle.Render(info))
|
||||
content.WriteString("\n\n")
|
||||
|
||||
content.WriteString("Enable disk encryption? (recommended)\n\n")
|
||||
content.WriteString(styles.RenderHelp("y", "Yes", "n", "No"))
|
||||
} else {
|
||||
s += "Enter encryption password:\n\n"
|
||||
s += m.passwordInput.View() + "\n\n"
|
||||
s += m.confirmInput.View() + "\n\n"
|
||||
content.WriteString(styles.LabelStyle.Render("Password:"))
|
||||
content.WriteString("\n")
|
||||
|
||||
inputStyle := styles.InputStyle
|
||||
if m.focusIndex == 0 {
|
||||
inputStyle = styles.FocusedInputStyle
|
||||
}
|
||||
content.WriteString(inputStyle.Render(m.passwordInput.View()))
|
||||
content.WriteString("\n\n")
|
||||
|
||||
content.WriteString(styles.LabelStyle.Render("Confirm Password:"))
|
||||
content.WriteString("\n")
|
||||
|
||||
confirmStyle := styles.InputStyle
|
||||
if m.focusIndex == 1 {
|
||||
confirmStyle = styles.FocusedInputStyle
|
||||
}
|
||||
content.WriteString(confirmStyle.Render(m.confirmInput.View()))
|
||||
content.WriteString("\n\n")
|
||||
|
||||
if m.passwordInput.Value() != "" && m.confirmInput.Value() != "" {
|
||||
if m.passwordInput.Value() != m.confirmInput.Value() {
|
||||
s += styles.HelpStyle.Render("Passwords do not match\n")
|
||||
content.WriteString(styles.ErrorStyle.Render("✗ Passwords do not match"))
|
||||
content.WriteString("\n\n")
|
||||
} else {
|
||||
content.WriteString(styles.SuccessStyle.Render("✓ Passwords match"))
|
||||
content.WriteString("\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
s += styles.HelpStyle.Render("[Tab] Switch fields [Enter] Continue")
|
||||
content.WriteString(styles.RenderHelp("Tab", "Switch fields", "Enter", "Continue"))
|
||||
}
|
||||
|
||||
return styles.MainStyle.Render(s)
|
||||
return styles.AppStyle.Render(content.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user