62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package steps
|
|
|
|
import (
|
|
"miasma-installer/tui/styles"
|
|
|
|
"github.com/charmbracelet/bubbles/textinput"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type HostnameModel struct {
|
|
Hostname string
|
|
input textinput.Model
|
|
Finished bool
|
|
}
|
|
|
|
func NewHostnameModel() HostnameModel {
|
|
ti := textinput.New()
|
|
ti.Placeholder = "miasma"
|
|
ti.Focus()
|
|
ti.CharLimit = 63
|
|
|
|
return HostnameModel{
|
|
input: ti,
|
|
}
|
|
}
|
|
|
|
func (m HostnameModel) Init() tea.Cmd {
|
|
return textinput.Blink
|
|
}
|
|
|
|
func (m HostnameModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
if m.Finished {
|
|
return m, nil
|
|
}
|
|
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
switch msg.String() {
|
|
case "enter":
|
|
if m.input.Value() != "" {
|
|
m.Hostname = m.input.Value()
|
|
m.Finished = true
|
|
return m, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
var cmd tea.Cmd
|
|
m.input, cmd = m.input.Update(msg)
|
|
return m, cmd
|
|
}
|
|
|
|
func (m HostnameModel) View() string {
|
|
s := styles.TitleStyle.Render("System Hostname")
|
|
s += "\n\n"
|
|
s += "Enter a hostname for your system:\n\n"
|
|
s += m.input.View() + "\n\n"
|
|
s += styles.HelpStyle.Render("[Enter] Continue")
|
|
|
|
return styles.MainStyle.Render(s)
|
|
}
|