From 8f054b63a14d557e4b49e25fca822b1151226987 Mon Sep 17 00:00:00 2001 From: tumillanino Date: Sat, 18 Oct 2025 17:13:02 +1100 Subject: [PATCH] first draft of miasma installer --- go.mod | 28 +++++++++++++ go.sum | 47 ++++++++++++++++++++++ main.go | 25 ++++++++++++ tui/model.go | 70 ++++++++++++++++++++++++++++++++ tui/steps/disk_sel.go | 94 +++++++++++++++++++++++++++++++++++++++++++ tui/steps/install.go | 0 tui/steps/welcome.go | 46 +++++++++++++++++++++ tui/styles/styles.go | 25 ++++++++++++ 8 files changed, 335 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 tui/model.go create mode 100644 tui/steps/disk_sel.go create mode 100644 tui/steps/install.go create mode 100644 tui/steps/welcome.go create mode 100644 tui/styles/styles.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3261a00 --- /dev/null +++ b/go.mod @@ -0,0 +1,28 @@ +module miasma-installer + +go 1.25.2 + +require ( + github.com/atotto/clipboard v0.1.4 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/bubbles v0.21.0 // indirect + github.com/charmbracelet/bubbletea v1.3.10 // indirect + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect + github.com/charmbracelet/lipgloss v1.1.0 // indirect + github.com/charmbracelet/x/ansi v0.10.1 // indirect + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect + github.com/charmbracelet/x/term v0.2.1 // indirect + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect + github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/termenv v0.16.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/sahilm/fuzzy v0.1.1 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/sys v0.36.0 // indirect + golang.org/x/text v0.3.8 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5582ec9 --- /dev/null +++ b/go.sum @@ -0,0 +1,47 @@ +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs= +github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg= +github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw= +github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= +github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= +github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= +github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ= +github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= +github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= +github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= +github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= +github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= +github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= +github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= +github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= +github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..4aa6d01 --- /dev/null +++ b/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "miasma-installer/tui" + "os" + + tea "github.com/charmbracelet/bubbletea" +) + +func main() { + p := tea.NewProgram(tui.NewModel(), tea.WithAltScreen()) + + if _, err := p.Run(); err != nil { + fmt.Printf("An error has occured during installation: %v\n", err) + os.Exit(1) + } + + finalModel, _ := p.Run() + if root, ok := finalModel.(tui.RootModel); ok { + if root.State == tui.StateFinished { + fmt.Println("\nMiasma OS Installation Complete! Please reboot.") + } + } +} diff --git a/tui/model.go b/tui/model.go new file mode 100644 index 0000000..6bf8013 --- /dev/null +++ b/tui/model.go @@ -0,0 +1,70 @@ +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() +} diff --git a/tui/steps/disk_sel.go b/tui/steps/disk_sel.go new file mode 100644 index 0000000..6c2196b --- /dev/null +++ b/tui/steps/disk_sel.go @@ -0,0 +1,94 @@ +package steps + +import ( + "fmt" + "io" + "miasma-installer/tui/styles" + + "github.com/charmbracelet/bubbles/list" + tea "github.com/charmbracelet/bubbletea" +) + +type Disk struct { + name, description string +} + +func (i Disk) FilterValue() string { return i.name } +func (i Disk) Title() string { return i.name } +func (i Disk) Description() string { return i.description } + +type ItemDelegate struct{} + +func (i ItemDelegate) Height() int { return 1 } +func (i ItemDelegate) Width() int { return 0 } +func (i ItemDelegate) Update(msg tea.Msg, m list.Model) tea.Cmd { return nil } +func (i ItemDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) { + i, ok := item.(Disk) + if !ok { + return + } + + s := fmt.Sprintf("%d. %s - %s", index+1, i.Title(), i.Description()) + + // focus styles + if index == m.Index() { + s = styles.ActiveItemStyle.Render("> " + s) + } else { + s = styles.InactiveItemStyle.Render(" " + s) + } + fmt.Fprint(w, s) +} + +type DiskSelModel struct { + list list.Model + Finished bool + SelectedDisk string +} + +func NewDiskSelModel(width, height int) DiskSelModel { + // This is a placeholder - I need to update this to a tea.Cmd to scan the system for drives + disks := []list.Item{ + Disk{name: "/dev/sda", description: "500GB Samsung NVME"}, + Disk{name: "/dev/sdb", description: "1TB Baracuda HDD"}, + Disk{name: "/dev/loop0", description: "2GB Fanxiang SSD"}, + } + + l := list.New(disks, itemDelegate{}, width, height-5) + l.Title = styles.TitleStyle.Render("Select Installation Disk") + l.SetShowStatusBar(false) + l.SetFilterEnabled(false) + l.Styles.Title = styles.TitleStyle + l.KeyMap.Unbind() + + return DiskSelModel{list: l} +} + +func (m DiskSelModel) Init() tea.Cmd { + return nil +} + +func (m DiskSelModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + if m.Finished { + return m, nil + } + + switch msg := msg.(type) { + case tea.KeyMsg: + if msg.String() == "enter" { + if item, ok := m.list.SelectedItem().(Disk); ok { + m.SelectedDisk = item.name + m.Finished = true + return m, nil + } + } + } + var cmd tea.Cmd + m.list, cmd = m.list.Update(msg) + return m, cmd +} + +func (m DiskSelModel) View() string { + s := m.list.View() + s += "\n" + styles.HelpStyle.Render("Use ↑/↓ to navigate, [Enter] to select disk.") + return s +} diff --git a/tui/steps/install.go b/tui/steps/install.go new file mode 100644 index 0000000..e69de29 diff --git a/tui/steps/welcome.go b/tui/steps/welcome.go new file mode 100644 index 0000000..24d17e6 --- /dev/null +++ b/tui/steps/welcome.go @@ -0,0 +1,46 @@ +package steps + +import ( + "miasma-installer/tui/styles" + + tea "github.com/charmbracelet/bubbletea" +) + +type WelcomeModel struct { + Finished bool +} + +func NewWelcomeModel() WelcomeModel { + return WelcomeModel{Finished: false} +} + +func (m WelcomeModel) Init() tea.Cmd { + return nil +} + +func (m WelcomeModel) 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": + m.Finished = true + } + } + return m, nil +} + +func (m WelcomeModel) View() string { + s := styles.TitleStyle.Render("Welcome to the Miasma OS Installer") + s += "\n\n" + s += "This program will guide you through installing Miasma OS. \n" + s += "Please ensure that you have backed up any important data before proceding" + s += "\n\n" + s += styles.HelpStyle.Render("Press [Enter] to continue") + s += styles.HelpStyle.Render("Press [Ctrl+C] to exit") + + return styles.MainStyle.Render(s) +} diff --git a/tui/styles/styles.go b/tui/styles/styles.go new file mode 100644 index 0000000..146fe3e --- /dev/null +++ b/tui/styles/styles.go @@ -0,0 +1,25 @@ +package styles + +import "github.com/charmbracelet/lipgloss" + +var ( + MainStyle = lipgloss.NewStyle(). + Border(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("#7fb4ca")). + Padding(1, 2) + + HelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")) + + TitleStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#7fb4ca")). + Align(lipgloss.Center). + Bold(true). + PaddingBottom(1) + + ActiveItemStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#87a987")). + Bold(true) + + InactiveItemStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("240")) +)