71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package tui
|
|
|
|
import (
|
|
"miasma-installer/tui/steps"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type State int
|
|
|
|
const (
|
|
StateWelcome State = iota
|
|
StateDiskSelection
|
|
StateInstalling
|
|
StateFinished
|
|
)
|
|
|
|
type RootModel struct {
|
|
State State
|
|
CurrentModel tea.Model
|
|
Width int
|
|
Height int
|
|
}
|
|
|
|
func NewModel() RootModel {
|
|
return RootModel{
|
|
State: StateWelcome,
|
|
CurrentModel: steps.NewWelcomeModel(),
|
|
}
|
|
}
|
|
|
|
func (m RootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
var cmd tea.Cmd
|
|
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
if msg.String() == "ctrl+c" {
|
|
return m, tea.Quit
|
|
}
|
|
case tea.WindowSizeMsg:
|
|
m.Width = msg.Width
|
|
m.Height = msg.Height
|
|
}
|
|
|
|
m.CurrentModel, cmd = m.CurrentModel.Update(msg)
|
|
|
|
switch m.CurrentModel.(type) {
|
|
case steps.WelcomeModel:
|
|
if m.CurrentModel.(steps.WelcomeModel).Finished {
|
|
m.State = StateDiskSelection
|
|
m.CurrentModel = steps.NewDiskSelModel(m.Width, m.Height)
|
|
return m, m.CurrentModel.Init()
|
|
}
|
|
|
|
case steps.DiskSelModel:
|
|
if m.CurrentModel.(steps.DiskSelModel).Finished {
|
|
// need to update this to pass actual selected disk model to the installer
|
|
selectedDisk := m.CurrentModel.(steps.DiskSelModel).SelectedDisk
|
|
m.State = StateInstalling
|
|
m.CurrentModel = steps.NewInstallModel(selectedDisk)
|
|
return m, m.CurrentModel.Init()
|
|
}
|
|
// logic for StateInstalling -> StateFinished will go here
|
|
}
|
|
return m, cmd
|
|
}
|
|
|
|
func (m RootModel) View() string {
|
|
return m.CurrentModel.View()
|
|
}
|